Skip to content

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

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3305-app-build-helpers
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3305-app-build-helpers

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #3305

Part of #3298 (Pro/core boundary) and #3322 (Tauri extension points): the two build-script helpers move into a nodespace-app-build crate, so any app crate built on core's library can call them from its build.rs.

What changed

  • New crate packages/desktop-app/app-build (nodespace-app-build, lib nodespace_app_build). Its only dependency is serde_json; it has no tauri dependency, so it runs in the ordinary workspace nextest run on every platform (rust:test:workspace excludes only the three app crates).
    • sidecar_staging.rs is build_support.rs moved with git mv. Only the module doc changed: the "why not a crate" paragraph is gone and the rest is written for "an app crate", not for core's binaries.
    • bundle_entries.rs holds drop_unstaged_bundle_entries() and a pure plan(conf, target_triple, exe_suffix, file_exists, dir_has_entries) -> Option<Plan>. The wrapper reads the environment, calls plan, sets TAURI_CONFIG, prints the warning and emits rerun-if-changed.
    • The hard-coded skill path is gone. A string resources entry is kept when its base directory exists and is non-empty; otherwise it is dropped and listed as missing.
  • Core's build.rs drops mod build_support;, SKILL_RESOURCES and drop_unstaged_bundle_entries, and calls the crate for both helpers. sync_external_bin_staging and EXTERNAL_BIN_NAMES stay (they are core's own list). build_support.rs is deleted. serde_json is no longer a build dependency of the app crate.
  • nodespace-app-test-support takes the crate as a dependency and re-exports sync_stale_sidecar with pub use, replacing the #[path] include.
  • Tooling: Cargo.toml member, gate-scope.ts RUST_DIRS (+ a gate-scope.test.ts case), the vite watch ignore list, comments in test-app-units.ts / build-skill.ts / sidecar_staging_sync_test.rs, and the CLAUDE.md structure tree. test-app-units.ts logic is unchanged.

Parity with the old build script

The release bundle must stage exactly what it staged before. I compared the old and new build script three ways, with no full release/LTO build:

  1. Real cargo build -p nodespace-app (debug), same three scenarios before and after, each after resetting target/debug's staged copies. Nothing staged, sidecars + skill staged but the skill installer missing, and everything staged. In all three, what tauri_build copied into target/debug (file list and sizes) and the contents of binaries/ and resources/ are identical before and after. The build-script output differs only in the hint wording and in one absolute path containing the build-script hash directory; the cargo:warning list of missing paths and every cargo:rerun-if-changed line are identical.
    • nothing staged: not staged, left out of this debug build's bundle: binaries/nodespaced-aarch64-apple-darwin, binaries/nodespace-aarch64-apple-darwin, binaries/nodespace-skill-installer-aarch64-apple-darwin, resources/skill
  2. Differential test (temporary, not committed): the old function's logic transcribed verbatim against plan, over the core config for all 8 sidecar subsets x skill staged/unstaged, plus the Windows .exe suffix. Patch value, serialised patch string and missing-path list all matched.
  3. Release stays strict. I replayed the exact environment cargo gives the compiled build script (captured from a real run), changing only PROFILE: release with nothing staged exits 1 with resource path `binaries/nodespaced-aarch64-apple-darwin` doesn't exist; debug with nothing staged exits 0; release and debug with everything staged both exit 0.

An end-to-end mutation of the wrapper (drop the env::set_var("TAURI_CONFIG", ...) call) makes the real debug build fail with that same resource path ... doesn't exist error, so the wrapper is covered beyond the pure-function tests.

Deviations from the issue text (the code and a correct reading won)

  • Base directory is whole path components. The issue says "the path up to the first *, ? or [". Read literally, binaries/tool-* would be judged by binaries/tool-, which is never a directory, so the entry would be dropped even when the files exist. The base directory here is the run of whole components before the first glob character (binaries/tool-* -> binaries). For every entry in core's config the result is the issue's (resources/skill/**/* -> resources/skill, resources/models/**/* -> resources/models). Pinned by a_partial_filename_glob_is_judged_by_its_directory and base_dir_is_the_whole_components_before_the_first_glob_character.
  • A glob-free entry can be a file. "Exists and is non-empty" is false for a plain file, so a file counts as content too (a_glob_free_resource_is_kept_when_it_is_a_staged_file).
  • Two more tiny pure functions beyond plan: applies(profile, tauri_config_is_set) (debug only, never over an explicit TAURI_CONFIG) and nearest_existing_ancestor (the rerun-if-changed target). Both were inline before; splitting them made the "release stays strict" and "don't rerun every build" rules testable.
  • Patch key order. serde_json without preserve_order serialises externalBin before resources; the issue writes them the other way round. It is a JSON merge patch, so the order is irrelevant. The test compares JSON values, and the differential test above showed the serialised string is byte-identical to the old code's.
  • The models glob is no longer special. Under the generalised rule a debug build now also drops an unstaged resources/models entry with a warning, where before it failed with GlobPathNotFound. A checkout always has the tracked .gitkeep, so nothing changes for core today, and test-app-units.ts still requires the path up front as before.
  • Core-specific commentary moved, not dropped. The old doc's notes on what dev:tauri stages and how the Tauri-seam tests find the daemon are now a comment at the call site in core's build.rs; the crate's docs are generic.

Tests

New in app-build/src/bundle_entries.rs (14 tests in the crate; all six from the issue plus the extras above):
keeps_everything_when_everything_is_staged, drops_an_unstaged_sidecar, drops_a_resource_whose_base_directory_is_empty_or_missing, keeps_a_resource_whose_base_directory_has_a_file, leaves_non_string_entries_as_declared, core_config_with_nothing_staged_matches_todays_patch (reads tauri.conf.json via include_str!, pins the patch value and the printed list of missing paths), looks_for_the_executable_suffix_of_the_target_platform, a_partial_filename_glob_is_judged_by_its_directory, a_glob_free_resource_is_kept_when_it_is_a_staged_file, a_resources_map_leaves_the_config_alone, a_config_without_a_sidecar_list_is_left_alone, base_dir_is_the_whole_components_before_the_first_glob_character, only_a_debug_build_without_an_explicit_config_drops_entries, watches_the_nearest_existing_ancestor_of_a_dropped_path.

Mutation check: 20 breaks, each applied to the source, the crate's tests run, and the intended test confirmed failing before restoring (source restored byte-identical afterwards). All 20 were caught by the test meant to catch them, for example: plan never returning None, an unstaged sidecar never dropped, the .exe suffix ignored, unstaged resources never dropped, every resource dropped, a partial-name glob judged by its literal prefix, a staged file not counting as content, non-string sidecar or resource entries dropped, a resources map or a missing sidecar list treated as empty, missing paths reversed, externalBin omitted from the patch, a trailing separator kept on the base directory, only * starting a glob, an empty base not becoming ., applies true for non-debug profiles or over an explicit config, and the ancestor watch returning the path itself or the empty path.

gate-scope.test.ts gains packages/desktop-app/app-build/src/bundle_entries.rs in its "counts as a Rust input" table; without the RUST_DIRS entry that path would classify as frontend-only.

Verification run

  • cargo test -p nodespace-app-build (14 pass); cargo fmt; cargo clippy -p nodespace-app-build -p nodespace-app -p nodespace-app-test-support --all-targets -- -D warnings -D clippy::unused-async clean
  • NODESPACE_PRO_SUPABASE_URL=https://example.invalid NODESPACE_PRO_ANON_KEY=dummy cargo check -p nodespace-app passes
  • bun test scripts/gate-scope.test.ts (26 pass); bun run quality:scripts:fix; bun run --cwd packages/desktop-app quality:fix
  • bun run test:changed (every tier: the gate's own scripts changed)

Ratchet

bun run scripts/check-pro-boundary.ts passes with no count above its baseline. This change removes no Pro markers (I counted markers in the old and new text of every changed file: none in either), so BASELINES are untouched and no count rises. cloudSyncHooks reads 0 against a baseline of 4 from earlier merged work, not from this PR; I left it for whoever tightens next rather than add a conflicting edit to BASELINES here.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits September 30, 2026 13:25
drop_unstaged_bundle_entries and sync_stale_sidecar move out of the app
crate's build.rs and build_support.rs into packages/desktop-app/app-build,
so any app crate built on core's library can call them from its build.rs.
The crate has no tauri dependency and runs in the ordinary workspace test
run. nodespace-app-test-support takes it as a dependency instead of a
#[path] include.

drop_unstaged_bundle_entries no longer hard-codes core's skill path: it
drops any string resources entry whose base directory (the whole path
components before the first glob character) is missing or empty. The
decision is a pure function over injected file-system predicates, and a
test pins that core's config with nothing staged yields the same patch and
the same list of missing paths as before.

build.rs keeps sync_external_bin_staging, whose sidecar list is core's own,
and calls both helpers before tauri_build::build(). gate-scope, the vite
watch ignore list and the app-units script comments follow the new crate.

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

base_dir rebuilt its result from Path components, which re-joins with the
platform separator: on Windows the warning would print `resources\skill`
next to `binaries/...`, where the old code printed the entry's own
separators, and the two text assertions in the tests would not match. It now
cuts the entry at the last separator before the first glob character and
trims trailing separators on the string, so the entry's separators reach the
warning unchanged on every platform. A path of separators only stays the
root.

Two resources that draw from the same missing directory listed it twice in
the warning and in the rerun-if-changed output. It is listed once.

The drop_unstaged_bundle_entries doc now says what the rule leaves alone: a
config whose externalBin or resources is missing or not a list, a glob on
part of a file name (judged by its directory), a glob at the crate root
(never empty), and a non-empty directory that matches nothing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3305-app-build-helpers branch from 3e65dea to 6c170f2 Compare September 30, 2026 11:25
@mstomar125
mstomar125 merged commit cfea583 into main Sep 30, 2026
@mstomar125
mstomar125 deleted the issue-3305-app-build-helpers branch September 30, 2026 11:25
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.

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

1 participant