2 use std::path::PathBuf;
5 use self::utils::is_ci;
18 eprintln!(" ./y.rs prepare");
20 " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
23 " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
27 macro_rules! arg_error {
31 std::process::exit(1);
35 #[derive(PartialEq, Debug)]
41 #[derive(Copy, Clone, Debug)]
42 pub(crate) enum SysrootKind {
49 env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
50 env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
51 // The target dir is expected in the default location. Guard against the user changing it.
52 env::set_var("CARGO_TARGET_DIR", "target");
55 // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
56 env::set_var("CARGO_BUILD_INCREMENTAL", "false");
59 let mut args = env::args().skip(1);
60 let command = match args.next().as_deref() {
62 if args.next().is_some() {
63 arg_error!("./y.rs prepare doesn't expect arguments");
68 Some("build") => Command::Build,
69 Some("test") => Command::Test,
70 Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
71 Some(command) => arg_error!("Unknown command {}", command),
78 let mut target_dir = PathBuf::from("build");
79 let mut channel = "release";
80 let mut sysroot_kind = SysrootKind::Clif;
81 let mut use_unstable_features = true;
82 while let Some(arg) = args.next().as_deref() {
85 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
86 arg_error!("--target-dir requires argument");
89 "--debug" => channel = "debug",
91 sysroot_kind = match args.next().as_deref() {
92 Some("none") => SysrootKind::None,
93 Some("clif") => SysrootKind::Clif,
94 Some("llvm") => SysrootKind::Llvm,
95 Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
96 None => arg_error!("--sysroot requires argument"),
99 "--no-unstable-features" => use_unstable_features = false,
100 flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
101 arg => arg_error!("Unexpected argument {}", arg),
104 target_dir = std::env::current_dir().unwrap().join(target_dir);
106 let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
108 } else if let Some(host_triple) = config::get_value("host") {
111 rustc_info::get_host_triple()
113 let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
114 if target_triple != "" {
117 host_triple.clone() // Empty target triple can happen on GHA
119 } else if let Some(target_triple) = config::get_value("target") {
125 if target_triple.ends_with("-msvc") {
126 eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
127 eprintln!("Switch to the MinGW toolchain for Windows support.");
128 eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
129 eprintln!("set the global default target to MinGW");
133 let cg_clif_build_dir =
134 build_backend::build_backend(channel, &host_triple, use_unstable_features);
156 build_sysroot::build_sysroot(