Repository navigation
Conversation
bazelbuild#4117 disables path mapping when a target's rustc_flags or rustc_env carry a location expansion. A rust_test built with `crate = ...` inherits that crate's rustc_env, already expanded in the crate's own rule, so its own attr.rustc_env holds no marker and its Rustc action is mapped: inputs are staged under bazel-out/cfg/ while the inherited env value still names the configuration's bin directory, and an include!(env!(...)) of a generated file fails to read it under --experimental_output_paths=strip. Treat the action as unmappable when any crate_info.rustc_env value contains ctx.bin_dir.path. Add mylibrary_env_test, a rust_test of mylibrary_env, which fails to build under strip without this change, and an analysis test of its inherited MY_DATA. Assisted-by: an AI coding agent
This branch has not been deployed
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.
#4117 turns path mapping off for a Rustc action when the target's
rustc_flagsorrustc_envcarry a location expansion, since an expanded value names a configuration's output directory, which path mapping never rewrites. Arust_testbuilt withcrate = ...slips past that check. It inherits the crate'srustc_env, already expanded in the crate's own rule, and has no marker in its ownattr.rustc_envto find. The test's Rustc action is then mapped: its inputs are staged underbazel-out/cfg/, while the inherited env value still namesbazel-out/k8-fastbuild/bin/.... Anyinclude!(env!(...))orinclude_bytes!(env!(...))of a generated file then fails under--experimental_output_paths=stripwith "couldn't read bazel-out/k8-fastbuild/bin/...".This change also treats the action as unmappable when any value in
crate_info.rustc_envcontainsctx.bin_dir.path. An env value is never path-mapped, so a value naming this configuration's output directory is as configuration-specific as an unexpanded macro.Test:
location_expansion_test.bzlgainsmylibrary_env_test, arust_test(crate = ":mylibrary_env")with norustc_envof its own, and an analysis test,location_expansion_inherited_rustc_env_test, that checks the inheritedMY_DATAvalue. As withmylibrary_envandmytest_env, the build-time guard is the target itself:mylibrary_env.rsdoesinclude_bytes!(env!("MY_DATA")), so under--experimental_output_paths=stripthe new target fails to build without therustc.bzlchange and builds with it.We found this turning on
--experimental_output_paths=stripin a repository where about 15 crates pass a generated file's path throughrustc_envand test themselves withrust_test(crate = ...). We carry this change as a patch on 0.74.0 until a release ships it.AI assistance: this change was written by an AI agent; we reviewed it and ran the tests above, with and without the fix.