Skip to content

Commit 9e7e29e

Browse files
committed
fix(fingerprint): force update mtime of cargo-check artifacts
This mtime shift for .rmeta is a workaround as rustc incremental build since rust-lang/rust 114669 (1.90.0) skips unnecessary rmeta generation. The situation is like this: 1. When build script execution's external dependendies (rerun-if-changed, rerun-if-env-changed) got updated, the execution unit reran and got a newer mtime. 2. rustc type-checked the associated crate, though with incremental compilation, no rmeta regeneration. Its `.rmeta` stays old. 3. Run `cargo check` again. Cargo found build script execution had a new mtime than existing crate rmeta, so re-checking the crate. However the check is a no-op (input has no change), so stuck.
1 parent 2a07c68 commit 9e7e29e

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,25 @@ fn rustc(
477477
paths::set_file_time_no_err(dep_info_loc, timestamp);
478478
}
479479

480+
// This mtime shift for .rmeta is a workaround as rustc incremental build
481+
// since rust-lang/rust#114669 (1.90.0) skips unnecessary rmeta generation.
482+
//
483+
// The situation is like this:
484+
//
485+
// 1. When build script execution's external dependendies
486+
// (rerun-if-changed, rerun-if-env-changed) got updated,
487+
// the execution unit reran and got a newer mtime.
488+
// 2. rustc type-checked the associated crate, though with incremental
489+
// compilation, no rmeta regeneration. Its `.rmeta` stays old.
490+
// 3. Run `cargo check` again. Cargo found build script execution had
491+
// a new mtime than existing crate rmeta, so re-checking the crate.
492+
// However the check is a no-op (input has no change), so stuck.
493+
if mode.is_check() {
494+
for output in outputs.iter() {
495+
paths::set_file_time_no_err(&output.path, timestamp);
496+
}
497+
}
498+
480499
Ok(())
481500
}));
482501

tests/testsuite/freshness.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,9 +3229,7 @@ fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
32293229
p.cargo("check -v")
32303230
.env("CARGO_INCREMENTAL", "1")
32313231
.with_stderr_data(str![[r#"
3232-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3233-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3234-
[RUNNING] `rustc --crate-name foo [..]`
3232+
[FRESH] foo v0.0.1 ([ROOT]/foo)
32353233
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
32363234
32373235
"#]])
@@ -3240,9 +3238,7 @@ fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
32403238
p.cargo("check -v")
32413239
.env("CARGO_INCREMENTAL", "1")
32423240
.with_stderr_data(str![[r#"
3243-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3244-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3245-
[RUNNING] `rustc --crate-name foo [..]`
3241+
[FRESH] foo v0.0.1 ([ROOT]/foo)
32463242
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
32473243
32483244
"#]])

tests/testsuite/freshness_checksum.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,9 +3007,7 @@ fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
30073007
.masquerade_as_nightly_cargo(&["checksum-freshness"])
30083008
.env("CARGO_INCREMENTAL", "1")
30093009
.with_stderr_data(str![[r#"
3010-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3011-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3012-
[RUNNING] `rustc --crate-name foo [..]`
3010+
[FRESH] foo v0.0.1 ([ROOT]/foo)
30133011
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
30143012
30153013
"#]])
@@ -3019,9 +3017,7 @@ fn incremental_build_script_execution_got_new_mtime_and_cargo_check() {
30193017
.masquerade_as_nightly_cargo(&["checksum-freshness"])
30203018
.env("CARGO_INCREMENTAL", "1")
30213019
.with_stderr_data(str![[r#"
3022-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the dependency build_script_build was rebuilt ([TIME_DIFF_AFTER_LAST_BUILD])
3023-
[CHECKING] foo v0.0.1 ([ROOT]/foo)
3024-
[RUNNING] `rustc --crate-name foo [..]`
3020+
[FRESH] foo v0.0.1 ([ROOT]/foo)
30253021
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
30263022
30273023
"#]])

0 commit comments

Comments
 (0)