Skip to content

Move the bundle-staging build helpers into a nodespace-app-build crate #3305

Closed

Description

@mstomar125

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

Summary

Move core's two build-script helpers into a new crate, nodespace-app-build, at packages/desktop-app/app-build:

  • drop_unstaged_bundle_entries, which lets a debug build and tests run without staged sidecars;
  • sync_stale_sidecar, which stops tauri_build from overwriting a fresh target/<profile>/<bin> with a stale staged sidecar.

Any app crate built on core, core's own included, can then call them from its build.rs (ADR-082 (proposed) §3.1 and §3.7, item 3). test-support uses the crate as an ordinary dependency instead of a #[path] include.

drop_unstaged_bundle_entries also stops hard-coding core's skill path: it drops any unstaged resources entry. For core's config the result is exactly today's.

Context

src-tauri/build.rs

  • SKILL_RESOURCES (70).
  • drop_unstaged_bundle_entries (72-170):
    • it runs only in debug builds, and only when TAURI_CONFIG is unset;
    • it reads tauri.conf.json from the build script's working directory;
    • it drops externalBin entries whose <entry>-<triple><exe> file is missing;
    • it drops the resources/skill/**/* entry when resources/skill is missing or empty;
    • it writes the result as a TAURI_CONFIG patch and prints one cargo:warning;
    • it emits rerun-if-changed on the nearest existing ancestor of each dropped path.
  • sync_external_bin_staging (15-66) stays in core's build.rs, because its EXTERNAL_BIN_NAMES list is core's own. It calls build_support::sync_stale_sidecar.

src-tauri/build_support.rs

  • 141 lines. It holds sync_stale_sidecar (111).
  • Its module doc says it is a shared file rather than a crate, because test-support depends on the app, so a build dependency back onto the app would be a cycle.
  • That no longer holds: the new crate depends on nothing in the app.

test-support (in app-lib/test-support after #3303)

  • It includes the file through #[path].
  • It re-exports sync_stale_sidecar for tests/it/sidecar_staging_sync_test.rs.

Why the skill path has to go. In a generated app config, such as the Pro app crate's, resource paths point into a core checkout. A fixed "resources/skill/**/*" string would never match there.

Scope

New packages/desktop-app/app-build/

Cargo.toml

  • Package nodespace-app-build, lib nodespace_app_build.
  • version.workspace = true, edition.workspace = true, publish = false.
  • The only dependency is serde_json = { workspace = true }.
  • No tauri dependency, so the crate runs in the ordinary workspace nextest run on every platform.

src/lib.rs: a crate doc, written generically for "an app crate built on core's library". It says what each helper is for, and that both are called before tauri_build::build().

src/sidecar_staging.rs

  • build_support.rs moved here (git mv), with pub fn sync_stale_sidecar.
  • Rewrite the "why not a crate" paragraph of its doc.

src/bundle_entries.rs

  • pub fn drop_unstaged_bundle_entries(): the wrapper that reads the environment. Its behaviour is today's.
  • A pure function that returns the patch and the list of missing paths:
    fn plan(
        conf: &serde_json::Value,
        target_triple: &str,
        exe_suffix: &str,
        file_exists: impl Fn(&Path) -> bool,
        dir_has_entries: impl Fn(&Path) -> bool,
    ) -> Option<Plan>
  • The generalized rule: keep a string resources entry when its base directory exists and is non-empty. Otherwise, drop the entry and list it as missing.
    • The base directory is the path up to the first *, ? or [. If there is none, it is the path itself.
  • Non-string entries and a map-form resources keep today's handling. They stay as declared, and a map means the function does nothing.
  • Keep the warning's shape, and reword its hint generically, for example "only needed to run the app; stage them to include them".

Core's app crate

  • src-tauri/Cargo.toml: add nodespace-app-build = { path = "../app-build" } to [build-dependencies]. Drop serde_json if build.rs no longer uses it.
  • src-tauri/build.rs:
    • remove mod build_support;, SKILL_RESOURCES and drop_unstaged_bundle_entries;
    • call nodespace_app_build::drop_unstaged_bundle_entries();
    • have sync_external_bin_staging call nodespace_app_build::sync_stale_sidecar;
    • keep the ordering comment: both run before tauri_build::build().
  • Delete src-tauri/build_support.rs, which has moved.

Test support and tooling

  • app-lib/test-support:
    • add nodespace-app-build = { path = "../../app-build" };
    • replace the #[path] module with pub use nodespace_app_build::sync_stale_sidecar;;
    • update the comment there.
  • Root Cargo.toml: add the member.
  • scripts/gate-scope.ts: add "packages/desktop-app/app-build/" to RUST_DIRS, and add a case to gate-scope.test.ts.
  • packages/desktop-app/vite.config.js: add "**/app-build/**" to the watch ignore list.
  • scripts/test-app-units.ts: its comments name build.rs's drop_unstaged_bundle_entries. Point them at the helper crate. The logic doesn't change.

Out of scope

  • sync_external_bin_staging and EXTERNAL_BIN_NAMES, which stay core's own.
  • The Pro app crate's build.rs, which is a sync item.

Steps

  1. Run the CLAUDE.md startup sequence. Self-assign at pickup; the worktree is issue-<N>-app-build-helpers.
  2. Create the crate, and move build_support.rs into it.
  3. Write plan, the wrapper and their tests, then switch core's build.rs over.
  4. Update test-support and the tooling.
  5. In a fresh worktree with nothing staged, check two builds:
    • cargo build -p nodespace-app (debug) succeeds and prints the same list of missing paths as before; only the hint's wording changes;
    • cargo build --release -p nodespace-app still fails on the missing sidecars.
  6. Run bun run quality:fix, then bun run test:changed.

Acceptance criteria

  • nodespace-app-build exists, has no tauri dependency, and bun run rust:test runs its unit tests.
  • Core's build.rs uses the crate for both helpers, and build_support.rs is gone.
  • For core's tauri.conf.json with nothing staged, the TAURI_CONFIG patch is exactly today's, {"bundle":{"resources":["resources/models/**/*"],"externalBin":[]}}, and a test pins it.
  • A debug build in a fresh worktree succeeds, and a release build still fails without staged sidecars.
  • sidecar_staging_sync_test passes through test-support's new re-export.
  • bun run scripts/check-pro-boundary.ts passes. BASELINES are lowered to the exact new counts wherever this PR removes markers, and no count rises.
  • No product names or GitHub issue numbers in the new code or docs.

Tests and verification

New tests in app-build/src/bundle_entries.rs:

  • keeps_everything_when_everything_is_staged (returns None)
  • drops_an_unstaged_sidecar
  • drops_a_resource_whose_base_directory_is_empty_or_missing
  • keeps_a_resource_whose_base_directory_has_a_file (the .gitkeep case of resources/models)
  • leaves_non_string_entries_as_declared
  • core_config_with_nothing_staged_matches_todays_patch (reads ../src-tauri/tauri.conf.json through include_str!)

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

cargo test -p nodespace-app-build
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 sidecar_staging_sync_test:: -- --test-threads=1
cargo clippy -p nodespace-app-build -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 test:changed   # gate files changed, so every tier runs

Dependencies

Risks and rollback

  • A build-script regression breaks every build. plan is pure and unit-tested, and the core-config test pins today's output.
  • The Pro build. sync passes --config, which sets TAURI_CONFIG, so the helper leaves its bundle config alone, as it does today.
  • Rollback: revert.

Plan key: C2.6 (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 #3386 (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