Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packaging/app/scripts/build-appstore.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
# Mac App Store pipeline for Onde Desktop.
# build tauri build (universal, App Store config, YYYYMMDD.HHMM build number)
# build frontend, then each architecture with tauri build --no-bundle, lipo,
# tauri bundle --no-sign, and codesign (universal, App Store config,
# YYYYMMDD.HHMM build number). The script runs lipo and codesign itself
# because tauri-cli cannot do either for this app from a non-tty shell.
# sign productbuild, signed with the 3rd Party Mac Developer Installer cert
# upload altool upload to App Store Connect
#
Expand All @@ -11,6 +14,7 @@
# API_PRIVATE_KEYS_DIR or ~/.appstoreconnect/private_keys
# MAS_PROVISIONING_PROFILE_PATH default: the private apple-certificates checkout
# SIGNING_IDENTITY installer identity; default: looked up in the keychain
# MAS_SIGNING_IDENTITY app identity; default: signingIdentity in the App Store config
# DEVELOPER_DIR a release Xcode; default: picked automatically
# BUNDLE_VERSION default: now, UTC
set -euo pipefail
Expand All @@ -35,20 +39,30 @@ do_build() {
echo "🏷 bundleVersion → ${BUNDLE_VERSION}"
echo "📜 profile → ${MAS_PROVISIONING_PROFILE_PATH}"

prebuild_mlx
build_frontend
build_arch_binary aarch64-apple-darwin --config "$CONFIG"
build_arch_binary x86_64-apple-darwin --config "$CONFIG"
METALLIB="$(mlx_metallib)"
echo "🧩 mlx.metallib → ${METALLIB}"
lipo_universal "$TARGET_DIR"

# --config values merge in order; the file is never modified.
(cd "$APP_DIR" && pnpm tauri build \
# --config values merge in order; the file is never modified. --no-sign
# because codesign_app signs the bundle below.
step "Bundle"
rm -rf "$APP_PATH"
(cd "$APP_DIR" && pnpm tauri bundle \
--bundles app \
--target universal-apple-darwin \
--no-sign \
--config "$CONFIG" \
--config "$(config_json "$BUNDLE_VERSION" "$MAS_PROVISIONING_PROFILE_PATH" "$METALLIB")")

[[ -d "$APP_PATH" ]] || fail "Build succeeded but the .app is not at: ${APP_PATH}"
verify_codesign_matches_profile "$APP_PATH"
[[ -d "$APP_PATH" ]] || fail "Bundling succeeded but the .app is not at: ${APP_PATH}"
require_metallib "$APP_PATH"
codesign_app "$APP_PATH" \
"${MAS_SIGNING_IDENTITY:-$(config_signing_identity "$CONFIG")}" \
"${TAURI_DIR}/Entitlements-appstore.plist"
verify_codesign_matches_profile "$APP_PATH"
require_entitlements "$APP_PATH" \
com.apple.security.app-sandbox \
com.apple.security.network.client \
Expand Down
1 change: 1 addition & 0 deletions packaging/app/scripts/build-direct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ do_build() {
echo "🏷 bundleVersion → ${BUNDLE_VERSION}"
echo "📜 profile → ${DEVID_PROVISIONING_PROFILE_PATH}"

build_frontend
prebuild_mlx
Comment thread
setoelkahfi marked this conversation as resolved.
Resolved
METALLIB="$(mlx_metallib)"
echo "🧩 mlx.metallib → ${METALLIB}"
Expand Down
75 changes: 75 additions & 0 deletions packaging/app/scripts/release-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,81 @@ bundle_version() { date -u +"%Y%m%d.%H%M"; }
# the binary (build.rs reads ONDE_DESKTOP_BUILD), so the sidebar can show it.
export_build_number() { export ONDE_DESKTOP_BUILD="$1"; }

# tauri::generate_context!() reads frontendDist (../dist) at compile time, so
# any cargo build of the app fails on a fresh checkout until the frontend has
# been built once. Build it before anything touches Rust.
build_frontend() {
step "Frontend"
(cd "$APP_DIR" && pnpm install --frozen-lockfile && pnpm build)
}

# Main executable name inside Contents/MacOS, which is the cargo package name.
APP_BINARY="${APP_BINARY:-onde-desktop}"

# The frontend is already built; keep tauri build from building it again.
NO_FRONTEND_REBUILD='{"build":{"beforeBuildCommand":""}}'

# Compile the app for one architecture with tauri build, without bundling. Going
# through tauri build (not cargo) matters: it hands the merged --config to the
# compile through TAURI_CONFIG, so the binary embeds the release identifier and
# product name instead of the debug ones in tauri.conf.json. The aarch64 build
# also leaves mlx.metallib under the target directory.
# build_arch_binary <target triple> <tauri --config args...>
build_arch_binary() {
local target="$1"; shift
step "Compile ${target}"
(cd "$APP_DIR" && pnpm tauri build --no-bundle --target "$target" \
"$@" --config "$NO_FRONTEND_REBUILD")
}

# Merge the two architecture builds into the path tauri bundle reads for
# universal-apple-darwin. tauri-cli 2.12.5 spawns lipo itself and, from a shell
# without a terminal, fails with "Failed to launch the new process ... Bad file
# descriptor"; the same command run from bash works, so run it here.
# lipo_universal <target dir>
lipo_universal() {
local target_dir="$1" out
out="${target_dir}/universal-apple-darwin/release/${APP_BINARY}"
step "Universal binary"
mkdir -p "$(dirname "$out")"
lipo -create -output "$out" \
"${target_dir}/aarch64-apple-darwin/release/${APP_BINARY}" \
"${target_dir}/x86_64-apple-darwin/release/${APP_BINARY}"
local archs; archs="$(lipo -archs "$out")"
[[ "$archs" == *arm64* && "$archs" == *x86_64* ]] \
|| fail "lipo produced ${out} with architectures '${archs}', expected arm64 and x86_64."
ok "${out} → ${archs}"
}

# bundle.macOS.signingIdentity from a Tauri config file.
config_signing_identity() {
node -e 'const c = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
process.stdout.write((c.bundle && c.bundle.macOS && c.bundle.macOS.signingIdentity) || "");' "$1"
}

# Sign a bundled .app from the inside out. Tauri cannot do this for us: it signs
# the executable and the bundle, and codesign then refuses the bundle because
# Contents/MacOS/mlx.metallib is "not signed at all". Everything in
# Contents/MacOS counts as code, so the metallib gets its own signature first.
# codesign_app <app> <identity> <entitlements plist>
codesign_app() {
local app="$1" identity="$2" entitlements="$3"
step "Codesign"
[[ -n "$identity" ]] || fail "No signing identity. Set signingIdentity in the Tauri config or export the override."
security find-identity -v -p codesigning 2>/dev/null | grep -q -- "$identity" \
|| fail "Signing identity ${identity} is not in the keychain.\n Import the Apple Distribution certificate, or override the identity."
[[ -f "$entitlements" ]] || fail "Entitlements file not found: ${entitlements}"
echo "🔏 identity → ${identity}"
echo "📄 entitlements → ${entitlements}"

codesign --force --timestamp=none --sign "$identity" "${app}/Contents/MacOS/mlx.metallib"
codesign --force --timestamp=none --sign "$identity" --entitlements "$entitlements" \
"${app}/Contents/MacOS/${APP_BINARY}"
codesign --force --timestamp=none --sign "$identity" --entitlements "$entitlements" "$app"
codesign --verify --deep --strict --verbose=2 "$app"
ok "Signed ${app}"
}

# MLX loads its Metal kernels from mlx.metallib next to the app binary. Without
# the file, training quietly falls back to the CPU, which is many times slower.
# mlx-sys builds it under the cargo target directory, so compile for Apple
Expand Down