Skip to content

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

Closed

Description

@mstomar125

Part of #3322 (Tauri extension points for the desktop app).

Summary

Split packages/desktop-app/src-tauri into two packages. Today it is one package, nodespace-app, with lib nodespace_app_lib and bin nodespace-app.

This is a move. The only code change is the one the split forces: generate_context!() must expand in the crate that owns tauri.conf.json, so run() now takes the tauri::Context from main.rs. Behaviour does not change.

This is ADR-082 (proposed) §3.1. It lets an app crate outside core depend on core's desktop library without running core's build script or embedding core's config and frontend.

Context (lines at af8ddb6)

src-tauri/Cargo.toml

  • [lib] (9-11) has crate-type = ["staticlib", "cdylib", "rlib"], which comes from Tauri's mobile template. There is no mobile target: gen/ holds only schemas/.
  • [build-dependencies] (13-21): tauri-build, the Pro-proto tonic-build and protoc-bin-vendored, and serde_json.
  • [[bin]] (23-25), [features] devtools (33-34), [dependencies] (36-68), [dev-dependencies] (70-80).

src/lib.rs run() (311-870)

  • #[cfg_attr(mobile, tauri::mobile_entry_point)] (311).
  • #[cfg(desktop)] around the single-instance plugin (344).
  • .build(tauri::generate_context!()) (862).

build.rs main() (172-200)

  • The Pro proto step (173-192), then sync_external_bin_staging(), drop_unstaged_bundle_entries() and tauri_build::build().

Two things tauri_build does that the split has to preserve

  • The desktop/mobile cfg aliases (tauri-build 2.6.2 lib.rs 206-210, 476-477). A library without them compiles #[cfg(desktop)] code out silently, which would drop the single-instance guard.
  • Permission files, from direct dependencies only.
    • capabilities/default.json grants opener:default and dialog:default.
    • So the app crate must keep tauri-plugin-opener and tauri-plugin-dialog as direct dependencies. Otherwise validate_capabilities fails the build.

Paths built from CARGO_MANIFEST_DIR

These keep working, because app-lib is at the same depth as src-tauri:

  • skill_setup.rs: source_checkout_installer_candidate and the compiled-installer test (~1349);
  • daemon_setup.rs: pkg_plist_matches_app_plist_tests (~2492);
  • test-support: workspace_root() (~379).

Two test-support paths break and must be fixed:

  • the sidecar fallback CARGO_MANIFEST_DIR/../binaries (~517-520);
  • #[path = "../../build_support.rs"] (50).

Tooling that names the crate or its paths

  • Root Cargo.toml members (2-12).
  • Root package.json: rust:test:build (71) and rust:test:workspace (72).
  • scripts/test-app-units.ts: the cargo call (187-201).
  • scripts/test-gate.ts: the Tauri-seam compile (254) and run (304) stages.
  • scripts/gate-scope.ts RUST_DIRS (35-44). Without an entry, a change under app-lib/ falls into the packages/desktop-app/ branch and counts as frontend-only, so test:changed would skip Rust.
  • scripts/refresh-pro-proto.ts: its destination path (~30-35).

What must not move

  • sync's Pro build runs bunx tauri build --config src-tauri/tauri.pro.conf.json in packages/desktop-app.
  • It stages files into src-tauri/binaries and src-tauri/resources/models.
  • The bundle executable is nodespace-app.

All of these stay put. option_env!("NODESPACE_PRO_SUPABASE_URL") in daemon_setup.rs is still evaluated from the same build environment.

Scope

1. Moves (git mv, in their own commit)

  • src-tauri/src/* except main.rs → app-lib/src/
  • src-tauri/tests/ → app-lib/tests/
  • src-tauri/test-support/ → app-lib/test-support/
  • src-tauri/proto/ → app-lib/proto/

2. New packages/desktop-app/app-lib/Cargo.toml

  • [package]: name = "nodespace-app-lib", version.workspace = true, edition.workspace = true, publish = false, and a description.
  • [lib]: name = "nodespace_app_lib" and crate-type = ["rlib"], with a one-line comment saying there is no mobile target.
  • [dependencies]: every entry from today's [dependencies], moved verbatim with its comments.
  • [build-dependencies]: tonic-build and protoc-bin-vendored, moved verbatim with their comment.
  • [dev-dependencies]: today's three entries, with nodespace-app-test-support = { path = "test-support" }.

3. New packages/desktop-app/app-lib/build.rs

  • The Pro proto step, moved verbatim from src-tauri/build.rs. Delete the vendored nodespace_pro.proto, its build.rs step and its build-only deps #3335 deletes it.

  • A cfg_alias helper that mirrors tauri-build's:

    • for desktop and mobile, print cargo:rustc-check-cfg=cfg(<alias>);
    • print cargo:rustc-cfg=desktop unless CARGO_CFG_TARGET_OS is ios or android.

    Add a comment explaining that #[cfg(desktop)] guards the single-instance plugin.

  • No tauri_build call. The library has no tauri.conf.json.

4. Library code (the only edits)

  • run():
    • drop the mobile_entry_point attribute;
    • change the signature to pub fn run(context: tauri::Context<tauri::Wry>);
    • replace .build(tauri::generate_context!()) with .build(context);
    • add one doc line saying the app crate supplies the context.
  • test-support/Cargo.toml: nodespace-app-lib = { path = ".." }. The crate name nodespace_app_lib is unchanged, so the use lines stay.
  • test-support/src/lib.rs:
  • Comments that name a moved path: update them.

5. App crate packages/desktop-app/src-tauri

Cargo.toml

  • Keep [package], including its hard-coded version (which scripts/check-version-sync.ts reads) and default-run.
  • Keep [[bin]] and [features] devtools.
  • Remove [lib] and [dev-dependencies].
  • [dependencies]:
    • nodespace-app-lib = { path = "../app-lib" };
    • tauri = { version = "2", features = [] }, which tauri_build's manifest check and generate_context! need;
    • tokio = { workspace = true }, because main.rs builds the runtime;
    • tauri-plugin-opener = "2" and tauri-plugin-dialog = "2", with a comment saying they are here only for their permission files.
  • [build-dependencies]: tauri-build and serde_json.

build.rs: delete the Pro proto block, which moved. The rest is unchanged.

src/main.rs: runtime.block_on(async { nodespace_app_lib::run(tauri::generate_context!()) }). Nothing else changes.

6. Workspace and tooling

  • Root Cargo.toml members: add packages/desktop-app/app-lib and packages/desktop-app/app-lib/test-support, and drop packages/desktop-app/src-tauri/test-support.

  • Root package.json. The library links Tauri, so it follows nodespace-app's platform handling:

    • rust:test:build: add --exclude nodespace-app-lib to the nextest part, and -p nodespace-app-lib to the cargo test --lib --bins part;
    • rust:test:workspace: add --exclude nodespace-app-lib.
  • scripts/test-app-units.ts: add -p nodespace-app-lib and update the doc. Keep the prerequisite check, because the bin still runs tauri_build.

  • scripts/test-gate.ts: change both -p nodespace-app --test it to -p nodespace-app-lib --test it, and update their comment.

  • scripts/gate-scope.ts: add "packages/desktop-app/app-lib/" to RUST_DIRS. In scripts/gate-scope.test.ts, add packages/desktop-app/app-lib/src/lib.rs to the "counts as a Rust input" cases.

  • scripts/refresh-pro-proto.ts: set the destination to app-lib/proto/nodespace_pro.proto.

  • packages/desktop-app/vite.config.js: add "**/app-lib/**" to server.watch.ignored. ESLint and Vitest look only at src/, so they need no change.

  • Comments that point at src-tauri/src/… or src-tauri/tests/…: point them at app-lib/…. They are in:

    • packages/cli/src/lib.rs;
    • packages/daemon/tests/it/grpc_round_trip.rs;
    • packages/nodespace-types/src/schema.rs;
    • packages/desktop-app/src/lib/services/backend-adapter.ts;
    • src/tests/e2e/adapter-contract.e2e.ts;
    • src/tests/services/dev-proxy-*.test.ts;
    • packages/dev-tools/src/*;
    • packages/skill/src/install.ts and packages/skill/README.md;
    • scripts/build-skill.ts and scripts/publish-skill-repo.ts.

    Leave historical mentions alone, such as nodespace-types' "previously lived in src-tauri/src/types.rs".

  • CLAUDE.md repo tree (~356): add app-lib/ (the Tauri app library: commands, services, entry point), and describe src-tauri/ as the app crate (main.rs, build.rs, config, icons, sidecars).

  • scripts/check-pro-boundary.ts (Add the Pro-boundary ratchet check and the CLAUDE.md Pro/sync placement rule #3299): if it names a moved path in an exclusion list, update it.

Out of scope

Steps

  1. Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is issue-<N>-split-desktop-tauri-crate.
  2. Record the test counts before the split:
    • cargo test --lib --bins -p nodespace-app -p nodespace-app-test-support -- --list | grep -c ': test';
    • the same count for --test it.
  3. Commit the git mv moves on their own.
  4. Commit the manifests, both build.rs files, run(context), main.rs and the test-support paths.
  5. Commit the tooling and comment updates.
  6. Build, lint and test with the commands below. The test counts must match step 1.
  7. Run the Pro-mode compile check.
  8. Smoke-test:
    • Run bun run dev:tauri against the dev daemon and socket. While it runs, edit a comment in an app-lib file and confirm the app rebuilds. If it doesn't, add "../app-lib" to build.additionalWatchFolders in tauri.conf.json.
    • When the shared machine is quiet, run bun run --cwd packages/desktop-app tauri:build. Check that the bundle contains nodespaced, nodespace, nodespace-skill-installer and the skill resources, and that it launches.
  9. Run bun run scripts/check-pro-boundary.ts and bun run quality:fix, then bun run test:changed. Gate files changed, so every tier runs: start it when the machine is free.

Acceptance criteria

  • app-lib builds nodespace_app_lib as rlib only. It has no tauri.conf.json, no generate_context! and no tauri_build call.
  • src-tauri holds only src/main.rs, build.rs, build_support.rs (until Move the bundle-staging build helpers into a nodespace-app-build crate #3305), the configs, capabilities/, icons/, binaries/, resources/, gen/ and .gitignore.
  • The entry point is run(context), and main.rs expands generate_context!().
  • The new test desktop_cfg_alias_is_set (asserting cfg!(desktop)) passes. Removing the alias from app-lib/build.rs makes it fail.
  • Every existing unit test and Tauri-seam test passes from its new location, and the counts match step 1.
  • gate-scope classifies packages/desktop-app/app-lib/… as Rust, and a test covers that.
  • bun run rust:test runs the library's unit tests.
  • The merge gate's Tauri-seam stage runs -p nodespace-app-lib --test it.
  • The Pro-mode cargo check -p nodespace-app passes.
  • The free-app smoke test passes.
  • The tauri:build bundle contents are unchanged.
  • git grep -n -e 'src-tauri/src/' -e 'src-tauri/tests' -e 'src-tauri/test-support' returns only references to src-tauri/src/main.rs and historical mentions.
  • bun run scripts/check-pro-boundary.ts passes. BASELINES are unchanged (moves keep the counts), or lowered to the exact new counts wherever this PR removes markers, and no count rises.
  • No GitHub issue numbers in code comments.

Tests and verification

  • New test: desktop_cfg_alias_is_set, in app-lib/src/tests.rs.
  • New case: the app-lib case in gate-scope.test.ts.
  • Existing suites all run from their new locations.

Mutation-check each new test: break the code path it covers, confirm the test fails, then restore.

cargo check -p nodespace-app-lib -p nodespace-app
cargo test --lib --bins -p nodespace-app-lib -p nodespace-app -p nodespace-app-test-support -- --test-threads=2
cargo build --bin nodespaced && NODESPACED_TEST_BIN="$PWD/target/debug/nodespaced" cargo test -p nodespace-app-lib --test it -- --test-threads=1
cargo clippy -p nodespace-app-lib -p nodespace-app -p nodespace-app-test-support --all-targets -- -D warnings -D clippy::unused-async
NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app
bun test scripts/gate-scope.test.ts
bun run scripts/check-pro-boundary.ts
bun run test:changed

Note: cargo test --lib -p nodespace-app on its own now errors with "no library targets". Use --bins for the app crate.

Dependencies

Downstream

#3318, #3319 to #3335, #3346 to #3355, #3360 and #3363 cite packages/desktop-app/src-tauri/src/…, src-tauri/tests/it or src-tauri/build.rs (the proto step). After this PR:

  • library code is under app-lib/src/;
  • the seam tests are under app-lib/tests/it;
  • the Pro proto step is in app-lib/build.rs;
  • the library's tests run as -p nodespace-app-lib.

Find code by symbol.

Risks and rollback

  • Rebase churn for in-flight branches. Git follows renames, and the rename is in its own commit. Land quickly, and tell whoever has branches touching src-tauri/src.
  • Silently losing cfg(desktop). The new test guards against it.
  • ACL permissions. Dropping a plugin dependency from the app crate fails the build loudly, in validate_capabilities.
  • The Pro build. Every path it uses is unchanged, and the Pro-mode compile check covers it.
  • Rollback: revert the PR.

Plan key: C2.5 (pro-boundary DAG).

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Sep 30, 2026
  2. added
    pro-boundary
    on Sep 30, 2026
  3. mstomar125 commented on Sep 30, 2026

    @mstomar125
    ContributorAuthor

    Completed in #3379 (merged). Auto-close did not fire; closing manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

pro-boundary

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions