Skip to content

fix(ts): rebuild a target directory when its std sysroot changes - #256

Merged
kixelated merged 4 commits into
mainfrom
quest/m2/ts-sysroot-fingerprint
Oct 30, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m2/ts-sysroot-fingerprint

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Completes and deletes quest/m2/ts-sysroot-fingerprint.md.

Problem

After #237, the wrapper adds --sysroot itself, so nothing cargo fingerprints names the sysroot. If a second sysroot differs from the first only in std's flags, a target directory keeps crates checked against the old std. Reproduced: I translated crates, then translated it again against a sysroot built with only profile.toml's std line changed. It failed with E0463 on crates_dep, and stock fails with E0460. It kept failing until the target directory was cleaned.

Approach

  • The wrapper's rustc -vV adds a line rust2-ts-sysroot: <path>. Cargo hashes that output into every unit's fingerprint, and with -Zseparate-nightlies, which the CLI sets, into -C metadata too. Switching sysroots therefore rechecks every crate. Each sysroot also keeps its own artifacts, so switching back rechecks nothing.
  • The CLI sets CARGO_CACHE_RUSTC_INFO=0. Otherwise cargo would reuse the version cached in .rustc_info.json, which it keys only by the executables' paths and mtimes. That costs about 13 ms per query on this host.
  • The wrapper still adds --sysroot only for wasm32 crates, so build scripts and proc macros keep the host std.
  • Checked by hand in one target directory with the real second sysroot, switching A, then B, then A:
    • codec: registry crates, proc macros, and build scripts.
    • stock: with its profile.dev.package.getrandom.rustflags override.
    • B rechecks every crate. Back on A, everything is Fresh except the package, which always recompiles.
  • Test: sysroot in ts/tests/fixtures.rs runs in the merge gate (about 1.7 s). It censuses reject in one target directory against the flake's sysroot, then against the same std by another path (<sysroot>/../<name>), then the first again. It checks that bytes (a registry crate) is rechecked and then stays Fresh. It fails without the fix. It does nothing in the nightly run that leaves RUST2_TS_SYSROOT empty.
  • Snapshots and censuses are unchanged: just ci passes.

Impact

  • No public API change.
  • With a sysroot set, the compiler version cargo records for rust2-ts names the sysroot.
  • Proc macros and build scripts compile once more per sysroot.
  • With -Zseparate-nightlies, a target directory keeps artifacts for each nightly instead of replacing them.

Alternatives

  • --sysroot in the profile's rustflags, which the quest suggested: implemented first and dropped. A package-level profile.dev.package.<pkg>.rustflags replaces the profile's flags. That crate then compiles against the toolchain's std: stock's getrandom override failed with E0460 on a single sysroot. Covering it would mean refusing such overrides, a breaking change.
  • __CARGO_DEFAULT_LIB_METADATA: an internal variable meant for building std, and it also renames dylibs and executables.
  • Without -Zseparate-nightlies: E0460 would still be fixed, but on a nightly, sysroots would evict each other's artifacts.

Follow-ups

  • A sysroot rebuilt in place at the same path is still not detected, since the path is its identity. Only Nix sets RUST2_TS_SYSROOT, and its store paths change with their inputs. No quest filed.

Review

Codex gpt-6.1-sol, medium effort, quest review round 1 against origin/main cff3177b, on head e7498a0: no findings.

Checks: just ci passed on e7498a0.

Merge of main at 2a8cd4cbd3219513d5357df256d5d124cfe36937: git merged it without conflicts and just ci passed on this exact tree; it is a recorded skip, too trivial to review, on top of round 1's clean review of e7498a0c.

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 3 commits October 29, 2026 22:58
…ingerprints

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Rebuild a target directory when its std changes fix(ts): rebuild a target directory when its std sysroot changes Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 06:28
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 20b4af04-d7d9-425a-ae5c-b77d83039f2f
Commits

Reviewing files that changed from the base of the PR and between 1ce0b44 and 2a8cd4c.

Files selected for processing: 5
  • quest/m2/README.md
  • quest/m2/ts-sysroot-fingerprint.md
  • ts/src/cli.rs
  • ts/src/driver.rs
  • ts/tests/fixtures.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated review by review (OpenAI)

Reviewed commit e7498a0ca68add117252cfba47941533089c1367.

No actionable bugs found in this static review. The sysroot identity is exposed through the wrapper's version query, with Cargo's executable-only version cache disabled and separate-nightly metadata enabled in the same invocation. The actual --sysroot argument remains restricted to wasm32 compilation, preserving host build-script and proc-macro std. This avoids replacing package-specific rustflags or introducing a second artifact cache.

Direction: a small fix at Cargo's compiler-identity boundary is preferable to cleaning the whole target directory or refusing package overrides. The A/B/A regression checks registry dependency invalidation and reuse. Its B uses an alternate path to identical std contents, so the reported genuinely different-std and package-override exercises remain valuable complementary evidence, not coverage established by that fixture alone. Path identity also intentionally relies on immutable Nix store paths; an in-place rebuild at the same path remains outside this guarantee.

Verification limits: GitHub-only inspection of CLI/driver integration, shared Cargo launching, Nix sysroot construction and test wiring, with an independent pass. I did not run Cargo, translation, builds, or the regression suite, and did not independently reproduce the reported timings or two-sysroot experiments.

(Written by OpenAI)

@kixelated
kixelated merged commit baa2762 into main Oct 30, 2026
2 checks passed
@kixelated
kixelated deleted the quest/m2/ts-sysroot-fingerprint branch October 30, 2026 06:51
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.

1 participant