2022-12-14 12:30:46 -06:00
|
|
|
use std::env;
|
|
|
|
use std::ffi::OsString;
|
|
|
|
#[cfg(unix)]
|
|
|
|
use std::os::unix::process::CommandExt;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
2023-03-15 09:41:48 -05: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();
|
|
|
|
}
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
let cg_clif_dylib_path = sysroot.join(if cfg!(windows) { "bin" } else { "lib" }).join(
|
|
|
|
env::consts::DLL_PREFIX.to_string() + "rustc_codegen_cranelift" + env::consts::DLL_SUFFIX,
|
|
|
|
);
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
let passed_args = std::env::args_os().skip(1).collect::<Vec<_>>();
|
|
|
|
let mut args = vec![];
|
2022-12-14 12:30:46 -06:00
|
|
|
args.push(OsString::from("-Cpanic=abort"));
|
|
|
|
args.push(OsString::from("-Zpanic-abort-tests"));
|
2023-06-15 12:56:01 -05:00
|
|
|
if let Some(name) = option_env!("BUILTIN_BACKEND") {
|
|
|
|
args.push(OsString::from(format!("-Zcodegen-backend={name}")))
|
|
|
|
} else {
|
|
|
|
let mut codegen_backend_arg = OsString::from("-Zcodegen-backend=");
|
|
|
|
codegen_backend_arg.push(cg_clif_dylib_path);
|
|
|
|
args.push(codegen_backend_arg);
|
|
|
|
}
|
|
|
|
if !passed_args.iter().any(|arg| {
|
|
|
|
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
|
|
|
|
}) {
|
2022-12-14 12:30:46 -06:00
|
|
|
args.push(OsString::from("--sysroot"));
|
|
|
|
args.push(OsString::from(sysroot.to_str().unwrap()));
|
|
|
|
}
|
2023-04-29 07:00:43 -05:00
|
|
|
args.extend(passed_args);
|
2022-12-14 12:30:46 -06:00
|
|
|
|
2023-06-15 12:56:01 -05:00
|
|
|
let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
|
|
|
|
rustdoc
|
|
|
|
} else {
|
|
|
|
// Ensure that the right toolchain is used
|
|
|
|
env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
|
|
|
|
"rustdoc"
|
|
|
|
};
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
#[cfg(unix)]
|
2023-06-15 12:56:01 -05:00
|
|
|
panic!("Failed to spawn rustdoc: {}", Command::new(rustdoc).args(args).exec());
|
2022-12-14 12:30:46 -06:00
|
|
|
|
|
|
|
#[cfg(not(unix))]
|
|
|
|
std::process::exit(
|
2023-06-15 12:56:01 -05:00
|
|
|
Command::new(rustdoc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
|
2022-12-14 12:30:46 -06:00
|
|
|
);
|
|
|
|
}
|