BlueGit

ict rusty-teams

Files

rusty-teams / scripts / build-macos.sh

build-macos.sh

build-macos.sh 4.1 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# Usage: scripts/build-macos.sh [crate-dir, default crates/app] [binary-or-example-name, default: the crate's only binary]
5set -euo pipefail
6repoRoot="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
7crateDir="$(realpath "${1:-$repoRoot/crates/app}")"
8binaryName="${2:-}"
9export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$repoRoot/target}"
10export PATH="$HOME/.cargo/bin:$PATH"
11targets=(aarch64-apple-darwin x86_64-apple-darwin)
12
13rustup target add "${targets[@]}" >/dev/null
14
15buildArguments=(build --release)
16slicePathInTarget="release"
17if [ -n "$binaryName" ] && [ -f "$crateDir/examples/$binaryName.rs" ]; then
18 buildArguments+=(--example "$binaryName")
19 slicePathInTarget="release/examples"
20elif [ -n "$binaryName" ]; then
21 buildArguments+=(--bin "$binaryName")
22fi
23
24for target in "${targets[@]}"; do
25 (cd "$crateDir" && cargo "${buildArguments[@]}" --target "$target")
26done
27
28slices=()
29for target in "${targets[@]}"; do
30 sliceDirectory="$CARGO_TARGET_DIR/$target/$slicePathInTarget"
31 if [ -n "$binaryName" ]; then
32 slices+=("$sliceDirectory/$binaryName")
33 else
34 candidates=("$sliceDirectory"/*)
35 [ "${#candidates[@]}" -eq 1 ] && [ -f "${candidates[0]}" ] ||
36 { echo "more than one binary in $sliceDirectory, pass the name" >&2; exit 1; }
37 slices+=("${candidates[0]}")
38 fi
39done
40
41outputDirectory="$CARGO_TARGET_DIR/universal/release"
42mkdir -p "$outputDirectory"
43output="$outputDirectory/$(basename "${slices[0]}")"
44lipo -create -output "$output" "${slices[@]}"
45
46# Wrap the binary in a .app so Finder and the Dock treat it as an application:
47# double-clickable, with the icon, and with the camera / microphone / screen
48# permission prompts (macOS keys those off the bundle, not a bare binary).
49app="$outputDirectory/Rusty Teams.app"
50binary="$(basename "$output")"
51version="$(sed -n 's/^version = "\(.*\)"/\1/p' "$repoRoot/Cargo.toml" | head -1)"
52rm -rf "$app"
53mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
54cp "$output" "$app/Contents/MacOS/$binary"
55cat > "$app/Contents/Info.plist" <<PLIST
56<?xml version="1.0" encoding="UTF-8"?>
57<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
58<plist version="1.0">
59<dict>
60 <key>CFBundleName</key>
61 <string>Rusty Teams</string>
62 <key>CFBundleDisplayName</key>
63 <string>Rusty Teams</string>
64 <key>CFBundleIdentifier</key>
65 <string>org.rusty-teams.teams</string>
66 <key>CFBundleExecutable</key>
67 <string>$binary</string>
68 <key>CFBundleIconFile</key>
69 <string>icon</string>
70 <key>CFBundlePackageType</key>
71 <string>APPL</string>
72 <key>CFBundleShortVersionString</key>
73 <string>$version</string>
74 <key>CFBundleVersion</key>
75 <string>$version</string>
76 <key>NSHighResolutionCapable</key>
77 <true/>
78 <key>NSMicrophoneUsageDescription</key>
79 <string>Rusty Teams uses your microphone for calls.</string>
80 <key>NSCameraUsageDescription</key>
81 <string>Rusty Teams uses your camera for video calls.</string>
82 <key>NSScreenCaptureUsageDescription</key>
83 <string>Rusty Teams shares your screen in meetings.</string>
84</dict>
85</plist>
86PLIST
87
88# The same icon the Windows exe embeds (assets/icon/app.rc); iconutil compiles
89# whatever sizes the set has, all downscaled from the 256px original.
90iconset="$(mktemp -d)/teams.iconset"
91mkdir -p "$iconset"
92png="$repoRoot/crates/app/assets/icon/teams-fast-256.png"
93for size in 16 32 64 128 256; do
94 sips -z "$size" "$size" "$png" --out "$iconset/icon_${size}x${size}.png" >/dev/null
95done
96cp "$iconset/icon_32x32.png" "$iconset/icon_16x16@2x.png"
97cp "$iconset/icon_64x64.png" "$iconset/icon_32x32@2x.png"
98cp "$iconset/icon_256x256.png" "$iconset/icon_128x128@2x.png"
99iconutil -c icns "$iconset" -o "$app/Contents/Resources/icon.icns"
100
101# ditto keeps the bundle intact (plain zip would not); the result is the release asset.
102ditto -c -k --keepParent "$app" "$outputDirectory/teams-macos.zip"
103
104file "$output"
105ls -la "$output" "$app/Contents/MacOS/$binary" "$outputDirectory/teams-macos.zip"