2 use std
::path
::PathBuf
;
5 use self::utils
::{is_ci, is_ci_opt, Compiler}
;
19 eprintln
!("{}", include_str
!("usage.txt"));
22 macro_rules
! arg_error
{
26 std
::process
::exit(1);
30 #[derive(PartialEq, Debug)]
39 #[derive(Copy, Clone, Debug)]
40 pub(crate) enum SysrootKind
{
47 if env
::var("RUST_BACKTRACE").is_err() {
48 env
::set_var("RUST_BACKTRACE", "1");
50 env
::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
53 // Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
54 env
::set_var("CARGO_BUILD_INCREMENTAL", "false");
57 // Enable the Cranelift verifier
58 env
::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
62 let mut args
= env
::args().skip(1);
63 let command
= match args
.next().as_deref() {
64 Some("prepare") => Command
::Prepare
,
65 Some("build") => Command
::Build
,
66 Some("test") => Command
::Test
,
67 Some("abi-cafe") => Command
::AbiCafe
,
68 Some("bench") => Command
::Bench
,
69 Some(flag
) if flag
.starts_with('
-'
) => arg_error
!("Expected command found flag {}", flag
),
70 Some(command
) => arg_error
!("Unknown command {}", command
),
77 let mut out_dir
= PathBuf
::from(".");
78 let mut channel
= "release";
79 let mut sysroot_kind
= SysrootKind
::Clif
;
80 let mut use_unstable_features
= true;
81 while let Some(arg
) = args
.next().as_deref() {
84 out_dir
= PathBuf
::from(args
.next().unwrap_or_else(|| {
85 arg_error
!("--out-dir requires argument");
88 "--debug" => channel
= "debug",
90 sysroot_kind
= match args
.next().as_deref() {
91 Some("none") => SysrootKind
::None
,
92 Some("clif") => SysrootKind
::Clif
,
93 Some("llvm") => SysrootKind
::Llvm
,
94 Some(arg
) => arg_error
!("Unknown sysroot kind {}", arg
),
95 None
=> arg_error
!("--sysroot requires argument"),
98 "--no-unstable-features" => use_unstable_features
= false,
99 flag
if flag
.starts_with("-") => arg_error
!("Unknown flag {}", flag
),
100 arg
=> arg_error
!("Unexpected argument {}", arg
),
104 let bootstrap_host_compiler
= Compiler
::bootstrap_with_triple(
105 std
::env
::var("HOST_TRIPLE")
107 .or_else(|| config
::get_value("host"))
108 .unwrap_or_else(|| rustc_info
::get_host_triple()),
110 let target_triple
= std
::env
::var("TARGET_TRIPLE")
112 .or_else(|| config
::get_value("target"))
113 .unwrap_or_else(|| bootstrap_host_compiler
.triple
.clone());
115 // FIXME allow changing the location of these dirs using cli arguments
116 let current_dir
= std
::env
::current_dir().unwrap();
117 out_dir
= current_dir
.join(out_dir
);
118 let dirs
= path
::Dirs
{
119 source_dir
: current_dir
.clone(),
120 download_dir
: out_dir
.join("download"),
121 build_dir
: out_dir
.join("build"),
122 dist_dir
: out_dir
.join("dist"),
125 path
::RelPath
::BUILD
.ensure_exists(&dirs
);
128 // Make sure we always explicitly specify the target dir
130 path
::RelPath
::BUILD
.join("target_dir_should_be_set_explicitly").to_path(&dirs
);
131 env
::set_var("CARGO_TARGET_DIR", &target
);
132 let _
= std
::fs
::remove_file(&target
);
133 std
::fs
::File
::create(target
).unwrap();
136 if command
== Command
::Prepare
{
137 prepare
::prepare(&dirs
);
141 env
::set_var("RUSTC", "rustc_should_be_set_explicitly");
142 env
::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
144 let cg_clif_dylib
= build_backend
::build_backend(
147 &bootstrap_host_compiler
,
148 use_unstable_features
,
151 Command
::Prepare
=> {
160 &bootstrap_host_compiler
,
161 target_triple
.clone(),
164 Command
::AbiCafe
=> {
165 if bootstrap_host_compiler
.triple
!= target_triple
{
166 eprintln
!("Abi-cafe doesn't support cross-compilation");
169 abi_cafe
::run(channel
, sysroot_kind
, &dirs
, &cg_clif_dylib
, &bootstrap_host_compiler
);
172 build_sysroot
::build_sysroot(
177 &bootstrap_host_compiler
,
182 build_sysroot
::build_sysroot(
187 &bootstrap_host_compiler
,
190 bench
::benchmark(&dirs
, &bootstrap_host_compiler
);