]> git.lizzy.rs Git - rust.git/blob - y.rs
Disable long running libcore tests
[rust.git] / y.rs
1 #!/usr/bin/env bash
2 #![allow()] /*This line is ignored by bash
3 # This block is ignored by rustc
4 set -e
5 echo "[BUILD] y.rs" 1>&2
6 rustc $0 -o ${0/.rs/.bin} -g
7 exec ${0/.rs/.bin} $@
8 */
9
10 //! The build system for cg_clif
11 //!
12 //! # Manual compilation
13 //!
14 //! If your system doesn't support shell scripts you can manually compile and run this file using
15 //! for example:
16 //!
17 //! ```shell
18 //! $ rustc y.rs -o y.bin
19 //! $ ./y.bin
20 //! ```
21 //!
22 //! # Naming
23 //!
24 //! The name `y.rs` was chosen to not conflict with rustc's `x.py`.
25
26 use std::env;
27 use std::path::PathBuf;
28 use std::process;
29
30 #[path = "build_system/build_backend.rs"]
31 mod build_backend;
32 #[path = "build_system/build_sysroot.rs"]
33 mod build_sysroot;
34 #[path = "build_system/config.rs"]
35 mod config;
36 #[path = "build_system/prepare.rs"]
37 mod prepare;
38 #[path = "build_system/rustc_info.rs"]
39 mod rustc_info;
40 #[path = "build_system/utils.rs"]
41 mod utils;
42
43 fn usage() {
44     eprintln!("Usage:");
45     eprintln!("  ./y.rs prepare");
46     eprintln!("  ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]");
47 }
48
49 macro_rules! arg_error {
50     ($($err:tt)*) => {{
51         eprintln!($($err)*);
52         usage();
53         std::process::exit(1);
54     }};
55 }
56
57 enum Command {
58     Build,
59 }
60
61 #[derive(Copy, Clone)]
62 enum SysrootKind {
63     None,
64     Clif,
65     Llvm,
66 }
67
68 fn main() {
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");
73
74     let mut args = env::args().skip(1);
75     let command = match args.next().as_deref() {
76         Some("prepare") => {
77             if args.next().is_some() {
78                 arg_error!("./x.rs prepare doesn't expect arguments");
79             }
80             prepare::prepare();
81             process::exit(0);
82         }
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),
86         None => {
87             usage();
88             process::exit(0);
89         }
90     };
91
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() {
96         match arg {
97             "--target-dir" => {
98                 target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
99                     arg_error!("--target-dir requires argument");
100                 }))
101             }
102             "--debug" => channel = "debug",
103             "--sysroot" => {
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"),
110                 }
111             }
112             flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
113             arg => arg_error!("Unexpected argument {}", arg),
114         }
115     }
116
117     let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
118         host_triple
119     } else if let Some(host_triple) = crate::config::get_value("host") {
120         host_triple
121     } else {
122         rustc_info::get_host_triple()
123     };
124     let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
125         if target_triple != "" {
126             target_triple
127         } else {
128             host_triple.clone() // Empty target triple can happen on GHA
129         }
130     } else if let Some(target_triple) = crate::config::get_value("target") {
131         target_triple
132     } else {
133         host_triple.clone()
134     };
135
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");
141         process::exit(1);
142     }
143
144     let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple);
145     build_sysroot::build_sysroot(
146         channel,
147         sysroot_kind,
148         &target_dir,
149         cg_clif_build_dir,
150         &host_triple,
151         &target_triple,
152     );
153 }