From 877f8e48794495d1aea2c7d95a9ee2d50937fade Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 11 Dec 2025 10:54:44 -0500 Subject: [PATCH 1/4] test: update to `proc_macro::tracked::path` Changed accordingly to https://github.com/rust-lang/rust/pull/149400 --- tests/testsuite/dep_info.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index fd150170b54..85c5d567b82 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -588,7 +588,7 @@ fn no_trailing_separator_after_package_root_build_script() { ); } -#[cargo_test(nightly, reason = "proc_macro::tracked_path is unstable")] +#[cargo_test(nightly, reason = "proc_macro::tracked::path is unstable")] fn no_trailing_separator_after_package_root_proc_macro() { let p = project() .file( @@ -626,13 +626,13 @@ fn no_trailing_separator_after_package_root_proc_macro() { .file( "pm/src/lib.rs", r#" - #![feature(track_path)] + #![feature(proc_macro_tracked_path)] extern crate proc_macro; use proc_macro::TokenStream; #[proc_macro] pub fn noop(_item: TokenStream) -> TokenStream { - proc_macro::tracked_path::path( + proc_macro::tracked::path( std::env::current_dir().unwrap().to_str().unwrap() ); "".parse().unwrap() From cdeebd8c4fe314514087caa53d95936185463f4d Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 11 Dec 2025 11:09:06 -0500 Subject: [PATCH 2/4] test: fix clippy warnings ``` error: this assertion has a constant value --> crates/build-rs-test-lib/src/lib.rs:3:5 | 3 | assert!(cfg!(did_run_build_script)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: consider moving this into a const block: `const { assert!(..) }` = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#assertions_on_constants = note: `-D clippy::assertions-on-constants` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::assertions_on_constants)]` ``` A bit annoying we can't have `lint.workspace = true` for this crate yet --- crates/build-rs-test-lib/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/build-rs-test-lib/src/lib.rs b/crates/build-rs-test-lib/src/lib.rs index 871cc4ee586..a9297b6a17b 100644 --- a/crates/build-rs-test-lib/src/lib.rs +++ b/crates/build-rs-test-lib/src/lib.rs @@ -1,4 +1,4 @@ #[test] fn test() { - assert!(cfg!(did_run_build_script)); + const { assert!(cfg!(did_run_build_script)) }; } From b68eed526b2273d48b53892351c96051592dc09f Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Fri, 12 Dec 2025 10:40:45 +0900 Subject: [PATCH 3/4] test(check): Verify build-dir lock is taken on check builds --- tests/testsuite/check.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 470b18b0a31..5c76be3ca83 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1719,6 +1719,28 @@ fn check_build_should_not_lock_artifact_dir() { assert!(!p.root().join("target/debug/.cargo-lock").exists()); } +#[cargo_test] +fn check_build_should_not_lock_artifact_dir_when_build_dir_is_not_same_dir() { + let p = project() + .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) + .file( + ".cargo/config.toml", + r#" + [build] + target-dir = "target-dir" + build-dir = "build-dir" + "#, + ) + .build(); + + p.cargo("check").enable_mac_dsym().run(); + + // Verify we did NOT take the build-dir lock + assert!(!p.root().join("target-dir/debug/.cargo-lock").exists()); + // Verify we did take the build-dir lock + assert!(p.root().join("build-dir/debug/.cargo-lock").exists()); +} + // Regression test for #16305 #[cargo_test] fn check_build_should_not_uplift_proc_macro_dylib_deps() { From eb38bca9dc2aaea4c7aba3e241d1d594cd142a50 Mon Sep 17 00:00:00 2001 From: Ross Sullivan Date: Fri, 12 Dec 2025 10:48:31 +0900 Subject: [PATCH 4/4] fix(check): Fixed incorrect locking logic when artifact-dir == build-dir --- src/cargo/core/compiler/layout.rs | 7 ++++++- tests/testsuite/check.rs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cargo/core/compiler/layout.rs b/src/cargo/core/compiler/layout.rs index 272e8198e27..e30d178eda4 100644 --- a/src/cargo/core/compiler/layout.rs +++ b/src/cargo/core/compiler/layout.rs @@ -151,7 +151,12 @@ impl Layout { // actual destination (sub)subdirectory. paths::create_dir_all(dest.as_path_unlocked())?; - let build_dir_lock = if root == build_root || is_on_nfs_mount(build_root.as_path_unlocked()) + // We always need to take the build-dir lock but if the build-dir == artifact-dir then we + // only take the artifact-dir. (locking both as they are the same dir) + // However we need to take into account that for some builds like `cargo check` we avoid + // locking the artifact-dir. We still need to lock the build-dir to avoid file corruption. + let build_dir_lock = if (must_take_artifact_dir_lock && root == build_root) + || is_on_nfs_mount(build_root.as_path_unlocked()) { None } else { diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 5c76be3ca83..21709c60f1d 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -1710,13 +1710,13 @@ fn check_build_should_not_output_files_to_artifact_dir() { } #[cargo_test] -fn check_build_should_not_lock_artifact_dir() { +fn check_build_should_lock_target_dir_when_artifact_dir_is_same_as_build_dir() { let p = project() .file("src/main.rs", r#"fn main() { println!("Hello, World!") }"#) .build(); p.cargo("check").enable_mac_dsym().run(); - assert!(!p.root().join("target/debug/.cargo-lock").exists()); + assert!(p.root().join("target/debug/.cargo-lock").exists()); } #[cargo_test]