Skip to content

Commit

Permalink
Add macOS universal library build support
Browse files Browse the repository at this point in the history
  • Loading branch information
RyeMutt committed Nov 19, 2024
1 parent c2234d7 commit 06f9d62
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
build:
strategy:
matrix:
os: [windows-2022, macos-14, ubuntu-22.04]
os: [windows-2022, macos-15, ubuntu-22.04]
addrsize: ["64"]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -24,13 +24,13 @@ jobs:
libwayland-dev libdecor-0-dev libdbus-1-dev libibus-1.0-dev fcitx-libs-dev \
libudev-dev libunwind-dev libdirectfb-dev libasound2-dev libpulse-dev \
libpipewire-0.3-dev ninja-build
- name: Setup macOS Build Dependencies
if: ${{ runner.os == 'macOS' }}
run: brew install ninja

- name: Build with autobuild
uses: secondlife/action-autobuild@v4
uses: secondlife/action-autobuild@v5
with:
addrsize: ${{ matrix.addrsize }}
release:
Expand Down
68 changes: 38 additions & 30 deletions build-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,42 +83,50 @@ case "$AUTOBUILD_PLATFORM" in
cp $stage/release/lib/*.lib $stage/lib/release/
cp $stage/release/include/SDL2/*.h $stage/include/SDL2/
popd

SDL_VERSION=$(sed -n -e 's/^Version: //p' "$TOP/$SDL_SOURCE_DIR/build_release/SDL2.spec")
;;
darwin*)
# Setup osx sdk platform
export MACOSX_DEPLOYMENT_TARGET="$LL_BUILD_DARWIN_DEPLOY_TARGET"

# Setup build flags
opts="${TARGET_OPTS:--arch $AUTOBUILD_CONFIGURE_ARCH $LL_BUILD_RELEASE}"

mkdir -p "$stage/include/SDL2"
mkdir -p "$stage/lib/release"

PREFIX_RELEASE="$stage/temp_release"
mkdir -p $PREFIX_RELEASE

mkdir -p "build_release"
pushd "build_release"
cmake .. -GNinja -DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_FLAGS="$(remove_cxxstd $opts)" \
-DCMAKE_CXX_FLAGS="$opts" \
-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
-DCMAKE_MACOSX_RPATH=YES \
-DCMAKE_INSTALL_PREFIX=$PREFIX_RELEASE

cmake --build . --config Release
cmake --install . --config Release
popd

cp -a $PREFIX_RELEASE/include/SDL2/*.* $stage/include/SDL2
cp -a $PREFIX_RELEASE/lib/*.dylib* $stage/lib/release
cp -a $PREFIX_RELEASE/lib/libSDL2main.a $stage/lib/release
for arch in x86_64 arm64 ; do
ARCH_ARGS="-arch $arch"
opts="${TARGET_OPTS:-$ARCH_ARGS $LL_BUILD_RELEASE}"
cc_opts="$(remove_cxxstd $opts)"
ld_opts="$ARCH_ARGS"

mkdir -p "build_$arch"
pushd "build_$arch"
CFLAGS="$cc_opts" \
CXXFLAGS="$opts" \
LDFLAGS="$ld_opts" \
cmake .. -GNinja -DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_C_FLAGS="$cc_opts" \
-DCMAKE_CXX_FLAGS="$opts" \
-DCMAKE_OSX_ARCHITECTURES:STRING="$arch" \
-DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} \
-DCMAKE_MACOSX_RPATH=YES \
-DCMAKE_INSTALL_PREFIX="$stage" \
-DCMAKE_INSTALL_LIBDIR="$stage/lib/release/$arch"

cmake --build . --config Release
cmake --install . --config Release
popd
done


# create universal libraries
lipo -create -output ${stage}/lib/release/libSDL2.dylib ${stage}/lib/release/x86_64/libSDL2.dylib ${stage}/lib/release/arm64/libSDL2.dylib
lipo -create -output ${stage}/lib/release/libSDL2_test.a ${stage}/lib/release/x86_64/libSDL2_test.a ${stage}/lib/release/arm64/libSDL2_test.a
lipo -create -output ${stage}/lib/release/libSDL2main.a ${stage}/lib/release/x86_64/libSDL2main.a ${stage}/lib/release/arm64/libSDL2main.a

pushd "${stage}/lib/release"
fix_dylib_id "libSDL2.dylib"
install_name_tool -id "@rpath/libSDL2.dylib" "libSDL2.dylib"
dsymutil libSDL2.dylib
strip -x -S libSDL2.dylib
popd

SDL_VERSION=$(sed -n -e 's/^Version: //p' "$TOP/$SDL_SOURCE_DIR/build_arm64/SDL2.spec")
;;
linux*)
# Default target per autobuild build --address-size
Expand All @@ -144,6 +152,8 @@ case "$AUTOBUILD_PLATFORM" in
cp -a $PREFIX_RELEASE/include/SDL2/*.* $stage/include/SDL2
cp -a $PREFIX_RELEASE/lib/*.so* $stage/lib/release
cp -a $PREFIX_RELEASE/lib/libSDL2main.a $stage/lib/release

SDL_VERSION=$(sed -n -e 's/^Version: //p' "$TOP/$SDL_SOURCE_DIR/build_release/SDL2.spec")
;;

*)
Expand All @@ -152,8 +162,6 @@ case "$AUTOBUILD_PLATFORM" in
esac
popd

SDL_VERSION=$(sed -n -e 's/^Version: //p' "$TOP/$SDL_SOURCE_DIR/build_release/SDL2.spec")

mkdir -p "$stage/LICENSES"
cp "$TOP/$SDL_SOURCE_DIR/LICENSE.txt" "$stage/LICENSES/SDL2.txt"
echo "$SDL_VERSION" > "$stage/VERSION.txt"

0 comments on commit 06f9d62

Please sign in to comment.