fix(cargo_build_script): keep real OUT_DIR path in cross-crate dep-env#4104
Open
esnunes wants to merge 1 commit into
Open
fix(cargo_build_script): keep real OUT_DIR path in cross-crate dep-env#4104esnunes wants to merge 1 commit into
esnunes wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
A `links` crate whose build script exposes an OUT_DIR-relative path via the
metadata convention (e.g. `cargo:include=$OUT_DIR/include`) propagated
`DEP_<LINKS>_INCLUDE` to a dependent build script with the producing crate's
OUT_DIR rewritten to a literal `${out_dir}` token. That token is only resolved
by process_wrapper's `--out-dir` for the crate that directly owns the build
script; a cross-crate `.depenv` is consumed by a *dependent* crate's
build-script runner (`bin.rs`), which resolves only `${pwd}`. The token
survived unresolved, so e.g. librocksdb-sys could not find `lz4.h`.
`outputs_to_dep_env` now redacts only the exec root and keeps the producing
crate's real out_dir-relative path. This is the same transitive-consumption
case `redact_flags` handles with per-build-script tokens; the dep-env path has
no such resolution on the consuming side, so emit the real path. It is safe
because build-script actions do not advertise `supports-path-mapping`, and the
producing crate's out_dir tree is already a declared input of the dependent
action at that path. The producing crate's own `.env` file still uses
`${out_dir}`, so path-mapping cache-shareability is unchanged.
Adds unit tests (unix + windows) and an end-to-end regression test.
Fixes bazelbuild#4103.
ecc3509 to
c5510c9
Compare
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
Fixes #4103.
A
links(-sys) crate whose build script exposes anOUT_DIR-relative path through the metadata convention (cargo:include=$OUT_DIR/include) propagatedDEP_<LINKS>_INCLUDEto a dependent build script with the producing crate'sOUT_DIRrewritten to the literal, unresolved${out_dir}token — e.g. the dependent sawDEP_LZ4_INCLUDE=<execroot>/${out_dir}/include, which does not exist, solibrocksdb-syscould not findlz4.h.This is a regression from #4011 (
experimental_output_paths, refined by #4050), which introduced the${out_dir}tokenization of build-script outputs. It is onmainonly — the latest release0.70.0predates #4011 and is unaffected.Root cause
outputs_to_dep_envredacted values withredact_paths, rewriting the producing crate'sout_dirto the generic${out_dir}token. That token is only resolved byprocess_wrapper's--out-dirfor the crate that directly owns the build script. A.depenvfile is instead consumed by a dependent crate's build-script runner (bin.rs), which only substitutes${pwd}and has no${out_dir}binding for another crate's out_dir — so the token survives unresolved.This is the same transitive-consumption scenario
redact_flagswas written for (per-build-script tokens plus matching--substentries added on the Starlark side). The dep-env path was left on the generic-token codepath, which has no resolution mechanism on the consuming side.Fix
outputs_to_dep_envnow redacts only the exec root (${pwd}) and keeps the producing crate's realout_dir-relative path. Safe because:bin.rs) already resolves${pwd};out_dirtree is already a declared input of the dependent build-script action at that same exec-root-relative path;supports-path-mapping, so--experimental_output_paths=stripnever rewrites the literal path;.envfile (outputs_to_env) still uses${out_dir}, so path-mapping cache-shareability for the owning target is unchanged.Tests
cargo/private/cargo_build_script_runner):dep_env_out_dir_is_preserved_not_tokenizedand a Windows variant assert the dep-env keeps the real path with only${pwd}tokenized.test/cargo_build_script/metadata_dep_env): the producer now exposes anOUT_DIR-relativeinclude/viacargo:include=, andinclude_test.rsasserts the dependent build script receives a resolved, existing path (red before the fix, green after).Reported downstream as hermeticbuild/rules_rs#163.
🤖 Generated with Claude Code