]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_cranelift/scripts/cargo-clif.rs
Rollup merge of #104450 - andrewpollack:fix-fuchsia-compiler-docs, r=tmandry
[rust.git] / compiler / rustc_codegen_cranelift / scripts / cargo-clif.rs
1 use std::env;
2 #[cfg(unix)]
3 use std::os::unix::process::CommandExt;
4 use std::path::PathBuf;
5 use std::process::Command;
6
7 fn main() {
8     let sysroot = PathBuf::from(env::current_exe().unwrap().parent().unwrap());
9
10     let mut rustflags = String::new();
11     rustflags.push_str(" -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=");
12     rustflags.push_str(
13         sysroot
14             .join(if cfg!(windows) { "bin" } else { "lib" })
15             .join(
16                 env::consts::DLL_PREFIX.to_string()
17                     + "rustc_codegen_cranelift"
18                     + env::consts::DLL_SUFFIX,
19             )
20             .to_str()
21             .unwrap(),
22     );
23     rustflags.push_str(" --sysroot ");
24     rustflags.push_str(sysroot.to_str().unwrap());
25     env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
26     env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
27
28     // Ensure that the right toolchain is used
29     env::set_var("RUSTUP_TOOLCHAIN", env!("RUSTUP_TOOLCHAIN"));
30
31     let args: Vec<_> = match env::args().nth(1).as_deref() {
32         Some("jit") => {
33             env::set_var(
34                 "RUSTFLAGS",
35                 env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
36             );
37             IntoIterator::into_iter(["rustc".to_string()])
38                 .chain(env::args().skip(2))
39                 .chain([
40                     "--".to_string(),
41                     "-Zunstable-options".to_string(),
42                     "-Cllvm-args=mode=jit".to_string(),
43                 ])
44                 .collect()
45         }
46         Some("lazy-jit") => {
47             env::set_var(
48                 "RUSTFLAGS",
49                 env::var("RUSTFLAGS").unwrap_or(String::new()) + " -Cprefer-dynamic",
50             );
51             IntoIterator::into_iter(["rustc".to_string()])
52                 .chain(env::args().skip(2))
53                 .chain([
54                     "--".to_string(),
55                     "-Zunstable-options".to_string(),
56                     "-Cllvm-args=mode=jit-lazy".to_string(),
57                 ])
58                 .collect()
59         }
60         _ => env::args().skip(1).collect(),
61     };
62
63     #[cfg(unix)]
64     Command::new("cargo").args(args).exec();
65
66     #[cfg(not(unix))]
67     std::process::exit(
68         Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
69     );
70 }