From f17dbfc933eaef12d3ae29ca500675328eaeb08e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:51:15 +0000 Subject: [PATCH] Add rustdoc-clif wrapper --- build_system/build_sysroot.rs | 2 +- scripts/rustdoc-clif.rs | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 scripts/rustdoc-clif.rs diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 856aecc49fd..ba606278df5 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -35,7 +35,7 @@ pub(crate) fn build_sysroot( try_hard_link(cg_clif_dylib_src, &cg_clif_dylib_path); // Build and copy rustc and cargo wrappers - for wrapper in ["rustc-clif", "cargo-clif"] { + for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] { let wrapper_name = get_wrapper_file_name(wrapper, "bin"); let mut build_cargo_wrapper_cmd = Command::new("rustc"); diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs new file mode 100644 index 00000000000..a19d72acfa8 --- /dev/null +++ b/scripts/rustdoc-clif.rs @@ -0,0 +1,36 @@ +use std::env; +use std::ffi::OsString; +#[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()); + + 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, + ); + + let mut args = std::env::args_os().skip(1).collect::>(); + args.push(OsString::from("-Cpanic=abort")); + args.push(OsString::from("-Zpanic-abort-tests")); + let mut codegen_backend_arg = OsString::from("-Zcodegen-backend="); + codegen_backend_arg.push(cg_clif_dylib_path); + args.push(codegen_backend_arg); + if !args.contains(&OsString::from("--sysroot")) { + args.push(OsString::from("--sysroot")); + args.push(OsString::from(sysroot.to_str().unwrap())); + } + + // Ensure that the right toolchain is used + env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN")); + + #[cfg(unix)] + Command::new("rustdoc").args(args).exec(); + + #[cfg(not(unix))] + std::process::exit( + Command::new("rustdoc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1), + ); +}