Skip to content

Split the desktop Tauri crate into an app-lib library and a thin app crate - #3379

Merged
mstomar125 merged 5 commits into
mainfrom
issue-3303-split-desktop-tauri-crate
Sep 30, 2026
Merged

mstomar125 merged 5 commits into
mainfrom
issue-3303-split-desktop-tauri-crate

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3303

Summary

Splits the desktop Tauri crate in two so an app crate outside core can depend on core's desktop library without running core's build script or embedding core's config and frontend (ADR-082 §3.1, proposed).

  • nodespace-app-lib at packages/desktop-app/app-lib: crate nodespace_app_lib, rlib only. Holds every module that was under src-tauri/src/ except main.rs, the tests/it Tauri-seam suite, test-support, and the vendored Pro proto with its compile step.
  • nodespace-app stays at packages/desktop-app/src-tauri (package name, bin name, default-run, hard-coded version, devtools feature unchanged). Holds main.rs, build.rs, build_support.rs, both tauri*.conf.json, capabilities/, icons/, binaries/, resources/, gen/.

The moves are their own commit (git mv, 53 renames, 0 content changes) so history follows the files. The only code change the split forces: run() now takes the tauri::Context<tauri::Wry>, and main.rs expands generate_context!() in the crate that owns tauri.conf.json.

Commits

  1. Move the desktop Tauri library sources into app-lib: pure git mv. The workspace does not build at this commit.
  2. Split the desktop Tauri crate...: manifests, both build.rs, run(context), main.rs, test-support paths, the new test.
  3. Point the test tooling and path comments at app-lib: package.json, scripts, vite config, CLAUDE.md tree, comments.
  4. A one-line clippy fix to the new test.
  5. Review nits: comment attribution in packages/daemon/src/tray.rs, the workspace version comment, and a test-gate.ts comment.

What the split had to preserve

  • desktop / mobile cfg aliases. Only tauri_build defines them, and the library no longer calls it. app-lib/build.rs mirrors tauri-build's cfg_alias exactly (checked against tauri-build 2.6.2 lib.rs). Without it #[cfg(desktop)] (the single-instance guard) compiles out silently. New test desktop_cfg_alias_is_set guards it.
  • Permission files come from the app crate's direct dependencies. tauri-plugin-opener and tauri-plugin-dialog stay direct dependencies of nodespace-app. Verified the risk is real: dropping tauri-plugin-opener from the app crate fails its build with Permission opener:default not found (manifest restored).
  • Windows resource / manifest. tauri_winres links the resource through embed-resource's rustc-link-arg-bins, so it only ever applied to the bin. The library's unit-test binaries never had it, so nothing regresses there.
  • CARGO_MANIFEST_DIR paths in skill_setup.rs, daemon_setup.rs and test-support's workspace_root() still resolve because app-lib sits at the same depth as src-tauri. The two that break (build_support.rs #[path] and the sidecar fallback) are fixed.
  • Lockfile. Cargo.lock gains only the nodespace-app-lib entry and moves dependencies between the two package entries. No external crate version changes; cargo check --locked passes.

Deviations from the issue text

  • build_support.rs module doc and test-support's comment explained the #[path] include as a dependency cycle back onto nodespace-app. That is no longer true (test-support now depends on nodespace-app-lib), so both are reworded to the actual reason: the app crate is binary-only and its build.rs can't take test-support as a build dependency. Comment-only.
  • src-tauri/build.rs: one comment said "See main on set_var", pointing at the proto block that moved out. Reworded in place so it doesn't dangle.
  • clippy::assertions_on_constants fires on assert!(cfg!(desktop)) under -D warnings, and lint suppression is off the table. The test binds cfg!(desktop) to a local first.
  • A few bare packages/desktop-app/src-tauri mentions (packages/cli/src/commands/skill.rs, packages/daemon/src/services/node_service.rs, packages/nodespace-types/src/lib.rs) named the Tauri command layer, so they now say app-lib. Comment-only.
  • scripts/gate-stage.ts, scripts/gate-scope.ts and scripts/test-app-units.ts doc text updated to say nodespace-app-lib.
  • Left alone on purpose: two historical mentions (src-tauri/src/types.rs in nodespace-types' module doc, and a stale src-tauri/src/bin/dev-proxy.rs in browser-sync-service.test.ts), and src-tauri/history.txt, a stray tracked SQL history file that predates this and isn't part of a move.
  • Nothing else in .github/workflows needed changes: the release workflow's paths (src-tauri/binaries, resources/models, the rust-cache workspace entry) all still exist.

Verification

Test counts, before (main at af8ddb61) vs after, compared by test name:

Suite Before After
--lib --bins (app + test-support) 232 233 (232 identical names + tests::cfg_alias_tests::desktop_cfg_alias_is_set)
-p nodespace-app-lib --test it 46 46, identical names (45 pass, 1 #[ignore] that was already ignored)
  • cargo check -p nodespace-app-lib -p nodespace-app and --locked: pass.
  • cargo clippy -p nodespace-app-lib -p nodespace-app -p nodespace-app-test-support --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt clean.
  • Pro-mode NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app: passes. The option_env! reads live in app-lib/src/daemon_setup.rs and are picked up from the same build environment.
  • cargo test --lib --bins -p nodespace-app-lib -p nodespace-app -p nodespace-app-test-support -- --test-threads=2: 233 passed.
  • Tauri-seam suite with NODESPACED_TEST_BIN set to a freshly built nodespaced: 45 passed, 0 failed, 1 ignored.
  • cargo build -p nodespace-app --bin nodespace-app links; cargo metadata shows nodespace-app-lib with only an rlib lib target and nodespace-app with only the bin; the built binary embeds the Tauri context.
  • bun run test:changed (every tier, since package.json and gate files changed): frontend, scripts, skill, browser and rust:test all pass. rust:test runs the 233 app-lib unit tests, so bun run rust:test covers the library.
  • bun run quality:scripts:fix, bun run --cwd packages/desktop-app quality:fix, bun run --cwd packages/skill quality:fix: clean.
  • Acceptance grep git grep -n -e 'src-tauri/src/' -e 'src-tauri/tests' -e 'src-tauri/test-support' returns only the two historical mentions above.

Mutation checks

  • desktop_cfg_alias_is_set: commented out cfg_alias("desktop", !mobile) in app-lib/build.rs -> the test fails with its message (and rustc warns unexpected cfg condition name: desktop); restored -> passes.
  • gate-scope case for packages/desktop-app/app-lib/src/lib.rs: removed "packages/desktop-app/app-lib/" from RUST_DIRS -> that case fails (bun test scripts/gate-scope.test.ts: 24 pass, 1 fail); restored -> 25 pass.

Ratchet (scripts/check-pro-boundary.ts)

The ratchet is not on main yet. I ran the in-flight version from the #3299 worktree against this tree: all 12 counts equal their baselines (delta 0 everywhere; moves keep the counts, and the two Pro-proto comments I moved into app-lib were deleted from src-tauri in the same PR). No BASELINES edit is needed. It should be re-run once it lands.

Not run here, and why

  • bun run dev:tauri smoke test and the "edit an app-lib comment and see it rebuild" check. The app's setup runs kill_stale_daemon_sync() and ensure_daemon_running unconditionally, which writes a launchd plist, bootstraps or boots out the dev-variant job, and restarts the dev daemon. On this shared Mac that would hit whatever dev daemon is running, and HOME isolation doesn't isolate launchd's per-user domain. I didn't want to do that unattended. On the watch question: Tauri CLI's dev watcher watches the app's tauri dir plus the workspace path dependencies of the app crate plus build.additionalWatchFolders (upstream interface/rust.rs), and nodespace-app-lib is a workspace path dependency of nodespace-app, so I expect app-lib edits to rebuild without adding additionalWatchFolders. That is unverified empirically; whoever runs the smoke test should confirm it and add "../app-lib" if not.
  • bun run --cwd packages/desktop-app tauri:build and the bundle contents check. Release profile is lto = true and codegen-units = 1, on a machine that was at load 10+ with other Rust agents. tauri.conf.json, build.rs's sidecar staging, resources/ and externalBin are all unmoved and still owned by the app crate, so bundle contents should be identical, but that hasn't been observed.
  • Pro build pipeline (bunx tauri build --config src-tauri/tauri.pro.conf.json): every path it uses is unchanged; only the Pro-mode compile check above was run.

Downstream

Anything citing packages/desktop-app/src-tauri/src/..., src-tauri/tests/it or the proto step in src-tauri/build.rs now finds it under app-lib/. Library tests run as -p nodespace-app-lib; for the app crate use --bins (cargo test --lib -p nodespace-app now errors with "no library targets"). Git follows the renames, and they are in their own commit, so in-flight branches touching src-tauri/src should rebase cleanly.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review (medium), initial review

Review type: Initial Review. Recommendation: APPROVE.

Code Review Summary

No Critical or Important issues, and no behavior change outside the forced run(context) edit. Build semantics, path resolution, tooling and the version/release path all check out. Two acceptance items could not be exercised in the review environment (see Requirements Check). Cargo was not re-run by the reviewer; bun test scripts/gate-scope.test.ts (25 pass) and cargo metadata --no-deps --offline were.

What was verified against the code:

  • tauri-build 2.6.2 try_build (lib.rs 469-720) versus what the library lost. Only the desktop and mobile aliases matter to the library, and app-lib/build.rs:12-15,38-43 reproduces both check-cfg and cfg lines exactly.
    • dev cfg: no cfg(dev) / cfg!(dev) in app-lib. generate_context! derives dev from cfg!(not(feature = "custom-protocol")) (tauri-macros context.rs:155), a feature unified across the tauri package. The bin's own build script still sets dev.
    • TAURI_ENV_TARGET_TRIPLE is read only by generate_context!, which now expands in the app crate whose build script sets it.
    • ACL build, resource and sidecar copies, TAURI_CONFIG, rpath, MACOSX_DEPLOYMENT_TARGET and the Windows resource step all remain in the app crate. The Windows resource is rustc-link-arg-bins (embed-resource-3.0.9 lib.rs:444), so it was always bin-only.
    • TAURI_ANDROID_PACKAGE_NAME_* was only consumed by mobile_entry_point, which was removed.
  • Capabilities, manifest and features. capabilities/default.json grants only core, opener and dialog; both plugins are direct deps of nodespace-app (src-tauri/Cargo.toml:37-38). tauri stays a direct dep with features = []. devtools = ["tauri/devtools"] still unifies into app-lib's tauri.
  • run() and main.rs. git diff -M of app-lib/src shows only the lib.rs run() lines and the tests.rs addition; everything else is a pure rename. windows_subsystem is still in main.rs. Nothing referenced the old staticlib/cdylib outputs.
  • Path resolution from the new depth is correct: skill_setup.rs:787-790, skill_setup.rs:1349-1352, daemon_setup.rs:2492-2495, test-support workspace_root(), the sidecar fallback, and #[path = "../../../src-tauri/build_support.rs"]. No include_str!/include_bytes! in app-lib reaches a moved sibling.
  • Workspace and lockfile. The Cargo.lock diff is only the new package entry and dependency moves, with no external version drift. version.workspace = true is covered by release.ts (bumps [workspace.package], then cargo check --workspace re-syncs the lock); check-version-sync.ts still reads src-tauri/Cargo.toml. -p nodespace-app -p nodespace-app-lib --lib --bins is valid because cargo's "no library targets" error fires only when no selected package has a lib.
  • Tooling. gate-scope.ts:44 puts app-lib in RUST_DIRS, evaluated before the frontend packages/desktop-app/ prefix rule. test-changed.ts, merge-pr.ts, .husky/pre-push and the workflows have no other special-casing. rust:lint / rust:format run at workspace root. No ignore list needs an entry (app-lib has no JS/TS/CSS). No added #NNNN, allow( or lint-suppression lines.
  • New test desktop_cfg_alias_is_set. Build-script rustc-cfg applies to every target of the package, so cfg!(desktop) in the lib's test target reflects the same cfg as the non-test build. Binding it to a local does not weaken it. Declaring mobile with no user is a harmless check-cfg line.
  • Seam-suite flow. -p nodespace-app-lib --test it no longer triggers the app crate's build script (stale-sidecar sync, tauri-build copy). The gate builds nodespaced first and passes NODESPACED_TEST_BIN, so nothing relies on that side effect; it removes the historical clobber hazard.

Findings

Critical Issues

None.

Suggested Improvements

  • Suggestion (process): the dev:tauri smoke (including "edit an app-lib comment and see it rebuild") and the tauri:build bundle check were not run (disclosed in the PR). Static analysis says the bundle inputs are untouched, and the dev-watch expectation is plausible because app-lib is both a workspace member and a path dependency, but it is unverified. Run both on a quiet machine before or right after merge, and add "../app-lib" to build.additionalWatchFolders only if the rebuild check fails. Re-run scripts/check-pro-boundary.ts once it lands.

Nitpicks

  • Nit: packages/daemon/src/tray.rs (lines 8-9, 46-47, 63-64, 97-98, 127-128, 1162) attributes daemon_setup::... and quit_wiring_tests to nodespace-app; they now live in nodespace-app-lib. Comment-only.
  • Nit: Cargo.toml:16-19 lists the version-inheriting member crates and omits nodespace-app-lib.
  • Nit: scripts/test-gate.ts:280-282 says a bare cargo test -p nodespace-app-lib would re-run "the lib/bin unittest targets"; app-lib has only a lib target now.
  • Nit: src-tauri/history.txt is a tracked stray file, so the "src-tauri holds only ..." acceptance line is literally not met. Pre-existing and disclosed in the PR; a follow-up deletion would make it true.

Requirements Check (issue acceptance criteria)

  • app-lib is rlib only, no tauri.conf.json, no generate_context!, no tauri_build call: met.
  • src-tauri holds only the listed items: met except the pre-existing tracked history.txt.
  • Entry point run(context), main.rs expands generate_context!(): met (lib.rs:313, main.rs:29).
  • desktop_cfg_alias_is_set exists and fails without the alias: met per the author's mutation check (logic and alias confirmed by reading).
  • Existing unit and seam tests pass from new locations, counts match: not re-run by the reviewer; consistent with the diff (pure renames plus one new test module).
  • gate-scope classifies app-lib/... as Rust with a test: met (25 pass).
  • bun run rust:test runs the library's unit tests: met (test-app-units.ts:194-199).
  • Merge gate seam stage runs -p nodespace-app-lib --test it: met (test-gate.ts:254,304).
  • Pro-mode cargo check -p nodespace-app: author-run, not re-run.
  • Free-app smoke test: not verified (not run, disclosed).
  • tauri:build bundle contents unchanged: not verified; static analysis says unchanged.
  • git grep acceptance: met (two historical mentions only).
  • check-pro-boundary.ts: not verifiable in-tree (not on main); the author's preview showed zero delta.
  • No issue numbers in code comments: met.

Recommendation: APPROVE.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (medium): APPROVE (posted as a comment, GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3303-split-desktop-tauri-crate branch from b930962 to 9c22d66 Compare September 30, 2026 10:21
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary

Pushed 9c22d660 (branch also rebased onto current origin/main, no conflicts; the three commits that landed in between don't touch the split. After the rebase: clippy -D warnings -D clippy::unused-async on the three crates, 233 unit tests, Pro-mode cargo check, and the gate-scope test all pass, and the acceptance grep still returns only the two historical mentions.)

Addressed (3 of 5 items, all comment-only):

  • packages/daemon/src/tray.rs: the six comments that attributed daemon_setup::... and quit_wiring_tests to nodespace-app now say nodespace-app-lib. I grepped the rest of the repo for the same attribution; what remains says "nodespace-app's build script", which is correct because the app crate still owns build.rs.
  • Cargo.toml: the [workspace.package] comment listing version-inheriting members now includes nodespace-app-lib.
  • scripts/test-gate.ts: "lib/bin unittest targets" is now "lib unittest target".

Skipped (2):

  • src-tauri/history.txt (stray tracked file, so the "src-tauri holds only ..." criterion is not literally true): skipped as scope creep. It predates this change and this PR is a move plus wiring only. A one-line follow-up deletion would make the criterion literally true.
  • The dev:tauri smoke, the "edit an app-lib comment and see it rebuild" check and the tauri:build bundle check: cannot be done here. The app's setup runs kill_stale_daemon_sync() and ensure_daemon_running unconditionally (launchd plist plus bootstrap/bootout, restarting the dev daemon), which on the shared Mac would hit whatever dev daemon is running, and tauri:build is a LTO release build. Revisit: run both on a quiet machine before or right after merge, and add "../app-lib" to build.additionalWatchFolders in tauri.conf.json only if the rebuild check fails. Also re-run scripts/check-pro-boundary.ts once Add the Pro-boundary ratchet check and the CLAUDE.md Pro/sync placement rule #3299 lands (previewed at zero delta).

Checks run on the change: bun run quality:scripts:fix clean; bun run test:changed (every tier) passed before the rebase, including rust:test with the 233 app-lib unit tests.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the three fixes are comment and comment-adjacent text only, with no logic, manifest or build-script change. The review found no Critical or Important issues and recommended APPROVE.

mstomar125 and others added 5 commits September 30, 2026 12:26
Pure git mv, no content change: src-tauri/src (except main.rs), tests,
test-support and proto now live under packages/desktop-app/app-lib. The
workspace does not build at this commit; the next commit adds the manifests
and wiring.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…rate

nodespace-app-lib (packages/desktop-app/app-lib) is an rlib holding every
module the app ran, the Tauri-seam tests and test-support. run() now takes
the tauri::Context, so generate_context!() expands in main.rs of the
nodespace-app crate that owns tauri.conf.json. The library's build.rs takes
over the Pro proto step and defines the desktop/mobile cfg aliases that only
tauri_build used to provide; desktop_cfg_alias_is_set guards the single-
instance plugin against losing them silently.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
rust:test:* and test-app-units.ts build and run nodespace-app-lib's unit
tests, the merge gate's Tauri-seam stage runs -p nodespace-app-lib --test it,
gate-scope classifies packages/desktop-app/app-lib/ as Rust so test:changed
does not skip Rust for it, and refresh-pro-proto writes the vendored proto
into app-lib/proto. Comments that named src-tauri/src or src-tauri/tests now
name app-lib.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… items

tray.rs pointed at nodespace-app for daemon_setup and quit_wiring_tests, which
now live in nodespace-app-lib; the workspace version comment lists the new
member; test-gate.ts no longer calls app-lib's unit target a lib/bin pair.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3303-split-desktop-tauri-crate branch from 9c22d66 to 3c981e2 Compare September 30, 2026 10:26
@mstomar125
mstomar125 merged commit ca6a50e into main Sep 30, 2026
@mstomar125
mstomar125 deleted the issue-3303-split-desktop-tauri-crate branch September 30, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split the desktop Tauri crate into an app-lib library and a thin app crate

1 participant