2 #![allow()] /*This line is ignored by bash
3 # This block is ignored by rustc
5 echo "[BUILD] y.rs" 1>&2
6 rustc $0 -o ${0/.rs/.bin} -g
10 //! The build system for cg_clif
12 //! # Manual compilation
14 //! If your system doesn't support shell scripts you can manually compile and run this file using
18 //! $ rustc y.rs -o y.bin
24 //! The name `y.rs` was chosen to not conflict with rustc's `x.py`.
27 use std::path::PathBuf;
30 #[path = "build_system/build_backend.rs"]
32 #[path = "build_system/build_sysroot.rs"]
34 #[path = "build_system/config.rs"]
36 #[path = "build_system/prepare.rs"]
38 #[path = "build_system/rustc_info.rs"]
40 #[path = "build_system/utils.rs"]
45 eprintln!(" ./y.rs prepare");
47 " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
51 macro_rules! arg_error {
55 std::process::exit(1);
63 #[derive(Copy, Clone)]
71 env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
72 env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
73 // The target dir is expected in the default location. Guard against the user changing it.
74 env::set_var("CARGO_TARGET_DIR", "target");
76 let mut args = env::args().skip(1);
77 let command = match args.next().as_deref() {
79 if args.next().is_some() {
80 arg_error!("./x.rs prepare doesn't expect arguments");
85 Some("build") => Command::Build,
86 Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
87 Some(command) => arg_error!("Unknown command {}", command),
94 let mut target_dir = PathBuf::from("build");
95 let mut channel = "release";
96 let mut sysroot_kind = SysrootKind::Clif;
97 let mut use_unstable_features = true;
98 while let Some(arg) = args.next().as_deref() {
101 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
102 arg_error!("--target-dir requires argument");
105 "--debug" => channel = "debug",
107 sysroot_kind = match args.next().as_deref() {
108 Some("none") => SysrootKind::None,
109 Some("clif") => SysrootKind::Clif,
110 Some("llvm") => SysrootKind::Llvm,
111 Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
112 None => arg_error!("--sysroot requires argument"),
115 "--no-unstable-features" => use_unstable_features = false,
116 flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
117 arg => arg_error!("Unexpected argument {}", arg),
121 let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
123 } else if let Some(host_triple) = crate::config::get_value("host") {
126 rustc_info::get_host_triple()
128 let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
129 if target_triple != "" {
132 host_triple.clone() // Empty target triple can happen on GHA
134 } else if let Some(target_triple) = crate::config::get_value("target") {
140 if target_triple.ends_with("-msvc") {
141 eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
142 eprintln!("Switch to the MinGW toolchain for Windows support.");
143 eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
144 eprintln!("set the global default target to MinGW");
148 let cg_clif_build_dir =
149 build_backend::build_backend(channel, &host_triple, use_unstable_features);
150 build_sysroot::build_sysroot(