Build “fat binaries” for macOS (#1461)

The same binary, both for Intel and ARM Macs!

Builds libpng manually since the lib Brew distributes only contains code for the host arch.
This commit is contained in:
Eldred Habert
2024-08-09 19:18:58 +02:00
committed by GitHub
parent 2d530dbcd6
commit 718066c2cf
5 changed files with 48 additions and 22 deletions

27
.github/scripts/build_libpng.sh vendored Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
set -euo pipefail
pngver=1.6.43
## Grab sources and check them
curl -LOJ "http://prdownloads.sourceforge.net/libpng/libpng-$pngver.tar.xz?download"
# Brew doesn't provide any sha256sum, so we're making do with `sha2` instead.
if [ "$(sha2 -q -256 libpng-$pngver.tar.xz)" != 6a5ca0652392a2d7c9db2ae5b40210843c0bbc081cbd410825ab00cc59f14a6c ]; then
sha2 -256 libpng-$pngver.tar.xz
echo Checksum mismatch! Aborting. >&2
exit 1
fi
## 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"

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -euo pipefail
case "${1%-*}" in case "${1%-*}" in
ubuntu) ubuntu)
@@ -7,9 +7,11 @@ case "${1%-*}" in
sudo apt-get install -yq bison libpng-dev pkg-config sudo apt-get install -yq bison libpng-dev pkg-config
;; ;;
macos) macos)
brew install bison libpng pkg-config md5sha1sum brew install bison sha2 md5sha1sum
# For the version check below exclusively, re-do this before building # Export `bison` to allow using the version we install from Homebrew,
export PATH="/opt/homebrew/opt/bison/bin:/usr/local/opt/bison/bin:$PATH" # instead of the outdated one preinstalled on macOS (which doesn't even support `-Wall`...)
export PATH="/opt/homebrew/opt/bison/bin:$PATH"
printf 'PATH=%s\n' "$PATH" >>"$GITHUB_ENV" # Make it available to later CI steps too
;; ;;
*) *)
echo "WARNING: Cannot install deps for OS '$1'" echo "WARNING: Cannot install deps for OS '$1'"

View File

@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/bash
set -e set -euo pipefail
pngver=1.6.43 pngver=1.6.43
arch="$1" arch="$1"
@@ -27,7 +27,7 @@ cd build
--prefix="/usr/$arch" \ --prefix="/usr/$arch" \
--enable-shared --disable-static \ --enable-shared --disable-static \
CPPFLAGS="-D_FORTIFY_SOURCE=2" \ CPPFLAGS="-D_FORTIFY_SOURCE=2" \
CFLAGS="-O2 -pipe -fno-plt -fexceptions --param=ssp-buffer-size=4" \ CFLAGS="-O2 -pipe -fno-plt -fno-exceptions --param=ssp-buffer-size=4" \
LDFLAGS="-Wl,-O1,--sort-common,--as-needed -fstack-protector" LDFLAGS="-Wl,-O1,--sort-common,--as-needed -fstack-protector"
make -kj make -kj
make install sudo make install

View File

@@ -79,11 +79,13 @@ jobs:
shell: bash shell: bash
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 # We force linking libpng statically; the other libs are provided by macOS itself
- name: Build binaries - name: Build binaries
run: | run: |
export PATH="/usr/local/opt/bison/bin:$PATH" 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=
make -kj CXXFLAGS="-O3 -flto -DNDEBUG -mmacosx-version-min=10.9" PKG_CONFIG="pkg-config --static" PNGLDLIBS="$(pkg-config --static --libs-only-L libpng | cut -c 3-)/libpng.a $(pkg-config --static --libs-only-l libpng | sed s/-lpng[0-9]*//g)" Q=
strip rgb{asm,link,fix,gfx} strip rgb{asm,link,fix,gfx}
- name: Package binaries - name: Package binaries
run: | run: |
@@ -92,7 +94,7 @@ jobs:
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: macos name: macos
path: rgbds-${{ env.version }}-macos-x86_64.zip path: rgbds-${{ env.version }}-macos.zip
linux: linux:
runs-on: ubuntu-20.04 # Oldest supported, for best glibc compatibility. runs-on: ubuntu-20.04 # Oldest supported, for best glibc compatibility.

View File

@@ -22,18 +22,14 @@ jobs:
shell: bash shell: bash
run: | run: |
./.github/scripts/install_deps.sh ${{ matrix.os }} ./.github/scripts/install_deps.sh ${{ matrix.os }}
# Export `bison` to allow using the version we install from Homebrew,
# instead of the outdated 2.3 one preinstalled on macOS.
- name: Build & install using Make - name: Build & install using Make
if: matrix.buildsys == 'make' if: matrix.buildsys == 'make'
run: | run: |
export PATH="/opt/homebrew/opt/bison/bin:/usr/local/opt/bison/bin:$PATH"
make develop -kj Q= CXX=${{ matrix.cxx }} make develop -kj Q= CXX=${{ matrix.cxx }}
sudo make install -j Q= sudo make install -j Q=
- name: Build & install using CMake - name: Build & install using CMake
if: matrix.buildsys == 'cmake' if: matrix.buildsys == 'cmake'
run: | run: |
export PATH="/opt/homebrew/opt/bison/bin:/usr/local/opt/bison/bin:$PATH"
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DSANITIZERS=ON -DMORE_WARNINGS=ON cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${{ matrix.cxx }} -DSANITIZERS=ON -DMORE_WARNINGS=ON
cmake --build build -j --verbose cmake --build build -j --verbose
cp build/src/rgb{asm,link,fix,gfx} . cp build/src/rgb{asm,link,fix,gfx} .
@@ -84,13 +80,12 @@ jobs:
shell: bash shell: bash
run: | run: |
./.github/scripts/install_deps.sh macos ./.github/scripts/install_deps.sh macos
# Export `bison` to allow using the version we install from Homebrew, - name: Build libpng
# instead of the outdated one preinstalled on macOS (which doesn't run: |
# even support `-Wall`...). ./.github/scripts/build_libpng.sh
- name: Build & install - name: Build & install
run: | run: |
export PATH="/opt/homebrew/opt/bison/bin:/usr/local/opt/bison/bin:$PATH" 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=
make -kj CXXFLAGS="-O3 -flto -DNDEBUG -mmacosx-version-min=10.9" PKG_CONFIG="pkg-config --static" PNGLDLIBS="$(pkg-config --static --libs-only-L libpng | cut -c 3-)/libpng.a $(pkg-config --static --libs-only-l libpng | sed s/-lpng[0-9]*//g)" Q=
- name: Package binaries - name: Package binaries
run: | run: |
mkdir bins mkdir bins
@@ -238,13 +233,13 @@ jobs:
- name: Install deps - name: Install deps
shell: bash shell: bash
run: | run: |
./.github/scripts/install_deps.sh ${{ matrix.os }} ./.github/scripts/install_deps.sh ubuntu
- name: Install MinGW - name: Install MinGW
run: | # dpkg-dev is apparently required for pkg-config for cross-building run: | # dpkg-dev is apparently required for pkg-config for cross-building
sudo apt-get install g++-mingw-w64-${{ matrix.arch }}-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev sudo apt-get install g++-mingw-w64-${{ matrix.arch }}-win32 mingw-w64-tools libz-mingw-w64-dev dpkg-dev
- name: Install libpng dev headers for MinGW - name: Install libpng dev headers for MinGW
run: | run: |
sudo ./.github/scripts/mingw-w64-libpng-dev.sh ${{ matrix.triplet }} ./.github/scripts/mingw-w64-libpng-dev.sh ${{ matrix.triplet }}
- name: Cross-build Windows binaries - name: Cross-build Windows binaries
run: | run: |
make mingw${{ matrix.bits }} -kj Q= make mingw${{ matrix.bits }} -kj Q=