Skip to content

Commit

Permalink
Do not cache rustc info in deps resolver
Browse files Browse the repository at this point in the history
The cargo_tree_resolver discovers dependencies by executing `cargo tree`
for different host and target triples. This procedure breaks when cargo
successfully but incorrectly caches rustc info. Incorrect cache hit may
happen because cache key does not take into account HOST_TRIPLE env
variable used by `rules_rust` to force rustc to report it's built for
different host.

The caching may happen if one has target/ directory in repo, or it was
created through running some commands outside of bazel.

Details:

After recent fixes to support properly bzlmod
(#3034) noticed issues
under windows when building bazel-lsp: cameron-martin/bazel-lsp#92

Cargo may cache rustc info in target/.rustc_info.json :
https://github.com/rust-lang/cargo/blob/769f622e12db0001431d8ae36d1093fb8727c5d9/src/cargo/util/rustc.rs#L163

The rules_rust hacks rustc by setting HOST_TRIPLE:
https://github.com/bazelbuild/rules_rust/blob/3aecdbedba0c001d0660ff631aeccb35d94ff3a7/crate_universe/src/metadata/cargo_tree_resolver.rs#L152

The HOST_TRIPLE env variable is not taken into account by cargo when
checking whether cached rustc info is valid:
https://github.com/rust-lang/cargo/blob/769f622e12db0001431d8ae36d1093fb8727c5d9/src/cargo/util/rustc.rs#L320
  • Loading branch information
hauserx committed Dec 15, 2024
1 parent 3aecdbe commit f35dacf
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions crate_universe/src/metadata/cargo_tree_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ impl TreeResolver {
// host triple instead of the host triple detected by rustc.
.env("RUSTC_WRAPPER", rustc_wrapper)
.env("HOST_TRIPLE", host_triple)
.env("CARGO_CACHE_RUSTC_INFO", "0")
.current_dir(manifest_path.parent().expect("All manifests should have a valid parent."))
.arg("tree")
.arg("--manifest-path")
Expand Down

0 comments on commit f35dacf

Please sign in to comment.