Skip to content

Commit b0847b7

Browse files
committed
feat/dist/rust: include Cargo.toml in the hash keys
Solves a corner case when a procmacro relies upon Cargo.toml availability to retrieve crate aliases from Cargo.toml. Issue: mozilla#676 Side effects: Cache invalidation on Cargo.toml comment changes, the hash changes and as such the cache breaks.
1 parent abc2759 commit b0847b7

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/compiler/rust.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,16 @@ where
231231
let pool = pool.clone();
232232
let cwd = cwd.to_owned();
233233
let crate_name = crate_name.to_owned();
234+
let cargo_toml = cwd.join("Cargo.toml");
235+
trace!("[{}]: add cargo_toml: {:?}", crate_name, cargo_toml.display());
236+
234237
Box::new(dep_info.and_then(move |_| -> SFuture<_> {
235238
let name2 = crate_name.clone();
236239
let parsed = pool.spawn_fn(move || {
237240
parse_dep_file(&dep_file, &cwd)
238241
.chain_err(|| format!("Failed to parse dep info for {}", name2))
239242
});
240-
Box::new(parsed.map(move |files| {
243+
Box::new(parsed.map(move |mut files| {
241244
trace!(
242245
"[{}]: got {} source files from dep-info in {}",
243246
crate_name,
@@ -246,6 +249,7 @@ where
246249
);
247250
// Just to make sure we capture temp_dir.
248251
drop(temp_dir);
252+
files.push(cargo_toml);
249253
files
250254
}))
251255
}))
@@ -2897,7 +2901,7 @@ c:/foo/bar.rs:
28972901
let f = TestFixture::new();
28982902
const FAKE_DIGEST: &str = "abcd1234";
28992903
// We'll just use empty files for each of these.
2900-
for s in ["foo.rs", "bar.rs", "bar.rlib", "libbaz.a"].iter() {
2904+
for s in ["foo.rs", "bar.rs", "bar.rlib", "libbaz.a", "Cargo.toml"].iter() {
29012905
f.touch(s).unwrap();
29022906
}
29032907
let mut emit = HashSet::new();
@@ -2978,6 +2982,8 @@ c:/foo/bar.rs:
29782982
m.update(empty_digest.as_bytes());
29792983
// libbaz.a (static library, from staticlibs)
29802984
m.update(empty_digest.as_bytes());
2985+
// Cargo.toml
2986+
m.update(empty_digest.as_bytes());
29812987
// Env vars
29822988
OsStr::new("CARGO_BLAH").hash(&mut HashToDigest { digest: &mut m });
29832989
m.update(b"=");
@@ -3012,7 +3018,7 @@ c:/foo/bar.rs:
30123018
o => panic!("Got unexpected parse result: {:?}", o),
30133019
};
30143020
// Just use empty files for sources.
3015-
for src in ["foo.rs"].iter() {
3021+
for src in ["foo.rs", "Cargo.toml"].iter() {
30163022
let s = format!("Failed to create {}", src);
30173023
f.touch(src).expect(&s);
30183024
}

0 commit comments

Comments
 (0)