diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 20c54a28dda83..d0edf6c90899c 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -61,6 +61,9 @@ impl Step for Std { return; } + // Explicitly pass -p for all dependencies crates -- this will force cargo + // to also check the tests/benches/examples for these crates, rather + // than just the leaf crate. let crates = std_crates_for_run_make(&run); run.builder.ensure(Std { build_compiler: prepare_compiler_for_check(run.builder, run.target, Mode::Std) @@ -83,16 +86,12 @@ impl Step for Std { Kind::Check, ); - std_cargo(builder, target, &mut cargo); + std_cargo(builder, target, &mut cargo, &self.crates); if matches!(builder.config.cmd, Subcommand::Fix) { // By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot. cargo.arg("--lib"); } - for krate in &*self.crates { - cargo.arg("-p").arg(krate); - } - let _guard = builder.msg( Kind::Check, format_args!("library artifacts{}", crate_description(&self.crates)), @@ -135,14 +134,7 @@ impl Step for Std { Kind::Check, ); - std_cargo(builder, target, &mut cargo); - - // Explicitly pass -p for all dependencies krates -- this will force cargo - // to also check the tests/benches/examples for these crates, rather - // than just the leaf crate. - for krate in &*self.crates { - cargo.arg("-p").arg(krate); - } + std_cargo(builder, target, &mut cargo, &self.crates); let stamp = build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check-test"); diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index d5b15d7908646..290a00aa3c13a 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -195,11 +195,7 @@ impl Step for Std { Kind::Clippy, ); - std_cargo(builder, target, &mut cargo); - - for krate in &*self.crates { - cargo.arg("-p").arg(krate); - } + std_cargo(builder, target, &mut cargo, &self.crates); let _guard = builder.msg( Kind::Clippy, diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 96b4e15433f7e..03046b1126beb 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -266,10 +266,7 @@ impl Step for Std { target, Kind::Build, ); - std_cargo(builder, target, &mut cargo); - for krate in &*self.crates { - cargo.arg("-p").arg(krate); - } + std_cargo(builder, target, &mut cargo, &self.crates); cargo }; @@ -497,7 +494,12 @@ fn compiler_rt_for_profiler(builder: &Builder<'_>) -> PathBuf { /// Configure cargo to compile the standard library, adding appropriate env vars /// and such. -pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Cargo) { +pub fn std_cargo( + builder: &Builder<'_>, + target: TargetSelection, + cargo: &mut Cargo, + crates: &[String], +) { // rustc already ensures that it builds with the minimum deployment // target, so ideally we shouldn't need to do anything here. // @@ -605,6 +607,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1"); } + for krate in crates { + cargo.args(["-p", krate]); + } + let mut features = String::new(); if builder.no_std(target) == Some(true) { @@ -614,8 +620,10 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, cargo: &mut Car } // for no-std targets we only compile a few no_std crates + if crates.is_empty() { + cargo.args(["-p", "alloc"]); + } cargo - .args(["-p", "alloc"]) .arg("--manifest-path") .arg(builder.src.join("library/alloc/Cargo.toml")) .arg("--features") diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 7865b68565930..7fb0fe17eb0cf 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -783,7 +783,7 @@ fn doc_std( Kind::Doc, ); - compile::std_cargo(builder, target, &mut cargo); + compile::std_cargo(builder, target, &mut cargo, requested_crates); cargo .arg("--no-deps") .arg("--target-dir") @@ -803,10 +803,6 @@ fn doc_std( cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items"); } - for krate in requested_crates { - cargo.arg("-p").arg(krate); - } - let description = format!("library{} in {} format", crate_description(requested_crates), format.as_str()); let _guard = builder.msg(Kind::Doc, description, Mode::Std, build_compiler, target); diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 00aea8feab7de..2910de5e29ef7 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2963,7 +2963,7 @@ impl Step for Crate { .arg("--manifest-path") .arg(builder.src.join("library/sysroot/Cargo.toml")); } else { - compile::std_cargo(builder, target, &mut cargo); + compile::std_cargo(builder, target, &mut cargo, &[]); } } Mode::Rustc => {