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
3 changes: 2 additions & 1 deletion packaging/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"tauri": "tauri",
"appstore": "bash scripts/build-appstore.sh",
"direct": "bash scripts/build-direct.sh",
"check:config": "node scripts/check-tauri-config.mjs"
"check:config": "node scripts/check-tauri-config.mjs",
"test": "node --test"
},
"dependencies": {
"@tauri-apps/api": "^2.12.5",
Expand Down
7 changes: 6 additions & 1 deletion packaging/app/scripts/build-appstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,20 @@ do_build() {
echo "🏷 bundleVersion → ${BUNDLE_VERSION}"
echo "📜 profile → ${MAS_PROVISIONING_PROFILE_PATH}"

prebuild_mlx
METALLIB="$(mlx_metallib)"
echo "🧩 mlx.metallib → ${METALLIB}"

# --config values merge in order; the file is never modified.
(cd "$APP_DIR" && pnpm tauri build \
--bundles app \
--target universal-apple-darwin \
--config "$CONFIG" \
--config "$(config_json "$BUNDLE_VERSION" "$MAS_PROVISIONING_PROFILE_PATH")")
--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"
require_metallib "$APP_PATH"
require_entitlements "$APP_PATH" \
com.apple.security.app-sandbox \
com.apple.security.network.client \
Expand Down
7 changes: 6 additions & 1 deletion packaging/app/scripts/build-direct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ do_build() {
echo "🏷 bundleVersion → ${BUNDLE_VERSION}"
echo "📜 profile → ${DEVID_PROVISIONING_PROFILE_PATH}"

prebuild_mlx
METALLIB="$(mlx_metallib)"
echo "🧩 mlx.metallib → ${METALLIB}"

(cd "$APP_DIR" && pnpm tauri build \
--bundles app,dmg \
--target universal-apple-darwin \
--config "$CONFIG" \
--config "$(config_json "$BUNDLE_VERSION" "$DEVID_PROVISIONING_PROFILE_PATH")")
--config "$(config_json "$BUNDLE_VERSION" "$DEVID_PROVISIONING_PROFILE_PATH" "$METALLIB")")

[[ -d "$APP_PATH" ]] || fail "Build succeeded but the .app is not at: ${APP_PATH}"
[[ -n "$(find_dmg)" ]] || fail "Build succeeded but there is no .dmg in ${BUNDLE_DIR}/dmg"
require_metallib "$APP_PATH"
notarize_dmg "$(find_dmg)"
ok "Build complete → $(find_dmg)"
}
Expand Down
27 changes: 24 additions & 3 deletions packaging/app/scripts/release-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,33 @@ 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"; }

# 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
# Silicon first and hand the file's path to the bundle.
prebuild_mlx() {
step "MLX kernels"
(cd "$TAURI_DIR" && cargo build --release --target aarch64-apple-darwin --features tauri/custom-protocol)
}

# Absolute path of the mlx.metallib that prebuild_mlx left behind.
mlx_metallib() {
(cd "$TAURI_DIR" && "${CLI_ROOT}/packaging/macos/find-mlx-metallib.sh" aarch64-apple-darwin "${1:-release}")
}

# Fail unless the built .app carries the kernels next to its binary.
require_metallib() {
[[ -f "$1/Contents/MacOS/mlx.metallib" ]] \
|| fail "mlx.metallib is not in $1/Contents/MacOS. Training would fall back to the CPU."
}

# JSON for one extra --config. node is already needed for the frontend, and it
# quotes paths correctly.
# quotes paths correctly. The third argument is the mlx.metallib to bundle.
config_json() {
BUNDLE_VERSION="$1" PROFILE="$2" node -e '
BUNDLE_VERSION="$1" PROFILE="$2" METALLIB="$3" node -e '
const m = { bundleVersion: process.env.BUNDLE_VERSION,
files: { "embedded.provisionprofile": process.env.PROFILE } };
files: { "embedded.provisionprofile": process.env.PROFILE,
"MacOS/mlx.metallib": process.env.METALLIB } };
process.stdout.write(JSON.stringify({ bundle: { macOS: m } }));'
}

Expand Down
10 changes: 9 additions & 1 deletion packaging/app/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ base64 = "0.22"
# calls with no Tauri API, so they are used directly and only on macOS.
[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.6"
objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSArray", "NSData", "NSError", "NSString", "NSURL"] }
objc2-foundation = { version = "0.3", default-features = false, features = ["std", "NSArray", "NSData", "NSError", "NSObject", "NSProcessInfo", "NSString", "NSURL"] }
objc2-app-kit = { version = "0.3", default-features = false, features = ["std", "NSOpenPanel", "NSSavePanel", "NSPanel", "NSWindow", "NSResponder", "NSApplication"] }

[dev-dependencies]
tempfile = "3"

# `tauri dev` is a debug build, and an unoptimized trainer and GGUF quantizer are
# unusably slow: exporting a 1.7B model took over five minutes where an optimized
# build takes under one. Dependencies, which include the onde-cli pipeline and
# candle, build with optimizations; the app's own code stays unoptimized so
# edits still rebuild quickly.
[profile.dev.package."*"]
opt-level = 3
43 changes: 43 additions & 0 deletions packaging/app/src-tauri/src/commands/jobs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use onde_cli::pipeline::RunProgress;
use tauri::{State, ipc::Channel};

use crate::{
desktop::jobs::{JobInfo, JobRequest, Jobs},
error::CommandError,
};

/// A sink that forwards each event to the webview. A webview that has gone away
/// makes `send` fail, and the job carries on without it.
fn sink(channel: Channel<RunProgress>) -> crate::desktop::jobs::Sink {
Box::new(move |event| {
let _ = channel.send(event);
})
}

/// Start a census or a training run. Events arrive on `on_event` until the run
/// ends with `done`, `failed` or `cancelled`.
///
/// `async` runs it off the main thread. Checking the project reads and parses
/// the whole dataset, which must not freeze the window.
#[tauri::command(async)]
pub fn start_job(
request: JobRequest,
on_event: Channel<RunProgress>,
jobs: State<'_, Jobs>,
) -> Result<JobInfo, CommandError> {
jobs.start(&request, sink(on_event))
.map_err(CommandError::InvalidChoice)
}

/// The job in progress, if any, and from now on its events go to `on_event`.
/// A webview that reloaded mid-run calls this to pick the run back up.
#[tauri::command]
pub fn attach_job(on_event: Channel<RunProgress>, jobs: State<'_, Jobs>) -> Option<JobInfo> {
jobs.attach(sink(on_event))
}

/// Ask the running job to stop. Training stops after the current step.
#[tauri::command]
pub fn cancel_job(jobs: State<'_, Jobs>) -> bool {
jobs.cancel()
}
1 change: 1 addition & 0 deletions packaging/app/src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod app;
pub mod auth;
pub mod base_models;
pub mod jobs;
pub mod links;
pub mod oauth;
pub mod projects;
Loading
Loading