Add incremental Rust compilation via Bazel-managed tree artifacts#3925
Open
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
Open
Add incremental Rust compilation via Bazel-managed tree artifacts#3925rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
Conversation
…acts Rustc's incremental compilation cache is stored as Bazel-managed tree artifacts so the path is identical on local and remote workers. The process wrapper seeds the cache from previous builds using hardlinks (with EXDEV fallback), with a configurable size threshold to skip small crates where loading overhead exceeds benefit. Key changes: - rustc.bzl: Declare tree artifact outputs for incremental state, gate on workspace crates, separate main/metadata artifacts - rust.bzl/settings.bzl: Add incremental and seed_threshold_mb settings - process_wrapper: Add --copy-seed, --seed-prev-dir, --seed-min-mb, --write-unused-inputs, --exit-early flags for cache management - Parallel hardlinking for trees with >256 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--@rules_rust//rust/settings:incremental=truebuild setting to enable incremental Rust compilation in Bazelincremental_seed_threshold_mb, default 20) skips seeding small crates where rustc's dep-graph loading overhead exceeds benefitunused_inputs_listensures seed changes don't invalidate action cache keysDesign
Rustc's incremental compilation stores state in a persistent directory. This PR makes that state a Bazel-managed tree artifact so:
Only workspace crates get incremental compilation (external deps are excluded via
ctx.label.workspace_rootgate). Exec-config targets (proc macros, build scripts) are also excluded. Both main and metadata actions use-Cincrementalfor matching SVH but with separate tree artifacts to prevent corruption from--rustc-quit-on-rmeta.The process wrapper handles cache seeding:
--copy-seed: hardlinks a seed tree artifact into the output directory--seed-prev-dir: reads directly from the previous build's output (for theRustcIncrSeedaction)--seed-min-mb: configurable threshold (default 20 MiB) to skip small caches--write-unused-inputs: populates the unused inputs list so Bazel excludes the seed from cache keys--exit-early: exits after pre-exec operations without spawning a child processTest plan
--@rules_rust//rust/settings:incremental=trueand verify incremental compilation works