Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1bc1993
make cargo test work for bootstrap self test
Shourya742 Sep 15, 2025
a12969e
walk up the ancestors
Shourya742 Sep 15, 2025
6c79f54
add an API in ConfigBuilder to point to config file for toml parsing
Shourya742 Sep 16, 2025
d488d33
let verify method run in test settings
Shourya742 Sep 16, 2025
ce4604e
remove using default toml config for test in get_toml, we handle it v…
Shourya742 Sep 16, 2025
24ed1a0
allow symlinking during test
Shourya742 Sep 16, 2025
05131bd
move most of the test to new testCtx
Shourya742 Sep 16, 2025
a29474d
this is dicy, whether we have a method to explicitly enable_llvm_over…
Shourya742 Sep 16, 2025
0c68c82
rename config_toml to with_default_toml_config
Shourya742 Sep 21, 2025
9189bf7
remove create_config_without_ci_llvm_override duplication
Shourya742 Sep 21, 2025
671aabd
add dry_run flag in config builder and remove runtime test hacks
Shourya742 Sep 21, 2025
afe380d
initialize out with CARGO_TARGET_DIR and then go for manifest and the…
Shourya742 Sep 21, 2025
a48cd76
add explicit config assignment when running the test, as the src is a…
Shourya742 Sep 21, 2025
33e262e
remove prepare_test_specific_dir and update tests accordingly
Shourya742 Sep 21, 2025
6adbb3a
remove explicit target assignment in config during rustc initialization
Shourya742 Sep 22, 2025
8a0e380
add check for toml file
Shourya742 Sep 22, 2025
83b784f
add comment explaining the test_build_dir
Shourya742 Sep 22, 2025
aaa82ae
move config check logic from get_toml to parse_inner
Shourya742 Sep 22, 2025
079addf
Ensure that `--build-dir` is always specified in tests
Kobzol Sep 25, 2025
191c7ed
Make `cargo test` work again
Kobzol Sep 25, 2025
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
32 changes: 12 additions & 20 deletions src/bootstrap/src/core/builder/tests.rs
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@Kobzol Kobzol Sep 24, 2025

Choose a reason for hiding this comment

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

Yeah, the documentation needs a lot of updates. Shourya is actually gonna work on that next :)

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am currently working on this, separate from this PR, I hope to open a PR by next week.

Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,17 @@ fn prepare_rustc_checkout(ctx: &mut GitCtx) {

/// Parses a Config directory from `path`, with the given value of `download_rustc`.
fn parse_config_download_rustc_at(path: &Path, download_rustc: &str, ci: bool) -> Config {
Config::parse_inner(
Flags::parse(&[
"build".to_owned(),
"--dry-run".to_owned(),
"--ci".to_owned(),
if ci { "true" } else { "false" }.to_owned(),
format!("--set=rust.download-rustc='{download_rustc}'"),
"--src".to_owned(),
path.to_str().unwrap().to_owned(),
]),
|&_| Ok(Default::default()),
)
TestCtx::new()
.config("build")
.args(&[
"--ci",
if ci { "true" } else { "false" },
format!("--set=rust.download-rustc='{download_rustc}'").as_str(),
"--src",
path.to_str().unwrap(),
])
.no_override_download_ci_llvm()
.create_config()
}

mod dist {
Expand Down Expand Up @@ -359,14 +358,7 @@ fn test_test_coverage() {
#[test]
fn test_prebuilt_llvm_config_path_resolution() {
fn configure(config: &str) -> Config {
Config::parse_inner(
Flags::parse(&[
"build".to_string(),
"--dry-run".to_string(),
"--config=/does/not/exist".to_string(),
]),
|&_| toml::from_str(&config),
)
TestCtx::new().config("build").with_default_toml_config(config).create_config()
}

// Removes Windows disk prefix if present
Expand Down
36 changes: 22 additions & 14 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,19 +630,13 @@ impl Config {
let llvm_assertions = llvm_assertions.unwrap_or(false);
let mut target_config = HashMap::new();
let mut channel = "dev".to_string();
let out = flags_build_dir.or(build_build_dir.map(PathBuf::from)).unwrap_or_else(|| {
if cfg!(test) {
// Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
Path::new(
&env::var_os("CARGO_TARGET_DIR").expect("cargo test directly is not supported"),
)
.parent()
.unwrap()
.to_path_buf()
} else {
PathBuf::from("build")
}
});
let out = if cfg!(test) {
test_build_dir()
} else {
flags_build_dir
.or_else(|| build_build_dir.map(PathBuf::from))
.unwrap_or_else(|| PathBuf::from("build"))
};

// NOTE: Bootstrap spawns various commands with different working directories.
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
Expand Down Expand Up @@ -694,7 +688,9 @@ impl Config {

let initial_rustc = build_rustc.unwrap_or_else(|| {
download_beta_toolchain(&dwn_ctx, &out);
out.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
let target = if cfg!(test) { get_host_target() } else { host_target };

out.join(target).join("stage0").join("bin").join(exe("rustc", host_target))
});

let initial_sysroot = t!(PathBuf::from_str(
Expand Down Expand Up @@ -2484,3 +2480,15 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> {
})
.collect()
}

fn test_build_dir() -> PathBuf {
env::var_os("CARGO_TARGET_DIR")
.map(|value| Path::new(&value).parent().unwrap().to_path_buf())
.unwrap_or_else(|| {
let base = option_env!("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.unwrap_or_else(|| std::env::current_dir().expect("failed to get current dir"));

base.ancestors().nth(2).unwrap_or_else(|| Path::new(".")).join("build")
})
}
Loading
Loading