Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3294,9 +3294,7 @@ impl Step for Bootstrap {
.env("INSTA_WORKSPACE_ROOT", &builder.src)
.env("RUSTC_BOOTSTRAP", "1");

// 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.
Comment on lines -3297 to -3298
Copy link
Contributor

@klensy klensy Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implies that tests no longer racy?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have attempted to remove all racy tests. If we find any more on CI, we should fix them, rather than making the test execution serial.

run_cargo_test(cargo, &["--test-threads=1"], &[], None, host, builder);
run_cargo_test(cargo, &[], &[], None, host, builder);
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down
45 changes: 10 additions & 35 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::config::Config;
use crate::utils::cache::ExecutedStep;
use crate::utils::helpers::get_host_target;
use crate::utils::tests::ConfigBuilder;
use crate::utils::tests::git::{GitCtx, git_test};
use crate::utils::tests::{ConfigBuilder, TestCtx};

static TEST_TRIPLE_1: &str = "i686-unknown-haiku";
static TEST_TRIPLE_2: &str = "i686-unknown-hurd-gnu";
Expand All @@ -22,38 +22,13 @@ fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
}

fn configure_with_args(cmd: &[&str], host: &[&str], target: &[&str]) -> Config {
let cmd = cmd.iter().copied().map(String::from).collect::<Vec<_>>();
let mut config = Config::parse(Flags::parse(&cmd));
// don't save toolstates
config.save_toolstates = None;
config.set_dry_run(DryRun::SelfCheck);

// Ignore most submodules, since we don't need them for a dry run, and the
// tests run much faster without them.
//
// The src/doc/book submodule is needed because TheBook step tries to
// access files even during a dry-run (may want to consider just skipping
// that in a dry run).
let submodule_build = Build::new(Config {
// don't include LLVM, so CI doesn't require ninja/cmake to be installed
rust_codegen_backends: vec![],
..Config::parse(Flags::parse(&["check".to_owned()]))
});
submodule_build.require_submodule("src/doc/book", None);
config.submodules = Some(false);

config.ninja_in_file = false;
// try to avoid spurious failures in dist where we create/delete each others file
// HACK: rather than pull in `tempdir`, use the one that cargo has conveniently created for us
let dir = Path::new(env!("OUT_DIR"))
.join("tmp-rustbuild-tests")
.join(&thread::current().name().unwrap_or("unknown").replace(":", "-"));
t!(fs::create_dir_all(&dir));
config.out = dir;
config.host_target = TargetSelection::from_user(TEST_TRIPLE_1);
config.hosts = host.iter().map(|s| TargetSelection::from_user(s)).collect();
config.targets = target.iter().map(|s| TargetSelection::from_user(s)).collect();
config
TestCtx::new()
.config(cmd[0])
.args(&cmd[1..])
.hosts(host)
.targets(target)
.args(&["--build", TEST_TRIPLE_1])
.create_config()
}

fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
Expand Down Expand Up @@ -547,8 +522,8 @@ mod snapshot {

use crate::core::build_steps::{compile, dist, doc, test, tool};
use crate::core::builder::tests::{
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, configure_with_args,
first, host_target, render_steps, run_build,
RenderConfig, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, configure, first, host_target,
render_steps, run_build,
};
use crate::core::builder::{Builder, Kind, StepDescription, StepMetadata};
use crate::core::config::TargetSelection;
Expand Down
21 changes: 14 additions & 7 deletions src/bootstrap/src/utils/cc_detect/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::{env, iter};

use super::*;
use crate::core::config::{Target, TargetSelection};
use crate::{Build, Config, Flags};
use crate::utils::tests::TestCtx;
use crate::{Build, Config, Flags, t};

#[test]
fn test_ndk_compiler_c() {
Expand Down Expand Up @@ -68,7 +69,8 @@ fn test_language_clang() {

#[test]
fn test_new_cc_build() {
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let build = Build::new(config);
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
let cfg = new_cc_build(&build, target.clone());
let compiler = cfg.get_compiler();
Expand All @@ -77,7 +79,8 @@ fn test_new_cc_build() {

#[test]
fn test_default_compiler_wasi() {
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let mut build = Build::new(config);
let target = TargetSelection::from_user("wasm32-wasi");
let wasi_sdk = PathBuf::from("/wasi-sdk");
build.wasi_sdk_path = Some(wasi_sdk.clone());
Expand All @@ -98,7 +101,8 @@ fn test_default_compiler_wasi() {

#[test]
fn test_default_compiler_fallback() {
let build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let build = Build::new(config);
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
let mut cfg = cc::Build::new();
let result = default_compiler(&mut cfg, Language::C, target, &build);
Expand All @@ -107,7 +111,8 @@ fn test_default_compiler_fallback() {

#[test]
fn test_find_target_with_config() {
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let mut build = Build::new(config);
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
let mut target_config = Target::default();
target_config.cc = Some(PathBuf::from("dummy-cc"));
Expand All @@ -128,7 +133,8 @@ fn test_find_target_with_config() {

#[test]
fn test_find_target_without_config() {
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let mut build = Build::new(config);
let target = TargetSelection::from_user("x86_64-unknown-linux-gnu");
build.config.target_config.clear();
fill_target_compiler(&mut build, target.clone());
Expand All @@ -141,7 +147,8 @@ fn test_find_target_without_config() {

#[test]
fn test_find() {
let mut build = Build::new(Config { ..Config::parse(Flags::parse(&["build".to_owned()])) });
let config = TestCtx::new().config("build").create_config();
let mut build = Build::new(config);
let target1 = TargetSelection::from_user("x86_64-unknown-linux-gnu");
let target2 = TargetSelection::from_user("x86_64-unknown-openbsd");
build.targets.push(target1.clone());
Expand Down
Loading