hex/scripts/build-app.sh
Kit Langton fb617e5082 Import scrawl-capture into crates/capture
Copy Scrawl's `crates/capture` from kitlangton/scrawl, branch
`engine/split`, commit e351ddb28be47c77481cb6821cc72d7f8fe7c769 (e351ddb),
without history, keeping the package name `scrawl-capture`, and its
`docs/app-handover-spec.md` as `docs/plans/capture-handover-spec.md`. Hex
depends on it by path instead of the Git pin at 86d7d6c; the Nix
`outputHashes."scrawl-capture-0.3.13"` entry goes.

Workspace: `crates/capture` is in `[workspace] exclude`, so `cargo build`,
`cargo test`, and `--workspace` never build it (Linux, Windows, and Nix
included). It compiles only as the `capture` feature's macOS dependency,
sharing the root Cargo.lock and target/. The root package stays a member
without being listed, since listing "." defeats `exclude`. On macOS
`scripts/check` and the macOS workflow name it (`-p voice-control
-p scrawl-capture --features capture`) to lint and test its 257 tests.

API adaptations in capture_host:
- `Finished` gains `gaps` and `missing_transcript`; the host records them
  and `hex capture status` (human and JSON `last`) shows them.
- `Engine::new` bridges the crate's log to `Host::log` when no sink is
  set, so Hex's own `TracingLog` sink goes and each line is logged once.
- Scrawl now writes its bundle files 0600; Hex still tightens
  recording.mp4, the window log, and folders.
- Nothing on Hex's path reads ~/.config/scrawl or writes under
  Application Support/scrawl: the crate does that only after
  `enable_scrawl_host_defaults`/`enable_file_log`, which Hex never calls.

Scrubbed (synthetic values): a file:///Users/<name> path in ax.rs, the
com.kitlangton.UpDown / dev.kitlangton.UpDown test bundle IDs in
handoff.rs and phone.rs (now com.example.UpDown), and a personal device
name in a phone.rs test. Kept: Scrawl's own product IDs
(dev.kitlangton.scrawl, .helper) and its public GitHub releases URL.

fmt and clippy -D warnings, no behaviour change: `cargo fmt` on five
files; `chunks_exact(N)` to `as_chunks::<N>()` (19 sites); collapsed
`if let` chains in capture/macos.rs and pipeline.rs and a `match` in
page.rs; `type` aliases for a drag start and two ingest hooks; explicit
lower bounds on two test `match` range arms in keyframes.rs;
`slice::from_ref` for two one-element slices; `and_then` for
`map().flatten()`; a dropped `to_owned`; `#[allow]` for one
`too_many_arguments` and one `single_range_in_vec_init`.
2026-10-25 19:14:23 -07:00

115 lines
4.7 KiB
Shell
Executable file

#!/bin/sh
set -eu
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
. "$root/scripts/macos-signing.sh"
# HEX_TEST_BUILD=1 builds the CI test app: ad-hoc signed, under its own
# name and bundle ID so it installs beside the released Hex and never
# touches its permissions; it never checks for updates.
if [ "${HEX_TEST_BUILD:-}" = 1 ]; then
team_id=
identity=-
app_name="Hex Test"
bundle_id=anomaly.hex.test
else
team_id=${VOICE_CONTROL_TEAM_ID:?Set VOICE_CONTROL_TEAM_ID to the Apple Developer signing team}
identity=$(hex_codesign_identity "$team_id")
app_name=Hex
bundle_id=anomaly.hex
fi
# HEX_CAPTURE=1 builds the `capture` experiment in (`--features capture`)
# with Scrawl's `scrawl-helper` beside `hex`, where the engine looks for
# it. crates/capture/build.rs compiles the helper from crates/capture/helper
# into target/release. Never for a public build: release-app.sh and
# validate-app.sh refuse it.
capture=${HEX_CAPTURE:-}
case "$capture" in
'' | 0) capture= ;;
1) ;;
*)
echo "HEX_CAPTURE must be 1 or unset" >&2
exit 1
;;
esac
icon_output="$root/target/AppIcon.assets"
icon_info="$root/target/AppIcon-info.plist"
version=$(hex_version "$root")
build_number=$(hex_build_number "$version")
bundle_name="$app_name.app"
executable_name=hex
bundle="$root/target/app/$bundle_name"
executable="$bundle/Contents/MacOS/$executable_name"
frameworks="$bundle/Contents/Frameworks"
sign() {
if [ "$identity" = - ]; then
codesign --force --sign - "$@"
else
codesign --force --timestamp --options runtime --sign "$identity" "$@"
fi
}
export MACOSX_DEPLOYMENT_TARGET=15.0
if [ -n "$capture" ]; then
# The helper's embedded Info.plist names Hex, not Scrawl.
SCRAWL_HELPER_PLIST="$root/packaging/macos/scrawl-helper-Info.plist" \
cargo build --locked --release --features capture --manifest-path "$root/Cargo.toml"
else
cargo build --locked --release --manifest-path "$root/Cargo.toml"
fi
rm -rf "$bundle"
mkdir -p "$bundle/Contents/MacOS" "$bundle/Contents/Resources" "$bundle/Contents/Library" "$frameworks"
cp "$root/target/release/voice-control" "$executable"
if [ -n "$capture" ]; then
cp "$root/target/release/scrawl-helper" "$bundle/Contents/MacOS/scrawl-helper"
fi
cp "$root/app/Info.plist" "$bundle/Contents/Info.plist"
cp "$root/LICENSE" "$root/THIRD_PARTY_NOTICES.md" "$bundle/Contents/Resources/"
HEX_VERSION="$version" HEX_BUILD_NUMBER="$build_number" VOICE_CONTROL_TEAM_ID="$team_id" VOICE_CONTROL_CODESIGN_IDENTITY="${identity#-}" HEX_SKIP_INSTALL_SCRIPT=1 \
"$root/scripts/build-hex-microphone-driver.sh" "$bundle/Contents/Library" >&2
(cd "$root/sdk/commands" && bun run build)
mkdir -p "$bundle/Contents/Resources/commands-sdk"
cp "$root/sdk/commands/package.json" "$bundle/Contents/Resources/commands-sdk/"
/usr/bin/ditto "$root/sdk/commands/dist" "$bundle/Contents/Resources/commands-sdk/dist"
/usr/bin/ditto "$root/sdk/commands/workspace-template" "$bundle/Contents/Resources/commands-sdk/workspace-template"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "$bundle/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build_number" "$bundle/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier $bundle_id" "$bundle/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $executable_name" "$bundle/Contents/Info.plist"
plutil -replace CFBundleName -string "$app_name" "$bundle/Contents/Info.plist"
plutil -replace CFBundleDisplayName -string "$app_name" "$bundle/Contents/Info.plist"
rm -rf "$icon_output"
mkdir -p "$icon_output"
xcrun actool "$root/app/AppIcon.icon" \
--compile "$icon_output" \
--platform macosx \
--minimum-deployment-target 15.0 \
--app-icon AppIcon \
--standalone-icon-behavior all \
--output-partial-info-plist "$icon_info" \
--output-format human-readable-text \
--warnings \
--notices >&2
cp "$icon_output/AppIcon.icns" "$icon_output/Assets.car" "$bundle/Contents/Resources/"
set -- "$root"/.venv/lib/python*/site-packages/moonshine_voice
moonshine_dir=$1
if [ ! -d "$moonshine_dir" ]; then
echo "Moonshine is not installed. Run ./scripts/setup.sh." >&2
exit 1
fi
cp "$moonshine_dir/libmoonshine.dylib" "$frameworks/"
cp "$moonshine_dir/libonnxruntime.1.23.2.dylib" "$frameworks/"
sign "$frameworks/libonnxruntime.1.23.2.dylib"
sign "$frameworks/libmoonshine.dylib"
sign "$bundle/Contents/Library/HexMicrophone.driver"
if [ -n "$capture" ]; then
# Hex runs it only to decode the capture's movie, which needs no
# entitlement; anything it touches is attributed to Hex, its responsible
# process.
sign --identifier "$bundle_id.scrawl-helper" "$bundle/Contents/MacOS/scrawl-helper"
fi
sign --entitlements "$root/app/VoiceControl.entitlements" "$bundle"
codesign --verify --deep --strict --verbose=2 "$bundle"
echo "$bundle"