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");
46 eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]");
49 macro_rules! arg_error {
53 std::process::exit(1);
61 #[derive(Copy, Clone)]
69 env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
70 env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
71 // The target dir is expected in the default location. Guard against the user changing it.
72 env::set_var("CARGO_TARGET_DIR", "target");
74 let mut args = env::args().skip(1);
75 let command = match args.next().as_deref() {
77 if args.next().is_some() {
78 arg_error!("./x.rs prepare doesn't expect arguments");
83 Some("build") => Command::Build,
84 Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
85 Some(command) => arg_error!("Unknown command {}", command),
92 let mut target_dir = PathBuf::from("build");
93 let mut channel = "release";
94 let mut sysroot_kind = SysrootKind::Clif;
95 while let Some(arg) = args.next().as_deref() {
98 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
99 arg_error!("--target-dir requires argument");
102 "--debug" => channel = "debug",
104 sysroot_kind = match args.next().as_deref() {
105 Some("none") => SysrootKind::None,
106 Some("clif") => SysrootKind::Clif,
107 Some("llvm") => SysrootKind::Llvm,
108 Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
109 None => arg_error!("--sysroot requires argument"),
112 flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
113 arg => arg_error!("Unexpected argument {}", arg),
117 let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
119 } else if let Some(host_triple) = crate::config::get_value("host") {
122 rustc_info::get_host_triple()
124 let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
125 if target_triple != "" {
128 host_triple.clone() // Empty target triple can happen on GHA
130 } else if let Some(target_triple) = crate::config::get_value("target") {
136 if target_triple.ends_with("-msvc") {
137 eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
138 eprintln!("Switch to the MinGW toolchain for Windows support.");
139 eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
140 eprintln!("set the global default target to MinGW");
144 let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple);
145 build_sysroot::build_sysroot(