2021-07-07 04:14:20 -05:00
|
|
|
use std::env;
|
|
|
|
#[cfg(unix)]
|
|
|
|
use std::os::unix::process::CommandExt;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
|
|
|
|
|
2022-05-15 05:32:19 -05: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-05-15 05:32:19 -05: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-24 11:56:42 -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-15 05:32:19 -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-15 05:32:19 -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)]
|
|
|
|
Command::new("cargo").args(args).exec();
|
|
|
|
|
|
|
|
#[cfg(not(unix))]
|
|
|
|
std::process::exit(
|
|
|
|
Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
|
|
|
);
|
|
|
|
}
|