Skip to content

Commit 55a3cdb

Browse files
Add new --with-llvm-sysroot option for test commands
1 parent 2818318 commit 55a3cdb

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

build_system/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
227227
}
228228
run_command_with_output_and_env(&command, None, Some(&env))?;
229229

230-
args.config_info.setup(&mut env, false)?;
230+
args.config_info.setup(&mut env, false, false)?;
231231

232232
// We voluntarily ignore the error.
233233
let _ = fs::remove_dir_all("target/out");

build_system/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ impl ConfigInfo {
314314
&mut self,
315315
env: &mut HashMap<String, String>,
316316
use_system_gcc: bool,
317+
with_llvm_sysroot: bool,
317318
) -> Result<(), String> {
318319
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
319320

@@ -392,7 +393,7 @@ impl ConfigInfo {
392393
// This option is only used in the rust compiler testsuite. The sysroot is handled
393394
// by its build system directly so no need to set it ourselves.
394395
rustflags.push(format!("-Zcodegen-backend={backend}"));
395-
} else {
396+
} else if !with_llvm_sysroot {
396397
rustflags.extend_from_slice(&[
397398
"--sysroot".to_string(),
398399
self.sysroot_path.clone(),

build_system/src/rust_tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl RustcTools {
7272

7373
let mut env: HashMap<String, String> = std::env::vars().collect();
7474
let mut config = ConfigInfo::default();
75-
config.setup(&mut env, false)?;
75+
config.setup(&mut env, false, false)?;
7676
let toolchain = get_toolchain()?;
7777

7878
let toolchain_version = rustc_toolchain_version_info(&toolchain)?;

build_system/src/test.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ fn show_usage() {
6868
--use-system-gcc : Use system installed libgccjit
6969
--build-only : Only build rustc_codegen_gcc then exits
7070
--nb-parts : Used to split rustc_tests (for CI needs)
71-
--current-part : Used with `--nb-parts`, allows you to specify which parts to test"#
71+
--current-part : Used with `--nb-parts`, allows you to specify which parts to test
72+
--with-llvm-sysroot : Use the LLVM sysroot instead of the GCC one"#
7273
);
7374
ConfigInfo::show_usage();
7475
for (option, (doc, _)) in get_runners() {
@@ -93,6 +94,7 @@ struct TestArg {
9394
config_info: ConfigInfo,
9495
sysroot_features: Vec<String>,
9596
keep_lto_tests: bool,
97+
with_llvm_sysroot: bool,
9698
}
9799

98100
impl TestArg {
@@ -136,6 +138,9 @@ impl TestArg {
136138
return Err(format!("Expected an argument after `{arg}`, found nothing"));
137139
}
138140
},
141+
"--with-llvm-sysroot" => {
142+
test_arg.with_llvm_sysroot = true;
143+
}
139144
"--help" => {
140145
show_usage();
141146
return Ok(None);
@@ -559,9 +564,14 @@ fn asm_tests(env: &Env, args: &TestArg) -> Result<(), String> {
559564
let extra =
560565
if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
561566

567+
let sysroot_arg = if args.with_llvm_sysroot {
568+
String::new()
569+
} else {
570+
format!(" --sysroot {}", args.config_info.sysroot_path)
571+
};
572+
562573
let rustc_args = format!(
563-
"-Zpanic-abort-tests -Zcodegen-backend={codegen_backend_path} --sysroot {} -Cpanic=abort{extra}",
564-
args.config_info.sysroot_path
574+
"-Zpanic-abort-tests -Zcodegen-backend={codegen_backend_path}{sysroot_arg} -Cpanic=abort{extra}",
565575
);
566576

567577
run_command_with_env(
@@ -1028,11 +1038,16 @@ where
10281038
let extra =
10291039
if args.is_using_gcc_master_branch() { "" } else { " -Csymbol-mangling-version=v0" };
10301040

1041+
let sysroot_arg = if args.with_llvm_sysroot {
1042+
String::new()
1043+
} else {
1044+
format!(" --sysroot {}", args.config_info.sysroot_path)
1045+
};
1046+
10311047
let rustc_args = format!(
1032-
"{test_flags} -Zcodegen-backend={backend} --sysroot {sysroot}{extra}",
1048+
"{test_flags} -Zcodegen-backend={backend}{sysroot_arg}{extra}",
10331049
test_flags = env.get("TEST_FLAGS").unwrap_or(&String::new()),
10341050
backend = args.config_info.cg_backend_path,
1035-
sysroot = args.config_info.sysroot_path,
10361051
extra = extra,
10371052
);
10381053

@@ -1270,7 +1285,7 @@ pub fn run() -> Result<(), String> {
12701285
return Ok(());
12711286
}
12721287

1273-
args.config_info.setup(&mut env, args.use_system_gcc)?;
1288+
args.config_info.setup(&mut env, args.use_system_gcc, args.with_llvm_sysroot)?;
12741289

12751290
if args.runners.is_empty() {
12761291
run_all(&env, &args)?;

0 commit comments

Comments
 (0)