diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 859cd30605..28a70be178 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -14,6 +14,7 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'po/**.po' + - 'util/ci/**' - '.github/workflows/macos.yml' pull_request: paths: @@ -27,87 +28,93 @@ on: - '**/CMakeLists.txt' - 'cmake/Modules/**' - 'po/**.po' + - 'util/ci/**' - '.github/workflows/macos.yml' jobs: - build-intel-macos: - # use lowest possible macOS running on x86_64 supported by brew to support more users - runs-on: macos-13 + build-older-macos: + strategy: + matrix: + osver: [11.3] + xcodever: [16.2] + arch: ["x86_64"] + build_type: ["Debug"] + xcode: ["no"] + include: + - osver: 11.3 + xcodever: 16.2 + arch: "x86_64" + build_type: "Debug" + xcode: "no" + - osver: 11.3 + xcodever: 16.2 + arch: "arm64" + build_type: "Release" + xcode: "yes" + runs-on: macos-15 steps: - uses: actions/checkout@v4 + + - name: Prepare environment + run: | + echo "REPDIR=$(pwd)" >> $GITHUB_ENV + echo "osver=${{matrix.osver}}" >> $GITHUB_ENV + echo "xcodever=${{matrix.xcodever}}" >> $GITHUB_ENV + echo "arch=${{matrix.arch}}" >> $GITHUB_ENV + echo "build_type=${{matrix.build_type}}" >> $GITHUB_ENV + - name: Install deps run: | + mkdir downloads source ./util/ci/common.sh - install_macos_deps + source ./util/ci/macos_sdk.sh + install_macos_precompiled_deps $osver $arch + install_macos_sdk $osver "$xcodever" downloads - - name: Build + - name: Build with GNU Make run: | mkdir build cd build - cmake .. \ - -DCMAKE_OSX_DEPLOYMENT_TARGET=13 \ - -DCMAKE_FIND_FRAMEWORK=LAST \ - -DCMAKE_INSTALL_PREFIX=../build/macos/ \ - -DRUN_IN_PLACE=FALSE -DENABLE_GETTEXT=TRUE \ - -DINSTALL_DEVTEST=TRUE - cmake --build . -j$(sysctl -n hw.logicalcpu) - make install + export DEPS_DIR=/Users/Shared/macos${osver}_${arch}_deps + export USE_XCODE=no + ../util/ci/build_macos.sh - - name: Test + - name: Build and Archive with Xcode + if: ${{matrix.xcode == 'yes'}} run: | + mkdir build_xcode + cd build_xcode + export DEPS_DIR=/Users/Shared/macos${osver}_${arch}_deps + export USE_XCODE=yes + ../util/ci/build_macos.sh + + - name: Test GNU Make build + run: | + mkdir -p "${HOME}/Library/Application Support/minetest/games/" + ln -s "${PWD}/games/devtest" "${HOME}/Library/Application Support/minetest/games/" ./build/macos/luanti.app/Contents/MacOS/luanti --run-unittests + - name: Test XCode build + if: ${{matrix.xcode == 'yes'}} + run: | + ./build_xcode/build/${build_type}/luanti.app/Contents/MacOS/luanti --run-unittests + ./build_xcode/luanti.xcarchive/Products/Applications/luanti.app/Contents/MacOS/luanti --run-unittests + + - name: Diff Resources + if: ${{matrix.xcode == 'yes'}} + run: | + diff -rd ./build/macos/luanti.app/Contents/Resources ./build_xcode/build/${build_type}/luanti.app/Contents/Resources || exit 1 + diff -rd ./build/macos/luanti.app/Contents/Resources ./build_xcode/luanti.xcarchive/Products/Applications/luanti.app/Contents/Resources || exit 1 # Zipping the built .app preserves permissions on the contained files, # which the GitHub artifact pipeline would otherwise strip away. - name: CPack run: | cd build rm -rf macos - cmake .. -DINSTALL_DEVTEST=FALSE cpack -G ZIP -B macos - - uses: actions/upload-artifact@v4 + - name: Upload + uses: actions/upload-artifact@v4 with: - name: luanti-macos + name: luanti-macos${{matrix.osver}}_${{matrix.arch}} path: ./build/macos/*.zip - build-arm-macos-xcode: - runs-on: macos-14 - steps: - - uses: actions/checkout@v4 - - name: Install deps - run: | - source ./util/ci/common.sh - install_macos_deps - # brew jsoncpp do not include libjsoncpp.a, and if installed header conflict caused build failure - brew uninstall jsoncpp - - - name: Build with Cmake - run: | - mkdir build - cd build - cmake .. \ - -DCMAKE_OSX_DEPLOYMENT_TARGET=14 \ - -DCMAKE_FIND_FRAMEWORK=LAST \ - -DCMAKE_INSTALL_PREFIX=../build/macos/ \ - -DRUN_IN_PLACE=FALSE -DENABLE_GETTEXT=TRUE \ - -DENABLE_SYSTEM_JSONCPP=OFF - cmake --build . -j$(sysctl -n hw.logicalcpu) - make install - - - name: Build and Archive with Xcode - run: | - mkdir build_xcode - cd build_xcode - ../util/ci/build_xcode.sh - - - name: Tests - run: | - mkdir -p "${HOME}/Library/Application Support/minetest/games/" - ln -s "${PWD}/games/devtest" "${HOME}/Library/Application Support/minetest/games/" - ./build/macos/luanti.app/Contents/MacOS/luanti --run-unittests - ./build_xcode/luanti.xcarchive/Products/Applications/luanti.app/Contents/MacOS/luanti --run-unittests - - - name: Diff Resources - run: | - diff -rd ./build/macos/luanti.app/Contents/Resources ./build_xcode/build/Release/luanti.app/Contents/Resources || exit 1 - diff -rd ./build/macos/luanti.app/Contents/Resources ./build_xcode/luanti.xcarchive/Products/Applications/luanti.app/Contents/Resources || exit 1 diff --git a/irr/include/WeightBuffer.h b/irr/include/WeightBuffer.h index 073a73987b..2fa3230292 100644 --- a/irr/include/WeightBuffer.h +++ b/irr/include/WeightBuffer.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace scene { diff --git a/util/ci/build_macos.sh b/util/ci/build_macos.sh new file mode 100755 index 0000000000..1274fd6add --- /dev/null +++ b/util/ci/build_macos.sh @@ -0,0 +1,59 @@ +#!/bin/bash -e + +sudo xcode-select -s /Applications/Xcode_${xcodever}.app/Contents/Developer +sdkroot="$(realpath $(xcrun --sdk macosx --show-sdk-path)/../MacOSX${osver}.sdk)" +export CMAKE_PREFIX_PATH=${DEPS_DIR} +export SDKROOT="$sdkroot" + +THIS_DIR=$(pwd) + +# common args +cmake_args=( + -DCMAKE_OSX_DEPLOYMENT_TARGET=$osver + -DCMAKE_FIND_FRAMEWORK=LAST + -DCMAKE_OSX_ARCHITECTURES=${arch} + -DCMAKE_INSTALL_PREFIX=${THIS_DIR}/macos/ + -DCMAKE_BUILD_TYPE=${build_type} + -DCMAKE_FIND_FRAMEWORK=LAST + -DRUN_IN_PLACE=FALSE + -DENABLE_GETTEXT=TRUE + -DJPEG_LIBRARY=${DEPS_DIR}/lib/libjpeg.a + -DJPEG_INCLUDE_DIR=${DEPS_DIR}/include + -DPNG_LIBRARY=${DEPS_DIR}/lib/libpng.a + -DPNG_PNG_INCLUDE_DIR=${DEPS_DIR}/include + -DFREETYPE_LIBRARY=${DEPS_DIR}/lib/libfreetype.a + -DFREETYPE_INCLUDE_DIRS=${DEPS_DIR}/include/freetype2 + -DGETTEXT_INCLUDE_DIR=${DEPS_DIR}/include + -DGETTEXT_LIBRARY=${DEPS_DIR}/lib/libintl.a + -DLUA_LIBRARY=${DEPS_DIR}/lib/libluajit-5.1.a + -DLUA_INCLUDE_DIR=${DEPS_DIR}/include/luajit-2.1 + -DOGG_LIBRARY=${DEPS_DIR}/lib/libogg.a + -DOGG_INCLUDE_DIR=${DEPS_DIR}/include + -DVORBIS_LIBRARY=${DEPS_DIR}/lib/libvorbis.a + -DVORBISFILE_LIBRARY=${DEPS_DIR}/lib/libvorbisfile.a + -DVORBIS_INCLUDE_DIR=${DEPS_DIR}/include + -DZSTD_LIBRARY=${DEPS_DIR}/lib/libzstd.a + -DZSTD_INCLUDE_DIR=${DEPS_DIR}/include + -DGMP_LIBRARY=${DEPS_DIR}/lib/libgmp.a + -DGMP_INCLUDE_DIR=${DEPS_DIR}/include + -DJSON_LIBRARY=${DEPS_DIR}/lib/libjsoncpp.a + -DJSON_INCLUDE_DIR=${DEPS_DIR}/include + -DENABLE_LEVELDB=OFF + -DENABLE_POSTGRESQL=OFF + -DENABLE_REDIS=OFF + -DCMAKE_EXE_LINKER_FLAGS=-lbz2 +) +if [ "$USE_XCODE" == "yes" ]; then + cmake_args+=(-GXcode) +fi + +cmake .. "${cmake_args[@]}" + +if [ "$USE_XCODE" == "yes" ]; then + xcodebuild -project luanti.xcodeproj -scheme luanti -configuration Release build + xcodebuild -project luanti.xcodeproj -scheme luanti -archivePath ./luanti.xcarchive archive +else + cmake --build . -j$(sysctl -n hw.logicalcpu) + make install +fi + diff --git a/util/ci/build_xcode.sh b/util/ci/build_xcode.sh deleted file mode 100755 index 8d36b2815c..0000000000 --- a/util/ci/build_xcode.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -e - -cmake .. \ - -DCMAKE_FIND_FRAMEWORK=LAST \ - -DRUN_IN_PLACE=FALSE -DENABLE_GETTEXT=TRUE \ - -DUSE_SDL2_STATIC=TRUE \ - -DSDL2_INCLUDE_DIRS=/opt/homebrew/include/SDL2 \ - -DFREETYPE_LIBRARY=/opt/homebrew/lib/libfreetype.a \ - -DGETTEXT_INCLUDE_DIR=/opt/homebrew/include \ - -DGETTEXT_LIBRARY=/opt/homebrew/lib/libintl.a \ - -DLUA_LIBRARY=/opt/homebrew/lib/libluajit-5.1.a \ - -DOGG_LIBRARY=/opt/homebrew/lib/libogg.a \ - -DVORBIS_LIBRARY=/opt/homebrew/lib/libvorbis.a \ - -DVORBISFILE_LIBRARY=/opt/homebrew/lib/libvorbisfile.a \ - -DZSTD_LIBRARY=/opt/homebrew/lib/libzstd.a \ - -DGMP_LIBRARY=/opt/homebrew/lib/libgmp.a \ - -DENABLE_SYSTEM_JSONCPP=OFF \ - -DENABLE_LEVELDB=OFF \ - -DENABLE_POSTGRESQL=OFF \ - -DENABLE_REDIS=OFF \ - -DJPEG_LIBRARY=/opt/homebrew/lib/libjpeg.a \ - -DPNG_LIBRARY=/opt/homebrew/lib/libpng.a \ - -DCMAKE_EXE_LINKER_FLAGS=-lbz2\ - -GXcode -xcodebuild -project luanti.xcodeproj -scheme luanti -configuration Release build -xcodebuild -project luanti.xcodeproj -scheme luanti -archivePath ./luanti.xcarchive archive diff --git a/util/ci/common.sh b/util/ci/common.sh index bd653a2c82..899982965d 100644 --- a/util/ci/common.sh +++ b/util/ci/common.sh @@ -33,10 +33,9 @@ install_linux_deps() { } # macOS build only -install_macos_deps() { +install_macos_brew_deps() { # Uninstall the bundled cmake, it is outdated, and brew does not want to install the newest version with this one present since they are from different taps. brew uninstall cmake || : - local pkgs=( cmake gettext freetype gmp jpeg-turbo jsoncpp leveldb libogg libpng libvorbis luajit zstd sdl2 @@ -49,3 +48,24 @@ install_macos_deps() { brew unlink $(brew ls --formula) brew link "${pkgs[@]}" } + +install_macos_precompiled_deps() { + osver=$1 + arch=$2 + + local pkgs=( + cmake wget + ) + export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1 + export HOMEBREW_NO_INSTALL_CLEANUP=1 + # contrary to how it may look --auto-update makes brew do *less* + brew update --auto-update + brew install --display-times "${pkgs[@]}" + brew unlink $(brew ls --formula) + brew link "${pkgs[@]}" + + cd /Users/Shared + wget -O macos${osver}_${arch}_deps.tar.gz https://github.com/luanti-org/luanti_macos_deps/releases/download/latest/macos${osver}_${arch}_deps.tar.gz + tar -xf macos${osver}_${arch}_deps.tar.gz + cd ~ +} diff --git a/util/ci/macos_sdk.sh b/util/ci/macos_sdk.sh new file mode 100755 index 0000000000..d49f575d0d --- /dev/null +++ b/util/ci/macos_sdk.sh @@ -0,0 +1,76 @@ +#!/bin/bash -e + +download_macos_archive() { + rm -f $1 + wget -O $1 $2 + checksum=$(shasum -a 256 $1 | cut -d " " -f 1) + if [[ "$checksum" != "$3" ]]; then + echo "Downloaded file $1 has unexpected checksum $checksum." + exit 1 + fi +} + +update_xcode_plist() { + plist=$1 + minsdk=#2 + + cp $plist Info.plist + plutil -convert xml1 Info.plist + sed -i '' "/MinimumSDKVersion<\/key>/{n;s/.*<\/string>/$minsdk<\/string>/;}" Info.plist + plutil -convert binary1 Info.plist + cp Info.plist $plist +} + +install_macos_sdk() { + osver=$1 + xcodever=$2 + downdir=$3 + + dir=$(pwd) + + # setup environment + xcodeapp="Xcode.app" + if [[ -n $xcodever ]]; then + xcodeapp="Xcode_$xcodever.app" + fi + sysroot="/Applications/$xcodeapp/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${osver}.sdk" + if [ ! -d "$sysroot" ]; then + if [ ! -d "/Applications/$xcodeapp/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" ]; then + echo "No location for install SDK found. Xcode is probably not installed. (sysroot = $sysroot)" + exit 1 + fi + if [[ "$osver" == "11.3" ]]; then + download_macos_archive $downdir/SDK.tar.bz2 \ + https://github.com/alexey-lysiuk/macos-sdk/releases/download/11.3/MacOSX11.3.tar.bz2 \ + d6604578f4ee3090d1c3efce1e5c336ecfd7be345d046c729189d631ea3b8ec6 + tar -xf $downdir/SDK.tar.bz2 + mv MacOSX11.3.sdk $sysroot + update_xcode_plist "/Applications/$xcodeapp/Contents/Developer/Platforms/MacOSX.platform/Info.plist" $osver + elif [[ "$osver" == "12.3" ]]; then + download_macos_archive $downdir/SDK.tar.bz2 \ + https://github.com/alexey-lysiuk/macos-sdk/releases/download/12.3/MacOSX12.3.tar.xz \ + 91c03be5399be04d8f6b773da13045525e01298c1dfff273b4e1f1e904ee5484 + tar -xf $downdir/SDK.tar.bz2 + mv MacOSX12.3.sdk $sysroot + update_xcode_plist "/Applications/$xcodeapp/Contents/Developer/Platforms/MacOSX.platform/Info.plist" $osver + elif [[ "$osver" == "13.3" ]]; then + download_macos_archive $downdir/SDK.tar.bz2 \ + https://github.com/alexey-lysiuk/macos-sdk/releases/download/13.3/MacOSX13.3.tar.xz \ + 71ae3a78ab1be6c45cf52ce44cb29a3cc27ed312c9f7884ee88e303a862a1404 + tar -xf $downdir/SDK.tar.bz2 + mv MacOSX13.3.sdk $sysroot + elif [[ "$osver" == "14.5" ]]; then + download_macos_archive $downdir/SDK.tar.bz2 \ + https://github.com/alexey-lysiuk/macos-sdk/releases/download/14.5/MacOSX14.5.tar.xz \ + f6acc6209db9d56b67fcaf91ec1defe48722e9eb13dc21fb91cfeceb1489e57e + tar -xf $downdir/SDK.tar.bz2 + mv MacOSX14.5.sdk $sysroot + else + echo "This SDK target is not supported. (osver = $osver)" + exit 1 + fi + echo "SDK downloaded and added to Xcode." + else + echo "SDK found in Xcode. (sysroot = $sysroot)" + fi +}