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 build/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/prepare.rs"]
36 #[path = "build_system/rustc_info.rs"]
38 #[path = "build_system/utils.rs"]
43 eprintln!(" ./y.rs prepare");
44 eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]");
47 macro_rules! arg_error {
51 std::process::exit(1);
59 #[derive(Copy, Clone)]
67 env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
68 env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
70 let mut args = env::args().skip(1);
71 let command = match args.next().as_deref() {
73 if args.next().is_some() {
74 arg_error!("./x.rs prepare doesn't expect arguments");
79 Some("build") => Command::Build,
80 Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
81 Some(command) => arg_error!("Unknown command {}", command),
88 let mut target_dir = PathBuf::from("build");
89 let mut channel = "release";
90 let mut sysroot_kind = SysrootKind::Clif;
91 while let Some(arg) = args.next().as_deref() {
94 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
95 arg_error!("--target-dir requires argument");
98 "--debug" => channel = "debug",
100 sysroot_kind = match args.next().as_deref() {
101 Some("none") => SysrootKind::None,
102 Some("clif") => SysrootKind::Clif,
103 Some("llvm") => SysrootKind::Llvm,
104 Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
105 None => arg_error!("--sysroot requires argument"),
108 flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
109 arg => arg_error!("Unexpected argument {}", arg),
113 let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
116 rustc_info::get_host_triple()
118 let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
119 if target_triple != "" {
122 host_triple.clone() // Empty target triple can happen on GHA
128 let cg_clif_dylib = build_backend::build_backend(channel);
129 build_sysroot::build_sysroot(