Skip to content

Commit

Permalink
Unrolled build for rust-lang#137679
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137679 - bjorn3:coretests_improvements, r=jieyouxu,onur-ozkan

Various coretests improvements

The first commit is not yet strictly necessary as directly testing libcore works though useless work, but will be necessary once rust-lang#136642 migrates the liballoc tests into a separate package. The second commit fixes rust-lang#137478 and ensures that coretests actually gets tested on all CI job. The third commit fixes an error that didn't get caught because coretests doesn't run on the wasm32 CI job.
  • Loading branch information
rust-timer authored Mar 5, 2025
2 parents 4559163 + 169e731 commit fc8e6b9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 69 deletions.
3 changes: 1 addition & 2 deletions library/coretests/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use core::num::NonZero;
use core::ops::{Range, RangeInclusive};
use core::slice;

use rand::seq::IndexedRandom;

#[test]
fn test_position() {
let b = [1, 2, 3, 5, 5];
Expand Down Expand Up @@ -1810,6 +1808,7 @@ fn select_nth_unstable() {
use core::cmp::Ordering::{Equal, Greater, Less};

use rand::Rng;
use rand::seq::IndexedRandom;

let mut rng = crate::test_rng();

Expand Down
82 changes: 24 additions & 58 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Step for CrateBootstrap {
);

let crate_name = path.rsplit_once('/').unwrap().1;
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
run_cargo_test(cargo, &[], &[], crate_name, bootstrap_host, builder);
}
}

Expand Down Expand Up @@ -140,15 +140,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
SourceType::InTree,
&[],
);
run_cargo_test(
cargo,
&[],
&[],
"linkchecker",
"linkchecker self tests",
bootstrap_host,
builder,
);
run_cargo_test(cargo, &[], &[], "linkchecker self tests", bootstrap_host, builder);

if builder.doc_tests == DocTests::No {
return;
Expand Down Expand Up @@ -337,7 +329,7 @@ impl Step for Cargo {
);

// NOTE: can't use `run_cargo_test` because we need to overwrite `PATH`
let mut cargo = prepare_cargo_test(cargo, &[], &[], "cargo", self.host, builder);
let mut cargo = prepare_cargo_test(cargo, &[], &[], self.host, builder);

// Don't run cross-compile tests, we may not have cross-compiled libstd libs
// available.
Expand Down Expand Up @@ -423,7 +415,7 @@ impl Step for RustAnalyzer {
cargo.env("SKIP_SLOW_TESTS", "1");

cargo.add_rustc_lib_path(builder);
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", host, builder);
run_cargo_test(cargo, &[], &[], "rust-analyzer", host, builder);
}
}

Expand Down Expand Up @@ -472,7 +464,7 @@ impl Step for Rustfmt {

cargo.add_rustc_lib_path(builder);

run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", host, builder);
run_cargo_test(cargo, &[], &[], "rustfmt", host, builder);
}
}

Expand Down Expand Up @@ -588,7 +580,7 @@ impl Step for Miri {

// We can NOT use `run_cargo_test` since Miri's integration tests do not use the usual test
// harness and therefore do not understand the flags added by `add_flags_and_try_run_test`.
let mut cargo = prepare_cargo_test(cargo, &[], &[], "miri", host, builder);
let mut cargo = prepare_cargo_test(cargo, &[], &[], host, builder);

// miri tests need to know about the stage sysroot
cargo.env("MIRI_SYSROOT", &miri_sysroot);
Expand Down Expand Up @@ -736,7 +728,7 @@ impl Step for CompiletestTest {
&[],
);
cargo.allow_features("test");
run_cargo_test(cargo, &[], &[], "compiletest", "compiletest self test", host, builder);
run_cargo_test(cargo, &[], &[], "compiletest self test", host, builder);
}
}

Expand Down Expand Up @@ -797,7 +789,7 @@ impl Step for Clippy {
cargo.env("HOST_LIBS", host_libs);

cargo.add_rustc_lib_path(builder);
let cargo = prepare_cargo_test(cargo, &[], &[], "clippy", host, builder);
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);

let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);

Expand Down Expand Up @@ -1277,15 +1269,7 @@ impl Step for CrateRunMakeSupport {
&[],
);
cargo.allow_features("test");
run_cargo_test(
cargo,
&[],
&[],
"run-make-support",
"run-make-support self test",
host,
builder,
);
run_cargo_test(cargo, &[], &[], "run-make-support self test", host, builder);
}
}

Expand Down Expand Up @@ -1322,7 +1306,7 @@ impl Step for CrateBuildHelper {
&[],
);
cargo.allow_features("test");
run_cargo_test(cargo, &[], &[], "build_helper", "build_helper self test", host, builder);
run_cargo_test(cargo, &[], &[], "build_helper self test", host, builder);
}
}

Expand Down Expand Up @@ -2507,13 +2491,12 @@ fn run_cargo_test<'a>(
cargo: builder::Cargo,
libtest_args: &[&str],
crates: &[String],
primary_crate: &str,
description: impl Into<Option<&'a str>>,
target: TargetSelection,
builder: &Builder<'_>,
) -> bool {
let compiler = cargo.compiler();
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, target, builder);
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
let _time = helpers::timeit(builder);
let _group = description.into().and_then(|what| {
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
Expand All @@ -2537,7 +2520,6 @@ fn prepare_cargo_test(
cargo: builder::Cargo,
libtest_args: &[&str],
crates: &[String],
primary_crate: &str,
target: TargetSelection,
builder: &Builder<'_>,
) -> BootstrapCommand {
Expand Down Expand Up @@ -2567,13 +2549,6 @@ fn prepare_cargo_test(
cargo.arg("--doc");
}
DocTests::No => {
let krate = &builder
.crates
.get(primary_crate)
.unwrap_or_else(|| panic!("missing crate {primary_crate}"));
if krate.has_lib {
cargo.arg("--lib");
}
cargo.args(["--bins", "--examples", "--tests", "--benches"]);
}
DocTests::Yes => {}
Expand Down Expand Up @@ -2748,15 +2723,15 @@ impl Step for Crate {
_ => panic!("can only test libraries"),
};

run_cargo_test(
cargo,
&[],
&self.crates,
&self.crates[0],
&*crate_description(&self.crates),
target,
builder,
);
let mut crates = self.crates.clone();
// The core crate can't directly be tested. We could silently
// ignore it, but adding it's own test crate is less confusing
// for users. We still keep core itself for doctests.
if crates.iter().any(|crate_| crate_ == "core") {
crates.push("coretests".to_owned());
}

run_cargo_test(cargo, &[], &crates, &*crate_description(&self.crates), target, builder);
}
}

Expand Down Expand Up @@ -2849,15 +2824,7 @@ impl Step for CrateRustdoc {
dylib_path.insert(0, PathBuf::from(&*libdir));
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

run_cargo_test(
cargo,
&[],
&["rustdoc:0.0.0".to_string()],
"rustdoc",
"rustdoc",
target,
builder,
);
run_cargo_test(cargo, &[], &["rustdoc:0.0.0".to_string()], "rustdoc", target, builder);
}
}

Expand Down Expand Up @@ -2914,7 +2881,6 @@ impl Step for CrateRustdocJsonTypes {
libtest_args,
&["rustdoc-json-types".to_string()],
"rustdoc-json-types",
"rustdoc-json-types",
target,
builder,
);
Expand Down Expand Up @@ -3094,7 +3060,7 @@ impl Step for Bootstrap {

// bootstrap tests are racy on directory creation so just run them one at a time.
// Since there's not many this shouldn't be a problem.
run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder);
run_cargo_test(cargo, &["--test-threads=1"], &[], None, host, builder);
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -3219,7 +3185,7 @@ impl Step for RustInstaller {
bootstrap_host,
bootstrap_host,
);
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder);

// We currently don't support running the test.sh script outside linux(?) environments.
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a
Expand Down Expand Up @@ -3610,7 +3576,7 @@ impl Step for TestFloatParse {
&[],
);

run_cargo_test(cargo_test, &[], &[], crate_name, crate_name, bootstrap_host, builder);
run_cargo_test(cargo_test, &[], &[], crate_name, bootstrap_host, builder);

// Run the actual parse tests.
let mut cargo_run = tool::prepare_tool_cargo(
Expand Down
8 changes: 0 additions & 8 deletions src/bootstrap/src/core/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct Package {
source: Option<String>,
manifest_path: String,
dependencies: Vec<Dependency>,
targets: Vec<Target>,
features: BTreeMap<String, Vec<String>>,
}

Expand All @@ -40,11 +39,6 @@ struct Dependency {
source: Option<String>,
}

#[derive(Debug, Deserialize)]
struct Target {
kind: Vec<String>,
}

/// Collects and stores package metadata of each workspace members into `build`,
/// by executing `cargo metadata` commands.
pub fn build(build: &mut Build) {
Expand All @@ -59,12 +53,10 @@ pub fn build(build: &mut Build) {
.filter(|dep| dep.source.is_none())
.map(|dep| dep.name)
.collect();
let has_lib = package.targets.iter().any(|t| t.kind.iter().any(|k| k == "lib"));
let krate = Crate {
name: name.clone(),
deps,
path,
has_lib,
features: package.features.keys().cloned().collect(),
};
let relative_path = krate.local_path(build);
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ struct Crate {
name: String,
deps: HashSet<String>,
path: PathBuf,
has_lib: bool,
features: Vec<String>,
}

Expand Down

0 comments on commit fc8e6b9

Please sign in to comment.