diff --git a/.github/scripts/build_libpng.sh b/.github/scripts/build_libpng.sh deleted file mode 100755 index 51a06d30..00000000 --- a/.github/scripts/build_libpng.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -euo pipefail - -pngver=1.6.56 - -## Grab sources and check them - -curl -LOJ "http://prdownloads.sourceforge.net/libpng/libpng-$pngver.tar.xz?download" -echo f7d8bf1601b7804f583a254ab343a6549ca6cf27d255c302c47af2d9d36a6f18 \*libpng-$pngver.tar.xz | \ - shasum -a 256 -c - - -## Extract sources and patch them - -tar -xvf libpng-$pngver.tar.xz - -## Start building! - -mkdir -p build -cd build -../libpng-$pngver/configure --disable-shared --enable-static \ - CFLAGS="-O3 -flto -DNDEBUG -mmacosx-version-min=10.9 -arch x86_64 -arch arm64 -fno-exceptions" -make -kj -make install prefix="$PWD/../libpng-staging" diff --git a/.github/workflows/create-release-artifacts.yml b/.github/workflows/create-release-artifacts.yml index 23abae75..60abbd09 100644 --- a/.github/workflows/create-release-artifacts.yml +++ b/.github/workflows/create-release-artifacts.yml @@ -54,13 +54,10 @@ jobs: - name: Install deps run: | ./.github/scripts/install_deps.sh macos - - name: Build libpng - run: | - ./.github/scripts/build_libpng.sh - # We force linking libpng statically; the other libs are provided by macOS itself - name: Build binaries run: | - make -kj CXXFLAGS="-O3 -flto -DNDEBUG -mmacosx-version-min=10.9 -arch x86_64 -arch arm64" PNGCFLAGS="-I libpng-staging/include" PNGLDLIBS="libpng-staging/lib/libpng.a -lz" Q= + cmake -S . -B build --preset macos-static -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" + cmake --build build strip rgb{asm,link,fix,gfx} - name: Package binaries run: | diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a51eafd4..f3391d94 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -109,12 +109,16 @@ jobs: - name: Install deps run: | ./.github/scripts/install_deps.sh macos - - name: Build libpng - run: | - ./.github/scripts/build_libpng.sh + - name: Cache library deps + uses: actions/cache@v5 + with: + path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/ + key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }} + enableCrossOsArchive: true - name: Build & install run: | - make -kj CXXFLAGS="-O3 -flto -DNDEBUG -mmacosx-version-min=10.9 -arch x86_64 -arch arm64" PNGCFLAGS="-I libpng-staging/include" PNGLDLIBS="libpng-staging/lib/libpng.a -lz" Q= + cmake -S . -B build --preset macos-static -DFETCHCONTENT_BASE_DIR="${{ env.DEPS_ROOT_DIR }}" + cmake --build build - name: Package binaries run: | mkdir bins @@ -168,7 +172,7 @@ jobs: with: path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/ key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }} - enableCrossOsArchive: true # Currently only used on Windows, but the contents are OS-agnostic. + enableCrossOsArchive: true - name: Build Windows binaries run: | # ASan seems to be broken on Windows, so we disable it. cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DSANITIZERS=OFF \ diff --git a/CMakePresets.json b/CMakePresets.json index f94bdc0b..255c4db7 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -31,6 +31,14 @@ "name": "msvc64", "description": "Flags for building 64-bit executables with MSVC", "architecture": "x64" + }, + + { + "name": "macos-static", + "description": "Flags for building an executable compatible with old macOS", + "cacheVariables": { + "CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake/macos-static.cmake" + } } ] } diff --git a/cmake/macos-static.cmake b/cmake/macos-static.cmake new file mode 100644 index 00000000..575721a7 --- /dev/null +++ b/cmake/macos-static.cmake @@ -0,0 +1,28 @@ +# This file is meant to be included at the project level, +# in order to generate executables compatible with old macOS versions. +# See our `macos-static` CMake preset for how it's meant to be used. + +# The `-mmacosx-version-min=10.9` flag ensures that the binary only uses APIs available on Mac OS X 10.9 Mavericks. +# The `-arch` flags build a "fat binary" that works on both Apple architectures: +# older Intel x64 Macs and newer ARM "Apple Silicon" ones. +set("-mmacosx-version-min=10.9 -arch x86_64 -arch arm64") +set(CMAKE_C_FLAGS "${secret_sauce}" CACHE STRING "Flags used by the C compiler during all build types.") +set(CMAKE_CXX_FLAGS "${secret_sauce}" CACHE STRING "Flags used by the CXX compiler during all build types.") + +# Mac OS X has always provided zlib, so we can safely link dynamically against it. +# However, libpng is *not* provided by default, so we link it statically, which requires downloading and building it from source. +set(PNG_SHARED OFF) +set(PNG_STATIC ON) +# If libpng is already available (e.g. via Homebrew), we ignore that and still build our own. +set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER) +# But we still want to attempt linking against the system's zlib. +function(rgbds_provide_dependency method dep_name) + if(dep_name STREQUAL "ZLIB") + find_package(ZLIB) + if(ZLIB_FOUND) + FetchContent_SetPopulated(ZLIB) + endif() + endif() +endfunction(rgbds_provide_dependency) +cmake_language(SET_DEPENDENCY_PROVIDER rgbds_provide_dependency + SUPPORTED_METHODS FETCHCONTENT_MAKEAVAILABLE_SERIAL)