2 use std::path::PathBuf;
14 eprintln!(" ./y.rs prepare");
16 " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
20 macro_rules! arg_error {
24 std::process::exit(1);
32 #[derive(Copy, Clone)]
33 pub(crate) enum SysrootKind {
40 env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
41 env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
42 // The target dir is expected in the default location. Guard against the user changing it.
43 env::set_var("CARGO_TARGET_DIR", "target");
45 let mut args = env::args().skip(1);
46 let command = match args.next().as_deref() {
48 if args.next().is_some() {
49 arg_error!("./x.rs prepare doesn't expect arguments");
54 Some("build") => Command::Build,
55 Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
56 Some(command) => arg_error!("Unknown command {}", command),
63 let mut target_dir = PathBuf::from("build");
64 let mut channel = "release";
65 let mut sysroot_kind = SysrootKind::Clif;
66 let mut use_unstable_features = true;
67 while let Some(arg) = args.next().as_deref() {
70 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
71 arg_error!("--target-dir requires argument");
74 "--debug" => channel = "debug",
76 sysroot_kind = match args.next().as_deref() {
77 Some("none") => SysrootKind::None,
78 Some("clif") => SysrootKind::Clif,
79 Some("llvm") => SysrootKind::Llvm,
80 Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
81 None => arg_error!("--sysroot requires argument"),
84 "--no-unstable-features" => use_unstable_features = false,
85 flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
86 arg => arg_error!("Unexpected argument {}", arg),
90 let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
92 } else if let Some(host_triple) = config::get_value("host") {
95 rustc_info::get_host_triple()
97 let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
98 if target_triple != "" {
101 host_triple.clone() // Empty target triple can happen on GHA
103 } else if let Some(target_triple) = config::get_value("target") {
109 if target_triple.ends_with("-msvc") {
110 eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
111 eprintln!("Switch to the MinGW toolchain for Windows support.");
112 eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
113 eprintln!("set the global default target to MinGW");
117 let cg_clif_build_dir =
118 build_backend::build_backend(channel, &host_triple, use_unstable_features);
119 build_sysroot::build_sysroot(