Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(ci): unbreak desktop bundling by extracting the jan CLI to its own crate

Akarshan Biswas8cc49f34af89
diff --git a/.github/workflows/jan-tauri-build-agent-nightly.yaml b/.github/workflows/jan-tauri-build-agent-nightly.yaml
index cfd96ea2b..b0e729fb1 100644
--- a/.github/workflows/jan-tauri-build-agent-nightly.yaml
+++ b/.github/workflows/jan-tauri-build-agent-nightly.yaml
@@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: true
env:
- AGENT_BRANCH: refs/heads/dev
+ AGENT_BRANCH: refs/heads/main
jobs:
resolve-ref:
diff --git a/.github/workflows/template-cli-build-linux-aarch64.yml b/.github/workflows/template-cli-build-linux-aarch64.yml
index 3fdea1f51..aa4402f4a 100644
--- a/.github/workflows/template-cli-build-linux-aarch64.yml
+++ b/.github/workflows/template-cli-build-linux-aarch64.yml
@@ -72,7 +72,7 @@ jobs:
run: |
cd src-tauri
for crate in tauri gtk gdk muda wry webkit2gtk dbus libdbus-sys dbus-secret-service; do
- out=$(cargo tree --no-default-features --features cli -e normal \
+ out=$(cargo tree -p jan-cli --no-default-features --features cli -e normal \
--target aarch64-unknown-linux-gnu -i "$crate" 2>&1) || continue
case "$out" in *"nothing to print"*) continue ;; esac
echo "::error::$crate is back in the jan CLI dependency graph"
@@ -87,7 +87,7 @@ jobs:
JAN_SIGNING_KEY: ${{ secrets.JAN_SIGNING_KEY }}
run: |
cd src-tauri
- cargo build --no-default-features --features cli --bin jan --release
+ cargo build -p jan-cli --no-default-features --features cli --release
# See template-cli-build-linux-x64.yml for why this check exists.
- name: Assert the CLI binary links no unexpected shared libraries
diff --git a/.github/workflows/template-cli-build-linux-x64.yml b/.github/workflows/template-cli-build-linux-x64.yml
index 97dbd9e37..76c3e442e 100644
--- a/.github/workflows/template-cli-build-linux-x64.yml
+++ b/.github/workflows/template-cli-build-linux-x64.yml
@@ -93,7 +93,7 @@ jobs:
run: |
cd src-tauri
for crate in tauri gtk gdk muda wry webkit2gtk dbus libdbus-sys dbus-secret-service onig onig_sys; do
- out=$(cargo tree --no-default-features --features cli -e normal \
+ out=$(cargo tree -p jan-cli --no-default-features --features cli -e normal \
--target x86_64-unknown-linux-gnu -i "$crate" 2>&1) || continue
case "$out" in *"nothing to print"*) continue ;; esac
echo "::error::$crate is back in the jan CLI dependency graph"
@@ -108,7 +108,7 @@ jobs:
JAN_SIGNING_KEY: ${{ secrets.JAN_SIGNING_KEY }}
run: |
cd src-tauri
- cargo build --no-default-features --features cli --bin jan --release
+ cargo build -p jan-cli --no-default-features --features cli --release
# The crate blocklist above only catches names somebody thought to list.
# This catches any new dynamic dependency whatever its source: a NEEDED
diff --git a/.github/workflows/template-cli-build-macos.yml b/.github/workflows/template-cli-build-macos.yml
index 5ad0308a0..d2bc6df07 100644
--- a/.github/workflows/template-cli-build-macos.yml
+++ b/.github/workflows/template-cli-build-macos.yml
@@ -75,7 +75,7 @@ jobs:
JAN_SIGNING_KEY: ${{ secrets.JAN_SIGNING_KEY }}
run: |
cd src-tauri
- cargo build --no-default-features --features cli --bin jan --release --target x86_64-apple-darwin
+ cargo build -p jan-cli --no-default-features --features cli --release --target x86_64-apple-darwin
- name: Build CLI binary (aarch64)
env:
@@ -84,7 +84,7 @@ jobs:
JAN_SIGNING_KEY: ${{ secrets.JAN_SIGNING_KEY }}
run: |
cd src-tauri
- cargo build --no-default-features --features cli --bin jan --release --target aarch64-apple-darwin
+ cargo build -p jan-cli --no-default-features --features cli --release --target aarch64-apple-darwin
- name: Create universal binary
run: |
diff --git a/.github/workflows/template-cli-build-windows-x64.yml b/.github/workflows/template-cli-build-windows-x64.yml
index 101cc1652..04b7677e2 100644
--- a/.github/workflows/template-cli-build-windows-x64.yml
+++ b/.github/workflows/template-cli-build-windows-x64.yml
@@ -63,7 +63,7 @@ jobs:
JAN_SIGNING_KEY: ${{ secrets.JAN_SIGNING_KEY }}
run: |
cd src-tauri
- cargo build --no-default-features --features cli --bin jan --release
+ cargo build -p jan-cli --no-default-features --features cli --release
- name: Package zip
id: package
diff --git a/Makefile b/Makefile
index 7d2eb9d28..55645a98e 100644
--- a/Makefile
+++ b/Makefile
@@ -184,7 +184,7 @@ test-ci: test-prepare
# Cheap compile guard for the CLI feature set. The `jan` CLI is no longer
# bundled with the app; `make test` still builds the real binary via build-cli.
check-cli:
- cd src-tauri && cargo check --locked --no-default-features --features cli --bin jan
+ cd src-tauri && cargo check --locked -p jan-cli --no-default-features --features cli
# Build MLX server (macOS Apple Silicon only) - always builds
build-mlx-server:
@@ -249,8 +249,8 @@ endif
# Build jan CLI (release, platform-aware) → src-tauri/resources/bin/jan[.exe]
build-cli:
ifeq ($(DETECTED_OS),Darwin)
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan --target aarch64-apple-darwin
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan --target x86_64-apple-darwin
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli --target aarch64-apple-darwin
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli --target x86_64-apple-darwin
lipo -create \
src-tauri/target/aarch64-apple-darwin/release/jan \
src-tauri/target/x86_64-apple-darwin/release/jan \
@@ -270,10 +270,10 @@ ifeq ($(DETECTED_OS),Darwin)
cp src-tauri/resources/bin/jan src-tauri/target/universal-apple-darwin/release/jan
else ifeq ($(DETECTED_OS),Windows)
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli
cp src-tauri/target/release/jan.exe src-tauri/resources/bin/jan.exe
else
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli
cp src-tauri/target/release/jan src-tauri/resources/bin/jan
endif
@@ -534,13 +534,13 @@ agent: build-agent
# and then installed to src-tauri/resources/bin/jan[.exe] for bundling.
build-agent:
ifeq ($(DETECTED_OS),Windows)
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli
copy src-tauri\target\release\jan.exe src-tauri\resources\bin\jan.exe
@echo "Jan agent built at:"
@echo " src-tauri/resources/bin/jan.exe"
@echo " src-tauri/target/release/jan.exe"
else
- cd src-tauri && cargo build --release --no-default-features --features cli --bin jan
+ cd src-tauri && cargo build --release -p jan-cli --no-default-features --features cli
install -m755 src-tauri/target/release/jan src-tauri/resources/bin/jan
@echo "Jan agent built at:"
@echo " src-tauri/resources/bin/jan"
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index 988045bd6..808dbe1f6 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -3518,6 +3518,20 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+[[package]]
+name = "jan-cli"
+version = "0.8.4"
+dependencies = [
+ "Jan",
+ "chrono",
+ "clap",
+ "console",
+ "env_logger",
+ "serde_json",
+ "tauri-plugin-agent-tools",
+ "tokio",
+]
+
[[package]]
name = "jan-utils"
version = "0.1.0"
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 9b4e81133..4805fbaf8 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -9,7 +9,6 @@ edition = "2021"
# 1.85 is the floor: `genai` (the OpenAI upstream client) is edition 2024.
# Below that the previous floor was 1.82, for `Option::is_none_or` in agent/loop.rs.
rust-version = "1.85"
-resolver = "2"
default-run = "Jan-Desktop"
[lib]
@@ -21,10 +20,19 @@ name = "Jan-Desktop"
path = "src/main.rs"
required-features = ["desktop"]
-[[bin]]
-name = "jan"
-path = "src/bin/jan.rs"
-required-features = ["cli"]
+# The headless `jan` CLI is a separate workspace member (jan-cli/) rather than a
+# bin target here: tauri-cli bundles every [[bin]] regardless of
+# required-features, so a `jan` target would make the desktop bundler try to
+# copy a binary the desktop build never compiles.
+[workspace]
+members = ["jan-cli"]
+# The engine worker and the other plugins are path dependencies under this
+# directory, so cargo would auto-adopt them as workspace members and force the
+# app's size-tuned [profile.release] (opt-level "z", fat LTO) onto their own
+# standalone builds -- a speed/build-time regression for jan-llama-worker in
+# particular. Exclude them so they keep building as their own roots.
+exclude = ["plugins", "utils"]
+resolver = "2"
[features]
default = [
diff --git a/src-tauri/jan-cli/Cargo.toml b/src-tauri/jan-cli/Cargo.toml
new file mode 100644
index 000000000..229389836
--- /dev/null
+++ b/src-tauri/jan-cli/Cargo.toml
@@ -0,0 +1,30 @@
+[package]
+name = "jan-cli"
+version = "0.8.4"
+description = "Headless CLI for Jan: chat with remote AI models in an interactive agent console."
+authors = ["Jan <[email protected]>"]
+license = "MIT"
+repository = "https://github.com/janhq/jan"
+edition = "2021"
+rust-version = "1.85"
+
+# Split out of the desktop crate so the Tauri bundler never enumerates it as a
+# bin target of the app (tauri-cli ignores required-features and would try to
+# copy a `jan` binary the desktop build never produces). Shares the workspace
+# target dir, so `target/release/jan` is unchanged.
+[[bin]]
+name = "jan"
+path = "src/main.rs"
+
+[features]
+cli = ["app_lib/cli"]
+
+[dependencies]
+app_lib = { path = "..", package = "Jan", default-features = false }
+tauri-plugin-agent-tools = { path = "../plugins/tauri-plugin-agent-tools", default-features = false }
+chrono = { version = "0.4", features = ["serde"] }
+clap = { version = "4", features = ["derive"] }
+console = "0.15"
+env_logger = "0.11"
+serde_json = "1.0"
+tokio = { version = "1", features = ["full"] }
diff --git a/src-tauri/src/bin/jan.rs b/src-tauri/jan-cli/src/main.rs
similarity index 99%
rename from src-tauri/src/bin/jan.rs
rename to src-tauri/jan-cli/src/main.rs
index 5e67b6ebe..b3487895f 100644
--- a/src-tauri/src/bin/jan.rs
+++ b/src-tauri/jan-cli/src/main.rs
@@ -2,7 +2,7 @@
//!
//! Shares the Tauri-free core logic with the Jan desktop app; talks only to
//! remote providers (no local inference, no GUI dependencies).
-//! Build with: cargo build --no-default-features --features cli --bin jan
+//! Build with: cargo build -p jan-cli --no-default-features --features cli
use clap::{Args, CommandFactory, FromArgMatches, Parser, Subcommand};
use console::Style;
diff --git a/src-tauri/tauri.bundle.windows.nsis.template b/src-tauri/tauri.bundle.windows.nsis.template
index bc58aedb1..1d336729d 100644
--- a/src-tauri/tauri.bundle.windows.nsis.template
+++ b/src-tauri/tauri.bundle.windows.nsis.template
@@ -185,7 +185,6 @@ Var LockedFile
; be running and is not ours to kill, so those rely on the rename alone.
!macro FreeBundledFiles
!insertmacro StopBundledProcess "jan-llama-worker.exe"
- !insertmacro UnlockBundledBinary "$INSTDIR\resources\bin\jan.exe"
!insertmacro UnlockBundledBinary "$INSTDIR\resources\bin\jan-llama-worker.exe"
!insertmacro UnlockBundledPattern "$INSTDIR\resources\bin" "ggml*.dll"
!insertmacro UnlockBundledPattern "$INSTDIR\resources\bin" "cudart64_*.dll"
@@ -835,7 +834,6 @@ Section Install
SetOutPath "$INSTDIR\resources\pre-install"
File /nonfatal /a /r "jan_workspace\src-tauri\resources\pre-install\"
SetOutPath "$INSTDIR\resources\bin"
- File /a "/oname=jan.exe" "jan_workspace\src-tauri\resources\bin\jan.exe"
; The engine. This block is a hand-maintained snapshot of
; tauri.windows.conf.json's `bundle.resources`, which the NSIS bundler does
; not read once CI points it at this template, so anything added there has