From 925382dc3e993b0c2b66a8e413066d4e8fa4f334 Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sun, 7 Jul 2024 11:49:08 -0700 Subject: [PATCH] Make make_pkg.sh create fat binaries again on macOS --- .github/workflows/mac_codesign.yml | 2 ++ build_tools/make_pkg.sh | 53 +++++++++++++++++++++++++++--- cmake/MacApp.cmake | 15 +-------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/.github/workflows/mac_codesign.yml b/.github/workflows/mac_codesign.yml index 501a7f230..728c92bc2 100644 --- a/.github/workflows/mac_codesign.yml +++ b/.github/workflows/mac_codesign.yml @@ -10,6 +10,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.79 + with: + targets: aarch64-apple-darwin,x86_64-apple-darwin - name: build-and-codesign run: | cargo install apple-codesign diff --git a/build_tools/make_pkg.sh b/build_tools/make_pkg.sh index 7f293d65f..5dc0272fc 100755 --- a/build_tools/make_pkg.sh +++ b/build_tools/make_pkg.sh @@ -60,11 +60,42 @@ echo "$PKGDIR" SRC_DIR=$PWD OUTPUT_PATH=${FISH_ARTEFACT_PATH:-~/fish_built} -mkdir -p "$PKGDIR/build" "$PKGDIR/root" "$PKGDIR/intermediates" "$PKGDIR/dst" +mkdir -p "$PKGDIR/build_x86_64" "$PKGDIR/build_arm64" "$PKGDIR/root" "$PKGDIR/intermediates" "$PKGDIR/dst" +# Build and install for arm64. # Pass FISH_USE_SYSTEM_PCRE2=OFF because a system PCRE2 on macOS will not be signed by fish, # and will probably not be built universal, so the package will fail to validate/run on other systems. -{ cd "$PKGDIR/build" && cmake -DMAC_INJECT_GET_TASK_ALLOW=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" -DWITH_GETTEXT=OFF -DFISH_USE_SYSTEM_PCRE2=OFF -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' "$SRC_DIR" && make VERBOSE=1 -j 12 && env DESTDIR="$PKGDIR/root/" make install; } +# Note CMAKE_OSX_ARCHITECTURES is still relevant for the Mac app. +{ cd "$PKGDIR/build_arm64" \ + && cmake -DMAC_INJECT_GET_TASK_ALLOW=OFF \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \ + -DWITH_GETTEXT=OFF \ + -DRust_CARGO_TARGET=aarch64-apple-darwin \ + -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \ + -DFISH_USE_SYSTEM_PCRE2=OFF \ + "$SRC_DIR" \ + && make VERBOSE=1 -j 12 \ + && env DESTDIR="$PKGDIR/root/" make install; +} + +# Build for x86-64 but do not install; instead we will make some fat binaries inside the root. +{ cd "$PKGDIR/build_x86_64" \ + && cmake -DMAC_INJECT_GET_TASK_ALLOW=OFF \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DCMAKE_EXE_LINKER_FLAGS="-Wl,-ld_classic" \ + -DWITH_GETTEXT=OFF \ + -DRust_CARGO_TARGET=x86_64-apple-darwin \ + -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64' \ + -DFISH_USE_SYSTEM_PCRE2=OFF "$SRC_DIR" \ + && make VERBOSE=1 -j 12; } + +# Fatten them up. +for FILE in "$PKGDIR"/root/usr/local/bin/*; do + X86_FILE="$PKGDIR/build_x86_64/$(basename $FILE)" + rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE" + chmod 755 "$FILE" +done if test -n "$SIGN"; then echo "Signing executables" @@ -97,8 +128,19 @@ if test -n "$SIGN"; then fi # Make the app -cd "$PKGDIR/build" -make -j 12 fish_macapp +(cd "$PKGDIR/build_arm64" && make -j 12 fish_macapp) +(cd "$PKGDIR/build_x86_64" && make -j 12 fish_macapp) + +# Make the app's /usr/local/bin binaries universal. Note fish.app/Contents/MacOS/fish already is, courtsey of CMake. +cd "$PKGDIR/build_arm64" +for FILE in fish.app/Contents/Resources/base/usr/local/bin/*; do + X86_FILE="$PKGDIR/build_x86_64/fish.app/Contents/Resources/base/usr/local/bin/$(basename $FILE)" + rcodesign macho-universal-create --output "$FILE" "$FILE" "$X86_FILE" + + # macho-universal-create screws up the permissions. + chmod 755 "$FILE" +done + if test -n "$SIGN"; then echo "Signing app" ARGS=( @@ -113,7 +155,8 @@ if test -n "$SIGN"; then (set +x; rcodesign sign "${ARGS[@]}" "fish.app") fi -mv "fish.app" "$OUTPUT_PATH/fish-$VERSION.app" + +cp -R "fish.app" "$OUTPUT_PATH/fish-$VERSION.app" cd "$OUTPUT_PATH" # Maybe notarize. diff --git a/cmake/MacApp.cmake b/cmake/MacApp.cmake index 47072b2f8..e3e0abafa 100644 --- a/cmake/MacApp.cmake +++ b/cmake/MacApp.cmake @@ -61,18 +61,5 @@ add_custom_command(TARGET fish_macapp POST_BUILD # The entitlements file. set(MACAPP_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/osx/MacApp.entitlements") -# Target to sign the macapp. -# Note that a POST_BUILD step happens before resources are copied, -# and therefore would be too early. -add_custom_target(signed_fish_macapp - DEPENDS fish_macapp "${MACAPP_ENTITLEMENTS}" - COMMAND codesign --force --deep - --options runtime - --entitlements "${MACAPP_ENTITLEMENTS}" - --sign "${MAC_CODESIGN_ID}" - $ - VERBATIM -) - # Group our targets in a folder. -set_property(TARGET fish_macapp signed_fish_macapp PROPERTY FOLDER macapp) +set_property(TARGET fish_macapp PROPERTY FOLDER macapp)