Add exec config trimming to stabilize tool config hashes across modes#3926
Open
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
Open
Add exec config trimming to stabilize tool config hashes across modes#3926rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
rejuvenile wants to merge 1 commit intobazelbuild:mainfrom
Conversation
Configuration transitions that strip build-mode-specific settings from exec-config targets, improving cache hit rates across debug/asan/tsan/ release configurations. When switching between build modes, proc macros and build scripts were rebuilding because Starlark settings (lto, codegen_units, etc.) and native flags (compilation_mode, stamp, strip) leaked into the exec configuration hash. The actual rustc commands were identical, but different hashes prevented cache reuse. Key changes: - Add exec_settings_trim.bzl with marker-based reset mechanism - rust_proc_macro transitions unconditionally reset settings - Other rule transitions propagate the reset when the marker is set - Consolidate all rule transitions into shared rule_transition_impl() - Handle write-only flags (run_under) and build script trimming
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
rust_proc_macrotransitions unconditionally reset settings (proc macros are always exec tools)rule_transition_impl()functionMotivation
Bazel's built-in exec transition resets native flags (like
--compilation_mode) but does NOT reset Starlark build settings. This means settings like--@rules_rust//rust/settings:lto=thinleak into the exec configuration hash, causing proc macros and build scripts to rebuild unnecessarily when switching between e.g.fastbuildandoptmodes.rules_rust already strips these settings at action construction time (via
is_exec_configuration()checks), so the actual rustc commands for tools are identical. But the different config hash prevents cache reuse.Settings reset in exec configuration
compilation_mode,stamp,strip,run_underlto,codegen_units,extra_rustc_flags,extra_rustc_flag,extra_rustc_env,incremental,pipelined_compilation,no_std,experimental_per_crate_rustc_flagHow it works
rust_proc_macro's rule transition setsexec_settings_trimmed=Trueand resets all settings (viaforce=True)True, it also resets settings, propagating transitively through the exec dependency subgraphrun_underflag is write-only (cannot be read in Starlark) so it's only included in proc macro outputsTest plan
--compilation_mode=optthen--compilation_mode=fastbuildand verify proc macros are not rebuilt--@rules_rust//rust/settings:lto=thindoes not affect proc macro config hashes