| 1 | #!/usr/bin/env bash |
| 2 | # Cross-build Posprint.app (universal: arm64 + x86_64) on Linux with |
| 3 | # cargo-zigbuild and the macOS SDK from the cargo-zigbuild image ($SDKROOT). |
| 4 | # Output: dist/macos-universal.zip (Posprint.app). Not notarized; the |
| 5 | # binaries carry the linker's ad-hoc signature only. |
| 6 | set -euo pipefail |
| 7 | cd "$(dirname "$0")/../.." |
| 8 | v="$(cat artifacts/version.txt)" |
| 9 | : "${SDKROOT:?SDKROOT (macOS SDK) is not set in this image}" |
| 10 | apt-get update -qq |
| 11 | apt-get install -y -qq zip llvm >/dev/null |
| 12 | lipo="$(command -v llvm-lipo || ls /usr/bin/llvm-lipo-* | head -n1)" |
| 13 | rustup target add aarch64-apple-darwin x86_64-apple-darwin |
| 14 | cargo zigbuild --release --locked --target universal2-apple-darwin |
| 15 | bin=target/universal2-apple-darwin/release/posprint |
| 16 | test -f "$bin" |
| 17 | app=target/macos/Posprint.app |
| 18 | rm -rf "$app"; mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" |
| 19 | for a in aarch64 x86_64; do |
| 20 | zig cc -target "$a-macos.11.0" -O2 -isysroot "$SDKROOT" \ |
| 21 | -F"$SDKROOT/System/Library/Frameworks" -L"$SDKROOT/usr/lib" -I"$SDKROOT/usr/include" \ |
| 22 | -framework Cocoa -o "target/macos/launcher-$a" packaging/macos/launcher.m |
| 23 | done |
| 24 | "$lipo" -create -output "$app/Contents/MacOS/posprint-launcher" target/macos/launcher-aarch64 target/macos/launcher-x86_64 |
| 25 | cp "$bin" "$app/Contents/MacOS/posprint-bin" |
| 26 | chmod 755 "$app/Contents/MacOS/"* |
| 27 | sed "s/@VERSION@/${v}/g" packaging/macos/Info.plist > "$app/Contents/Info.plist" |
| 28 | "$lipo" -info "$app/Contents/MacOS/posprint-bin" "$app/Contents/MacOS/posprint-launcher" |
| 29 | mkdir -p dist |
| 30 | (cd target/macos && rm -f ../../dist/macos-universal.zip && zip -qry ../../dist/macos-universal.zip Posprint.app) |
| 31 | ls -l dist/macos-universal.zip |