diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 6f7da733b..eb0be0c03 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -149,12 +149,20 @@ jobs: [ -f ccache.tar.xz ] && tar xf ccache.tar.xz || true [ -f workspacecache.tar ] && mv workspacecache.tar ${{ github.workspace }} || true - name: Install Dependencies - run: brew install llvm@21 ccache + run: | + brew install llvm@21 ccache gmp mpfr mpc + # current homebrew cmake segfaults when building the ppc binary + wget -O- https://github.com/Kitware/CMake/releases/download/v4.2.3/cmake-4.2.3-macos-universal.tar.gz | tar -xz - name: Build run: | [ -f workspacecache.tar ] && tar xf workspacecache.tar || true - LLVM_CONFIG="$(brew --prefix)/opt/llvm@21/bin/llvm-config" ./platforms/macos/build.sh - tar cf workspacecache.tar platforms/macos/build/work/toolchain + LLVM_CONFIG="$(brew --prefix)/opt/llvm@21/bin/llvm-config" \ + GMP="$(brew --prefix)" \ + MPFR="$(brew --prefix)" \ + MPC="$(brew --prefix)" \ + PATH="$PWD/cmake-4.2.3-macos-universal/CMake.app/Contents/bin:$PATH" \ + ./platforms/macos/build.sh + tar cf workspacecache.tar platforms/macos/build/work/toolchain platforms/macos/build/work/toolchain-ppc mv workspacecache.tar ~ env: NOSTRIP: 1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3d8de6b08..a7d948726 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -110,9 +110,18 @@ jobs: with: submodules: true - name: Install Dependencies - run: brew install llvm@21 + run: | + brew install llvm@21 gmp mpfr mpc + # current homebrew cmake segfaults when building the ppc binary + wget -O- https://github.com/Kitware/CMake/releases/download/v4.2.3/cmake-4.2.3-macos-universal.tar.gz | tar -xz - name: Build - run: LLVM_CONFIG="$(brew --prefix)/opt/llvm@21/bin/llvm-config" ./platforms/macos/build.sh + run: | + LLVM_CONFIG="$(brew --prefix)/opt/llvm@21/bin/llvm-config" \ + GMP="$(brew --prefix)" \ + MPFR="$(brew --prefix)" \ + MPC="$(brew --prefix)" \ + PATH="$PWD/cmake-4.2.3-macos-universal/CMake.app/Contents/bin:$PATH" \ + ./platforms/macos/build.sh - name: Pack release run: | mv platforms/macos/build/ReMCPE . @@ -144,7 +153,9 @@ jobs: libssl-dev - name: Build - run: ./platforms/ios/build.sh + run: | + ./platforms/ios/build.sh + mv platforms/ios/build/ReMCPE.ipa ReMCPE-iOS.ipa env: CLANG: clang-21 AR: llvm-ar-21 @@ -154,7 +165,7 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} with: - asset_paths: '["platforms/ios/build/ReMCPE.ipa"]' + asset_paths: '["ReMCPE-iOS.ipa"]' android: strategy: @@ -192,7 +203,7 @@ jobs: env: BUILD_TOOLS_VERSION: 36.1.0 - name: Rename APK - run: mv ${{ steps.sign_apk.outputs.signedReleaseFile }} ReMCPE.apk + run: mv ${{ steps.sign_apk.outputs.signedReleaseFile }} ReMCPE-Android.apk - uses: alexellis/upload-assets@0.4.1 env: GITHUB_TOKEN: ${{ github.token }} diff --git a/platforms/ios/build.sh b/platforms/ios/build.sh index 948d76ada..5b5e8e7c0 100755 --- a/platforms/ios/build.sh +++ b/platforms/ios/build.sh @@ -45,11 +45,9 @@ fi if [ "$(uname -s)" = "Darwin" ]; then ar="${AR:-ar}" ranlib="${RANLIB:-ranlib}" - strip='strip' else ar="${AR:-"llvm-ar"}" ranlib="${RANLIB:-"llvm-ranlib"}" - strip='cctools-strip' fi for var in ar ranlib; do @@ -124,10 +122,10 @@ if [ -n "$outdated_toolchain" ]; then mv ld64/src/ld/ld ../../toolchain/bin/ld64.ld64 make -C libmacho -j"$ncpus" make -C libstuff -j"$ncpus" - make -C misc strip lipo + make -C misc strip lipo -j"$ncpus" strip misc/strip misc/lipo - cp misc/strip ../../toolchain/bin/cctools-strip - cp misc/lipo ../../toolchain/bin/lipo + mv misc/strip ../../toolchain/bin/cctools-strip + mv misc/lipo ../../toolchain/bin/lipo cd ../.. rm -rf "cctools-port-$cctools_commit" @@ -199,7 +197,7 @@ for target in $targets; do done lipo -create build-*/"$bin" -output "$bin" -[ -z "$DEBUG" ] && [ -z "$NOSTRIP" ] && "$strip" -no_code_signature_warning "$bin" +[ -z "$DEBUG" ] && [ -z "$NOSTRIP" ] && cctools-strip -no_code_signature_warning "$bin" if command -v ldid >/dev/null; then ldid -S"$entitlements" "$bin" else diff --git a/platforms/macos/arch.c b/platforms/macos/arch.c index aea8064dd..1c1cc84f5 100644 --- a/platforms/macos/arch.c +++ b/platforms/macos/arch.c @@ -9,10 +9,12 @@ int main(void) { puts("i386"); #elif defined(__aarch64__) puts("arm64"); -#elif defined(__powerpc64__) +#elif defined(__POWERPC__) +#ifdef __LP64__ puts("ppc64"); -#elif defined(__powerpc__) +#else puts("powerpc"); +#endif #else #error unknown mac architecture #endif diff --git a/platforms/macos/build.sh b/platforms/macos/build.sh index 383cd67ab..5dbe09b7e 100755 --- a/platforms/macos/build.sh +++ b/platforms/macos/build.sh @@ -5,7 +5,7 @@ set -e [ "${0%/*}" = "$0" ] && scriptroot="." || scriptroot="${0%/*}" cd "$scriptroot" -# TODO: powerpc +# powerpc is handled further down targets='i386-apple-macos10.4 x86_64-apple-macos10.7 arm64-apple-macos11.0' # Must be kept in sync with the cmake executable name bin='reminecraftpe' @@ -21,7 +21,7 @@ cd "$workdir" # Increase this if we ever make a change to the SDK, for example # using a newer SDK version, and we need to invalidate the cache. -sdkver=2 +sdkver=3 if ! [ -d "$x86_64_sdk" ] || ! [ -d "$arm64_sdk" ] || ! [ -d "$old_sdk" ] || [ "$(cat sdks/sdkver 2>/dev/null)" != "$sdkver" ]; then printf '\nDownloading macOS SDKs...\n\n' ( @@ -66,24 +66,6 @@ else ncpus="$(sysctl -n hw.ncpu)" fi -if [ "$(uname -s)" = "Darwin" ]; then - ar="${AR:-ar}" - ranlib="${RANLIB:-ranlib}" - strip='strip' -else - ar="${AR:-"llvm-ar"}" - ranlib="${RANLIB:-"llvm-ranlib"}" - strip='cctools-strip' -fi - -for var in ar ranlib; do - dep="$(eval "echo \$$var")" - if ! command -v "$dep" >/dev/null; then - printf '%s not found!\n' "$dep" - exit 1 - fi -done - for dep in "${CLANG:-clang}" make cmake; do if ! command -v "$dep" >/dev/null; then printf '%s not found!\n' "$dep" @@ -101,7 +83,7 @@ fi # Increase this if we ever make a change to the toolchain, for example # using a newer cctools-port version, and we need to invalidate the cache. -toolchainver=1 +toolchainver=2 if [ "$(cat toolchain/toolchainver 2>/dev/null)" != "$toolchainver" ]; then rm -rf toolchain outdated_toolchain=1 @@ -116,7 +98,7 @@ fi mkdir -p toolchain/bin mv toolchainsettings toolchain/lasttoolchainsettings -export PATH="$PWD/toolchain/bin:$PATH" +export PATH="$PWD/toolchain/bin:$PWD/toolchain-ppc/bin:$PATH" if [ -n "$CLANG" ]; then ln -sf "$(command -v "$CLANG")" toolchain/bin/clang && ln -sf clang toolchain/bin/clang++ @@ -156,6 +138,7 @@ if [ -n "$outdated_toolchain" ]; then --enable-silent-rules \ --with-llvm-config="$LLVM_CONFIG" \ --with-libtapi="$workdir/toolchain" \ + --target=i386-apple-darwin \ CC=remcpe-clang \ CXX=remcpe-clang++ make -C ld64 -j"$ncpus" @@ -163,10 +146,16 @@ if [ -n "$outdated_toolchain" ]; then mv ld64/src/ld/ld ../../toolchain/bin/ld64.ld64 make -C libmacho -j"$ncpus" make -C libstuff -j"$ncpus" - make -C misc strip lipo - strip misc/strip misc/lipo - cp misc/strip ../../toolchain/bin/cctools-strip - cp misc/lipo ../../toolchain/bin/lipo + make -C misc strip lipo ranlib -j"$ncpus" + strip misc/strip misc/lipo misc/ranlib + mv misc/strip ../../toolchain/bin/cctools-strip + mv misc/lipo ../../toolchain/bin/lipo + mv misc/ranlib ../../toolchain/bin/cctools-ranlib + ln -s cctools-ranlib ../../toolchain/bin/i386-apple-darwin-ranlib # so ar can find ranlib + make -C ar + strip ar/ar + mv ar/ar ../../toolchain/bin/cctools-ar + cd ../.. rm -rf "cctools-port-$cctools_commit" @@ -188,6 +177,85 @@ if [ -n "$outdated_toolchain" ]; then printf '%s' "$toolchainver" > toolchain/toolchainver fi +# The PPC toolchain is separate from the regular toolchain because +# it doesn't use llvm for LTO, so it doesn't get invalidated when llvm-config's +# version changes + +# Increase this if we ever make a change to the toolchain, for example +# using a newer GCC version, and we need to invalidate the cache. +ppctoolchainver=1 +ppc_triple='powerpc-apple-darwin8' +targets="$targets $ppc_triple" +if [ "$(cat toolchain-ppc/toolchainver 2>/dev/null)" != "$ppctoolchainver" ]; then + printf '\nBuilding powerpc toolchain...\n\n' + + rm -rf toolchain-ppc + mkdir -p toolchain-ppc/bin + + # building the real dsymutil would require a partial LLVM build, we don't need debug info that bad + printf '#!/bin/sh\nexit 0\n' > "toolchain-ppc/bin/$ppc_triple-dsymutil" + chmod +x "toolchain-ppc/bin/$ppc_triple-dsymutil" + + cctools_commit=a35aa0162cb2614e68db577a28fdd903fae47f20 + rm -rf cctools-port-* + wget -O- "https://github.com/Un1q32/cctools-port/archive/$cctools_commit.tar.gz" | tar -xz + + cd "cctools-port-$cctools_commit/cctools" + ./configure \ + --target="$ppc_triple" \ + --enable-silent-rules \ + --with-llvm-config=false \ + CC=remcpe-clang \ + CXX=remcpe-clang++ + make -C ld64 -j"$ncpus" + strip ld64/src/ld/ld + mv ld64/src/ld/ld ../../toolchain-ppc/bin/ppc-ld + make -C libstuff -j"$ncpus" + make -C misc nm strip -j"$ncpus" + strip misc/nm misc/strip + mv misc/nm ../../toolchain-ppc/bin/ppc-nm + mv misc/strip ../../toolchain-ppc/bin/ppc-strip + make -C as/ppc -j"$ncpus" + strip as/ppc/ppc-as + mv as/ppc/ppc-as ../../toolchain-ppc/bin/ppc-as + + cd ../.. + rm -rf "cctools-port-$cctools_commit" + + gcc_version='15.2.0' + rm -rf gcc-* + wget -O- "https://ftp.gnu.org/gnu/gcc/gcc-$gcc_version/gcc-$gcc_version.tar.xz" | tar -xJ + + cd "gcc-$gcc_version" + mkdir build + cd build + set -- + [ -n "$GMP" ] && set -- --with-gmp="$GMP" + [ -n "$MPFR" ] && set -- "$@" --with-mpfr="$MPFR" + [ -n "$MPC" ] && set -- "$@" --with-mpc="$MPC" + ../configure \ + --prefix="$workdir/toolchain-ppc" \ + --target="$ppc_triple" \ + --disable-multilib \ + --enable-lto \ + --with-system-zlib \ + --enable-languages=c,c++,objc,lto \ + --with-sysroot="$old_sdk" \ + --with-as="$(command -v ppc-as)" \ + --with-ld="$(command -v ppc-ld)" \ + AR_FOR_TARGET="$(command -v cctools-ar)" \ + RANLIB_FOR_TARGET="$(command -v cctools-ranlib)" \ + NM_FOR_TARGET="$(command -v ppc-nm)" \ + LIPO_FOR_TARGET="$(command -v lipo)" \ + "$@" + make -j"$ncpus" + make -j"$ncpus" install + cd ../.. + rm -rf "gcc-$gcc_version" + + printf '%s' "$ppctoolchainver" > toolchain-ppc/toolchainver +fi + # checks if the linker we build successfully linked with LLVM and supports LTO, # and enables LTO in the cmake build if it does. if [ -z "$DEBUG" ]; then @@ -222,11 +290,20 @@ for target in $targets; do cd "build-$target" arch="${target%%-*}" + cc="$platformdir/macos-cc" + cxx="$platformdir/macos-c++" case $arch in - (i386) - target_cflags="$cflags -march=pentium-m" + (i386|powerpc*) + if [ "$arch" = 'i386' ]; then + target_cflags="$cflags -march=pentium-m" + set -- -DCMAKE_EXE_LINKER_FLAGS='-framework IOKit -framework Carbon -framework AudioUnit -undefined dynamic_lookup' + else + target_cflags= + cc="$target-gcc" + cxx="$target-g++" + set -- -DCMAKE_EXE_LINKER_FLAGS='-framework IOKit -framework Carbon -framework AudioUnit -static-libgcc' + fi export REMCPE_SDK="$old_sdk" - set -- -DCMAKE_EXE_LINKER_FLAGS='-framework IOKit -framework Carbon -framework AudioUnit -undefined dynamic_lookup' platform='sdl1' sdl1ver=1 if ! [ -f sdl/lib/libSDL.a ] || [ "$(cat sdl/sdl1ver 2>/dev/null)" != "$sdl1ver" ]; then @@ -241,20 +318,29 @@ for target in $targets; do if [ -n "$DEBUG" ]; then opt='-O0' else - opt='-O2' + if [ "$arch" = 'i386' ]; then + opt='-O2' + else + opt='-O2 -flto' + fi + fi + if [ "$arch" != 'i386' ]; then + sed -e 's/-fpascal-strings//g' configure > configure.patched + mv configure.patched configure + chmod +x configure fi ./configure \ --host="$arch-apple-darwin" \ --prefix="${PWD%/*}/sdl" \ --disable-shared \ --disable-video-x11 \ - CC="$platformdir/macos-cc" \ - CXX="$platformdir/macos-c++" \ - CFLAGS="$opt $cflags" \ - CXXFLAGS="$opt $cflags" \ + CC="$cc" \ + CXX="$cxx" \ + CFLAGS="$opt $target_cflags" \ + CXXFLAGS="$opt $target_cflags" \ CPPFLAGS='-DNDEBUG' \ - AR="$ar" \ - RANLIB="$ranlib" + AR=cctools-ar \ + RANLIB=cctools-ranlib make -j"$ncpus" make install -j"$ncpus" cd .. @@ -290,10 +376,10 @@ for target in $targets; do -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ - -DCMAKE_AR="$(command -v "$ar")" \ - -DCMAKE_RANLIB="$(command -v "$ranlib")" \ - -DCMAKE_C_COMPILER="$platformdir/macos-cc" \ - -DCMAKE_CXX_COMPILER="$platformdir/macos-c++" \ + -DCMAKE_AR="$(command -v cctools-ar)" \ + -DCMAKE_RANLIB="$(command -v cctools-ranlib)" \ + -DCMAKE_C_COMPILER="$cc" \ + -DCMAKE_CXX_COMPILER="$cxx" \ -DCMAKE_FIND_ROOT_PATH="$REMCPE_SDK/usr;$PWD/sdl" \ -DCMAKE_SYSROOT="$REMCPE_SDK" \ -DCMAKE_C_FLAGS="$target_cflags" \ @@ -319,18 +405,22 @@ REMCPE_TARGET='unknown-apple-macos10.4' \ -arch x86_64 -arch i386 \ "$platformdir/arch.c" -Os -o arch-x86 -lipo -create arch-* -output arch -mv arch ../ReMCPE/libexec/arch +lipo -create arch-* -output ../ReMCPE/libexec/arch [ -z "$DEBUG" ] && [ -z "$NOSTRIP" ] && - "$strip" -no_code_signature_warning ../ReMCPE/libexec/arch + cctools-strip -no_code_signature_warning ../ReMCPE/libexec/arch cp -a "$platformdir/../../game/assets" ../ReMCPE cp "$platformdir/launchscript.sh" "../ReMCPE/$bin" for target in $targets; do - cp "build-$target/$bin" "../ReMCPE/libexec/$bin-${target%%-*}" + arch="${target%%-*}" + cp "build-$target/$bin" "../ReMCPE/libexec/$bin-$arch" + case $arch in + (powerpc*|ppc*) strip='ppc-strip' ;; + (*) strip='cctools-strip -no_code_signature_warning' ;; + esac [ -z "$DEBUG" ] && [ -z "$NOSTRIP" ] && - "$strip" -no_code_signature_warning "../ReMCPE/libexec/$bin-${target%%-*}" + $strip "../ReMCPE/libexec/$bin-${target%%-*}" done if command -v ldid >/dev/null; then ldid -S ../ReMCPE/libexec/arch "../ReMCPE/libexec/$bin-arm64"* diff --git a/platforms/macos/launchscript.sh b/platforms/macos/launchscript.sh index d506632ba..4ff900e34 100755 --- a/platforms/macos/launchscript.sh +++ b/platforms/macos/launchscript.sh @@ -8,16 +8,20 @@ # from this script. execdir="${0%/*}" + +[ "$(arch)" = "ppc" ] && + exec "$execdir/libexec/reminecraftpe-powerpc" "$@" + arch="$("$execdir/libexec/arch")" if [ "$arch" = "x86_64" ]; then case $(uname -r) in (8.*|9.*|10.*) # Tiger, Leopard, or Snow Leopard - exec "$execdir/libexec/reminecraftpe-i386" + exec "$execdir/libexec/reminecraftpe-i386" "$@" ;; (*) - exec "$execdir/libexec/reminecraftpe-x86_64" + exec "$execdir/libexec/reminecraftpe-x86_64" "$@" ;; esac fi diff --git a/platforms/macos/leopard-sdk-fix.patch b/platforms/macos/leopard-sdk-fix.patch index 46713c1ec..e64c4a85f 100644 --- a/platforms/macos/leopard-sdk-fix.patch +++ b/platforms/macos/leopard-sdk-fix.patch @@ -13,3 +13,14 @@ #ifndef __SCSI__ #include #endif +--- a/usr/include/sys/signal.h ++++ b/usr/include/sys/signal.h +@@ -121,7 +121,7 @@ + #define SIGUSR1 30 /* user defined signal 1 */ + #define SIGUSR2 31 /* user defined signal 2 */ + +-#if defined(_ANSI_SOURCE) || __DARWIN_UNIX03 || defined(__cplusplus) ++#if 1 + /* + * Language spec sez we must list exactly one parameter, even though we + * actually supply three. Ugh!