BlueGit

ict rusty-teams

Files

rusty-teams / scripts / build-macos.sh

build-macos.sh

c9c819d4 History
build-macos.sh 5.5 KiB Download Raw
1#!/usr/bin/env bash
2# Build a universal macOS binary (arm64 + x86_64) from a crate. Needs Xcode CLT only.
3# Wraps it in a .app bundle (icon, Info.plist) and zips that for distribution.
4# The published artifact is the `.app` zip. There is no in-app Mach-O swap.
5#
6# Optional signing / notarization when Apple credentials are present:
7# MACOS_CODESIGN_IDENTITY e.g. "Developer ID Application: …"
8# MACOS_NOTARY_PROFILE notarytool keychain profile (from `xcrun notarytool store-credentials`)
9# Without those env vars the .app stays unsigned (fine for local / internal RC).
10#
11# Usage: scripts/build-macos.sh [crate-dir, default crates/app] [binary-or-example-name, default: the crate's only binary]
12set -euo pipefail
13repoRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
14crateDir="$(realpath "${1:-$repoRoot/crates/app}")"
15binaryName="${2:-}"
16export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$repoRoot/target}"
17export PATH="$HOME/.cargo/bin:$PATH"
18entitlements="$repoRoot/scripts/macos/RustyTeams.entitlements"
19targets=(aarch64-apple-darwin x86_64-apple-darwin)
20
21rustup target add "${targets[@]}" >/dev/null
22
23buildArguments=(build --release)
24slicePathInTarget="release"
25if [ -n "$binaryName" ] && [ -f "$crateDir/examples/$binaryName.rs" ]; then
26 buildArguments+=(--example "$binaryName")
27 slicePathInTarget="release/examples"
28elif [ -n "$binaryName" ]; then
29 buildArguments+=(--bin "$binaryName")
30fi
31
32for target in "${targets[@]}"; do
33 (cd "$crateDir" && cargo "${buildArguments[@]}" --target "$target")
34done
35
36slices=()
37for target in "${targets[@]}"; do
38 sliceDirectory="$CARGO_TARGET_DIR/$target/$slicePathInTarget"
39 if [ -n "$binaryName" ]; then
40 slices+=("$sliceDirectory/$binaryName")
41 else
42 candidates=("$sliceDirectory"/*)
43 [ "${#candidates[@]}" -eq 1 ] && [ -f "${candidates[0]}" ] ||
44 { echo "more than one binary in $sliceDirectory, pass the name" >&2; exit 1; }
45 slices+=("${candidates[0]}")
46 fi
47done
48
49outputDirectory="$CARGO_TARGET_DIR/universal/release"
50mkdir -p "$outputDirectory"
51output="$outputDirectory/$(basename "${slices[0]}")"
52lipo -create -output "$output" "${slices[@]}"
53
54# Wrap the binary in a .app so Finder and the Dock treat it as an application:
55# double-clickable, with the icon, and with the camera / microphone / screen
56# permission prompts (macOS keys those off the bundle, not a bare binary).
57app="$outputDirectory/Rusty Teams.app"
58binary="$(basename "$output")"
59version="$(sed -n 's/^version = "\(.*\)"/\1/p' "$repoRoot/Cargo.toml" | head -1)"
60rm -rf "$app"
61mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
62cp "$output" "$app/Contents/MacOS/$binary"
63cat > "$app/Contents/Info.plist" <<PLIST
64<?xml version="1.0" encoding="UTF-8"?>
65<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
66<plist version="1.0">
67<dict>
68 <key>CFBundleName</key>
69 <string>Rusty Teams</string>
70 <key>CFBundleDisplayName</key>
71 <string>Rusty Teams</string>
72 <key>CFBundleIdentifier</key>
73 <string>org.rusty-teams.teams</string>
74 <key>CFBundleExecutable</key>
75 <string>$binary</string>
76 <key>CFBundleIconFile</key>
77 <string>icon</string>
78 <key>CFBundlePackageType</key>
79 <string>APPL</string>
80 <key>CFBundleShortVersionString</key>
81 <string>$version</string>
82 <key>CFBundleVersion</key>
83 <string>$version</string>
84 <key>NSHighResolutionCapable</key>
85 <true/>
86 <key>NSMicrophoneUsageDescription</key>
87 <string>Rusty Teams uses your microphone for calls.</string>
88 <key>NSCameraUsageDescription</key>
89 <string>Rusty Teams uses your camera for video calls.</string>
90 <key>NSScreenCaptureUsageDescription</key>
91 <string>Rusty Teams shares your screen in meetings.</string>
92</dict>
93</plist>
94PLIST
95
96# The same icon the Windows exe embeds (assets/icon/app.rc); iconutil compiles
97# whatever sizes the set has, all downscaled from the 256px original.
98iconset="$(mktemp -d)/teams.iconset"
99mkdir -p "$iconset"
100png="$repoRoot/crates/app/assets/icon/teams-fast-256.png"
101for size in 16 32 64 128 256; do
102 sips -z "$size" "$size" "$png" --out "$iconset/icon_${size}x${size}.png" >/dev/null
103done
104cp "$iconset/icon_32x32.png" "$iconset/icon_16x16@2x.png"
105cp "$iconset/icon_64x64.png" "$iconset/icon_32x32@2x.png"
106cp "$iconset/icon_256x256.png" "$iconset/icon_128x128@2x.png"
107iconutil -c icns "$iconset" -o "$app/Contents/Resources/icon.icns"
108
109# Developer ID signing when a certificate is configured in the build environment.
110if [ -n "${MACOS_CODESIGN_IDENTITY:-}" ]; then
111 echo "codesign with $MACOS_CODESIGN_IDENTITY"
112 codesign --force --options runtime --timestamp \
113 --entitlements "$entitlements" \
114 --sign "$MACOS_CODESIGN_IDENTITY" \
115 "$app/Contents/MacOS/$binary"
116 codesign --force --options runtime --timestamp \
117 --entitlements "$entitlements" \
118 --sign "$MACOS_CODESIGN_IDENTITY" \
119 "$app"
120 codesign --verify --deep --strict --verbose=2 "$app"
121fi
122
123# ditto keeps the bundle intact (plain zip would not); the result is the .app release asset.
124ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"
125
126if [ -n "${MACOS_CODESIGN_IDENTITY:-}" ] && [ -n "${MACOS_NOTARY_PROFILE:-}" ]; then
127 echo "notarize with profile $MACOS_NOTARY_PROFILE"
128 xcrun notarytool submit "$outputDirectory/teams-macos.zip" \
129 --keychain-profile "$MACOS_NOTARY_PROFILE" \
130 --wait
131 xcrun stapler staple "$app"
132 # Re-zip after staple so the published .app zip carries the ticket.
133 ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"
134fi
135
136file "$output"
137ls -la "$output" "$app/Contents/MacOS/$binary" \
138 "$outputDirectory/teams-macos.zip"