2021-07-07 04:14:20 -05:00
|
|
|
use std::env;
|
|
|
|
#[cfg(unix)]
|
|
|
|
use std::os::unix::process::CommandExt;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
2023-02-19 09:28:01 -06:00
|
|
|
let current_exe = env::current_exe().unwrap();
|
|
|
|
let mut sysroot = current_exe.parent().unwrap();
|
|
|
|
if sysroot.file_name().unwrap().to_str().unwrap() == "bin" {
|
|
|
|
sysroot = sysroot.parent().unwrap();
|
|
|
|
}
|
2021-07-07 04:14:20 -05:00
|
|
|
|
2022-02-13 12:31:49 -06:00
|
|
|
let mut rustflags = String::new();
|
|
|
|
rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
|
|
|
|
rustflags.push_str(
|
2021-07-07 04:14:20 -05:00
|
|
|
sysroot
|
|
|
|
.join(if cfg!(windows) { "bin" } else { "lib" })
|
|
|
|
.join(
|
|
|
|
env::consts::DLL_PREFIX.to_string()
|
|
|
|
+ "rustc_codegen_cranelift"
|
|
|
|
+ env::consts::DLL_SUFFIX,
|
|
|
|
)
|
|
|
|
.to_str()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
2022-02-13 12:31:49 -06:00
|
|
|
rustflags.push_str(" --sysroot ");
|
|
|
|
rustflags.push_str(sysroot.to_str().unwrap());
|
|
|
|
env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
|
|
|
|
env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
|
2021-07-07 04:14:20 -05:00
|
|
|
|
|
|
|
// Ensure that the right toolchain is used
|
2023-01-14 08:08:23 -06:00
|
|
|
env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
|
2021-07-07 04:14:20 -05:00
|
|
|
|
|
|
|
let args: Vec<_> = match env::args().nth(1).as_deref() {
|
|
|
|
Some("jit") => {
|
|
|
|
env::set_var(
|
|
|
|
"RUSTFLAGS",
|
|
|
|
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
|
|
|
|
);
|
2021-09-03 05:36:33 -05:00
|
|
|
IntoIterator::into_iter(["rustc".to_string()])
|
2021-07-07 04:14:20 -05:00
|
|
|
.chain(env::args().skip(2))
|
2021-08-06 09:26:56 -05:00
|
|
|
.chain([
|
|
|
|
"--".to_string(),
|
2022-05-01 08:54:12 -05:00
|
|
|
"-Zunstable-options".to_string(),
|
2021-08-06 09:26:56 -05:00
|
|
|
"-Cllvm-args=mode=jit".to_string(),
|
|
|
|
])
|
2021-07-07 04:14:20 -05:00
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
Some("lazy-jit") => {
|
|
|
|
env::set_var(
|
|
|
|
"RUSTFLAGS",
|
|
|
|
env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
|
|
|
|
);
|
2021-09-03 05:36:33 -05:00
|
|
|
IntoIterator::into_iter(["rustc".to_string()])
|
2021-07-07 04:14:20 -05:00
|
|
|
.chain(env::args().skip(2))
|
2021-08-06 09:26:56 -05:00
|
|
|
.chain([
|
|
|
|
"--".to_string(),
|
2022-05-01 08:54:12 -05:00
|
|
|
"-Zunstable-options".to_string(),
|
2021-08-06 09:26:56 -05:00
|
|
|
"-Cllvm-args=mode=jit-lazy".to_string(),
|
|
|
|
])
|
2021-07-07 04:14:20 -05:00
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
_ => env::args().skip(1).collect(),
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(unix)]
|
2023-03-21 08:41:28 -05:00
|
|
|
panic!("Failed to spawn cargo: {}", Command::new("cargo").args(args).exec());
|
2021-07-07 04:14:20 -05:00
|
|
|
|
|
|
|
#[cfg(not(unix))]
|
|
|
|
std::process::exit(
|
|
|
|
Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
|
|
|
);
|
|
|
|
}
|