mirror of
https://github.com/gbdev/rgbds.git
synced 2026-05-08 10:59:36 +00:00
Switch macOS static build to CMake (#1938)
This moves the tortuous flags out of our CI scripts, and allows us to benefit from the libpng download caching.
This commit is contained in:
@@ -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"
|
|
||||||
@@ -54,13 +54,10 @@ jobs:
|
|||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh macos
|
./.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
|
- name: Build binaries
|
||||||
run: |
|
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}
|
strip rgb{asm,link,fix,gfx}
|
||||||
- name: Package binaries
|
- name: Package binaries
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -109,12 +109,16 @@ jobs:
|
|||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: |
|
||||||
./.github/scripts/install_deps.sh macos
|
./.github/scripts/install_deps.sh macos
|
||||||
- name: Build libpng
|
- name: Cache library deps
|
||||||
run: |
|
uses: actions/cache@v5
|
||||||
./.github/scripts/build_libpng.sh
|
with:
|
||||||
|
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
|
||||||
|
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
|
||||||
|
enableCrossOsArchive: true
|
||||||
- name: Build & install
|
- name: Build & install
|
||||||
run: |
|
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
|
- name: Package binaries
|
||||||
run: |
|
run: |
|
||||||
mkdir bins
|
mkdir bins
|
||||||
@@ -168,7 +172,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
|
path: ${{ env.DEPS_ROOT_DIR }}/*-tmp/
|
||||||
key: dep-srcs-${{ hashFiles('cmake/deps.cmake') }}
|
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
|
- name: Build Windows binaries
|
||||||
run: | # ASan seems to be broken on Windows, so we disable it.
|
run: | # ASan seems to be broken on Windows, so we disable it.
|
||||||
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DSANITIZERS=OFF \
|
cmake -S . -B build --preset develop-msvc${{ matrix.bits }} -DSANITIZERS=OFF \
|
||||||
|
|||||||
@@ -31,6 +31,14 @@
|
|||||||
"name": "msvc64",
|
"name": "msvc64",
|
||||||
"description": "Flags for building 64-bit executables with MSVC",
|
"description": "Flags for building 64-bit executables with MSVC",
|
||||||
"architecture": "x64"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
Reference in New Issue
Block a user