2023-02-15 12:23:11 -06:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
#![warn(unused_lifetimes)]
|
|
|
|
#![warn(unreachable_pub)]
|
|
|
|
|
2022-01-09 12:30:07 -06:00
|
|
|
use std::env;
|
2023-02-10 04:03:42 -06:00
|
|
|
use std::path::PathBuf;
|
2022-01-09 12:30:07 -06:00
|
|
|
use std::process;
|
|
|
|
|
2023-02-04 04:22:24 -06:00
|
|
|
use self::utils::{is_ci, is_ci_opt, Compiler};
|
2022-08-05 07:57:19 -05:00
|
|
|
|
2022-09-26 06:56:18 -05:00
|
|
|
mod abi_cafe;
|
2023-01-05 11:57:35 -06:00
|
|
|
mod bench;
|
2022-01-09 12:30:07 -06:00
|
|
|
mod build_backend;
|
|
|
|
mod build_sysroot;
|
|
|
|
mod config;
|
2022-12-01 07:30:03 -06:00
|
|
|
mod path;
|
2022-01-09 12:30:07 -06:00
|
|
|
mod prepare;
|
|
|
|
mod rustc_info;
|
2023-08-02 04:06:29 -05:00
|
|
|
mod shared_utils;
|
2022-07-30 04:32:54 -05:00
|
|
|
mod tests;
|
2022-07-31 05:15:56 -05:00
|
|
|
mod utils;
|
2022-01-09 12:30:07 -06:00
|
|
|
|
|
|
|
fn usage() {
|
2023-01-13 10:34:43 -06:00
|
|
|
eprintln!("{}", include_str!("usage.txt"));
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! arg_error {
|
|
|
|
($($err:tt)*) => {{
|
|
|
|
eprintln!($($err)*);
|
|
|
|
usage();
|
|
|
|
std::process::exit(1);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2022-07-30 04:32:54 -05:00
|
|
|
#[derive(PartialEq, Debug)]
|
2022-01-09 12:30:07 -06:00
|
|
|
enum Command {
|
2022-12-01 11:42:29 -06:00
|
|
|
Prepare,
|
2022-01-09 12:30:07 -06:00
|
|
|
Build,
|
2022-07-30 04:32:54 -05:00
|
|
|
Test,
|
2023-01-16 05:21:37 -06:00
|
|
|
AbiCafe,
|
2023-01-05 11:57:35 -06:00
|
|
|
Bench,
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|
|
|
|
|
2022-07-30 04:32:54 -05:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2023-02-15 12:23:11 -06:00
|
|
|
enum SysrootKind {
|
2022-01-09 12:30:07 -06:00
|
|
|
None,
|
|
|
|
Clif,
|
|
|
|
Llvm,
|
|
|
|
}
|
|
|
|
|
2023-02-15 13:32:58 -06:00
|
|
|
#[derive(Clone, Debug)]
|
2023-02-15 12:23:11 -06:00
|
|
|
enum CodegenBackend {
|
2023-02-15 13:32:58 -06:00
|
|
|
Local(PathBuf),
|
|
|
|
Builtin(String),
|
|
|
|
}
|
|
|
|
|
2023-02-15 12:23:11 -06:00
|
|
|
fn main() {
|
2023-10-06 07:51:30 -05:00
|
|
|
if env::var_os("RUST_BACKTRACE").is_none() {
|
2022-12-15 08:12:46 -06:00
|
|
|
env::set_var("RUST_BACKTRACE", "1");
|
|
|
|
}
|
2022-01-09 12:30:07 -06:00
|
|
|
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
|
2022-11-28 09:15:40 -06:00
|
|
|
|
2022-08-05 07:57:19 -05:00
|
|
|
if is_ci() {
|
|
|
|
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
|
|
|
|
env::set_var("CARGO_BUILD_INCREMENTAL", "false");
|
2022-12-15 08:12:46 -06:00
|
|
|
|
2023-02-04 04:22:24 -06:00
|
|
|
if !is_ci_opt() {
|
|
|
|
// Enable the Cranelift verifier
|
|
|
|
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
|
|
|
|
}
|
2022-08-05 07:57:19 -05:00
|
|
|
}
|
|
|
|
|
2022-01-09 12:30:07 -06:00
|
|
|
let mut args = env::args().skip(1);
|
|
|
|
let command = match args.next().as_deref() {
|
2022-12-01 11:42:29 -06:00
|
|
|
Some("prepare") => Command::Prepare,
|
2022-01-09 12:30:07 -06:00
|
|
|
Some("build") => Command::Build,
|
2022-07-30 04:32:54 -05:00
|
|
|
Some("test") => Command::Test,
|
2023-01-16 05:21:37 -06:00
|
|
|
Some("abi-cafe") => Command::AbiCafe,
|
2023-01-05 11:57:35 -06:00
|
|
|
Some("bench") => Command::Bench,
|
2022-01-09 12:30:07 -06:00
|
|
|
Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
|
|
|
|
Some(command) => arg_error!("Unknown command {}", command),
|
|
|
|
None => {
|
|
|
|
usage();
|
|
|
|
process::exit(0);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-01 11:42:29 -06:00
|
|
|
let mut out_dir = PathBuf::from(".");
|
2023-02-13 04:38:25 -06:00
|
|
|
let mut download_dir = None;
|
2022-01-09 12:30:07 -06:00
|
|
|
let mut channel = "release";
|
|
|
|
let mut sysroot_kind = SysrootKind::Clif;
|
|
|
|
let mut use_unstable_features = true;
|
2023-02-12 08:16:48 -06:00
|
|
|
let mut frozen = false;
|
2023-06-05 10:15:48 -05:00
|
|
|
let mut skip_tests = vec![];
|
2023-02-15 13:32:58 -06:00
|
|
|
let mut use_backend = None;
|
2022-01-09 12:30:07 -06:00
|
|
|
while let Some(arg) = args.next().as_deref() {
|
|
|
|
match arg {
|
2022-12-01 11:42:29 -06:00
|
|
|
"--out-dir" => {
|
|
|
|
out_dir = PathBuf::from(args.next().unwrap_or_else(|| {
|
|
|
|
arg_error!("--out-dir requires argument");
|
2023-02-13 04:38:25 -06:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
"--download-dir" => {
|
|
|
|
download_dir = Some(PathBuf::from(args.next().unwrap_or_else(|| {
|
|
|
|
arg_error!("--download-dir requires argument");
|
|
|
|
})));
|
2022-12-01 11:42:29 -06:00
|
|
|
}
|
2022-01-09 12:30:07 -06:00
|
|
|
"--debug" => channel = "debug",
|
|
|
|
"--sysroot" => {
|
|
|
|
sysroot_kind = match args.next().as_deref() {
|
|
|
|
Some("none") => SysrootKind::None,
|
|
|
|
Some("clif") => SysrootKind::Clif,
|
|
|
|
Some("llvm") => SysrootKind::Llvm,
|
|
|
|
Some(arg) => arg_error!("Unknown sysroot kind {}", arg),
|
|
|
|
None => arg_error!("--sysroot requires argument"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"--no-unstable-features" => use_unstable_features = false,
|
2023-02-12 08:16:48 -06:00
|
|
|
"--frozen" => frozen = true,
|
2023-06-05 10:15:48 -05:00
|
|
|
"--skip-test" => {
|
|
|
|
// FIXME check that all passed in tests actually exist
|
|
|
|
skip_tests.push(args.next().unwrap_or_else(|| {
|
|
|
|
arg_error!("--skip-test requires argument");
|
|
|
|
}));
|
|
|
|
}
|
2023-02-15 13:32:58 -06:00
|
|
|
"--use-backend" => {
|
|
|
|
use_backend = Some(match args.next() {
|
|
|
|
Some(name) => name,
|
|
|
|
None => arg_error!("--use-backend requires argument"),
|
|
|
|
});
|
|
|
|
}
|
2022-01-09 12:30:07 -06:00
|
|
|
flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
|
|
|
|
arg => arg_error!("Unexpected argument {}", arg),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 10:41:43 -05:00
|
|
|
let current_dir = std::env::current_dir().unwrap();
|
|
|
|
out_dir = current_dir.join(out_dir);
|
|
|
|
|
|
|
|
if command == Command::Prepare {
|
|
|
|
prepare::prepare(&path::Dirs {
|
|
|
|
source_dir: current_dir.clone(),
|
|
|
|
download_dir: download_dir
|
|
|
|
.map(|dir| current_dir.join(dir))
|
|
|
|
.unwrap_or_else(|| out_dir.join("download")),
|
|
|
|
build_dir: PathBuf::from("dummy_do_not_use"),
|
|
|
|
dist_dir: PathBuf::from("dummy_do_not_use"),
|
|
|
|
frozen,
|
|
|
|
});
|
|
|
|
process::exit(0);
|
|
|
|
}
|
|
|
|
|
2023-02-13 04:11:45 -06:00
|
|
|
let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
|
|
|
|
(Ok(_), Ok(_), Ok(_)) => None,
|
|
|
|
(Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
|
|
|
|
_ => {
|
|
|
|
eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
2023-02-10 04:03:42 -06:00
|
|
|
let bootstrap_host_compiler = {
|
|
|
|
let cargo = rustc_info::get_cargo_path();
|
|
|
|
let rustc = rustc_info::get_rustc_path();
|
|
|
|
let rustdoc = rustc_info::get_rustdoc_path();
|
|
|
|
let triple = std::env::var("HOST_TRIPLE")
|
2023-01-13 06:16:11 -06:00
|
|
|
.ok()
|
|
|
|
.or_else(|| config::get_value("host"))
|
2023-02-10 04:03:42 -06:00
|
|
|
.unwrap_or_else(|| rustc_info::get_host_triple(&rustc));
|
|
|
|
Compiler {
|
|
|
|
cargo,
|
|
|
|
rustc,
|
|
|
|
rustdoc,
|
2023-08-02 04:06:29 -05:00
|
|
|
rustflags: vec![],
|
|
|
|
rustdocflags: vec![],
|
2023-02-10 04:03:42 -06:00
|
|
|
triple,
|
|
|
|
runner: vec![],
|
|
|
|
}
|
|
|
|
};
|
2023-01-13 06:16:11 -06:00
|
|
|
let target_triple = std::env::var("TARGET_TRIPLE")
|
|
|
|
.ok()
|
|
|
|
.or_else(|| config::get_value("target"))
|
2023-01-14 06:53:33 -06:00
|
|
|
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
|
2022-07-30 17:04:59 -05:00
|
|
|
|
2022-12-01 11:42:29 -06:00
|
|
|
let dirs = path::Dirs {
|
|
|
|
source_dir: current_dir.clone(),
|
2023-02-13 04:38:25 -06:00
|
|
|
download_dir: download_dir
|
|
|
|
.map(|dir| current_dir.join(dir))
|
|
|
|
.unwrap_or_else(|| out_dir.join("download")),
|
2022-12-01 11:42:29 -06:00
|
|
|
build_dir: out_dir.join("build"),
|
|
|
|
dist_dir: out_dir.join("dist"),
|
2023-02-12 08:16:48 -06:00
|
|
|
frozen,
|
2022-12-01 11:42:29 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
path::RelPath::BUILD.ensure_exists(&dirs);
|
|
|
|
|
|
|
|
{
|
|
|
|
// Make sure we always explicitly specify the target dir
|
|
|
|
let target =
|
|
|
|
path::RelPath::BUILD.join("target_dir_should_be_set_explicitly").to_path(&dirs);
|
|
|
|
env::set_var("CARGO_TARGET_DIR", &target);
|
|
|
|
let _ = std::fs::remove_file(&target);
|
|
|
|
std::fs::File::create(target).unwrap();
|
|
|
|
}
|
|
|
|
|
2023-01-14 06:41:07 -06:00
|
|
|
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
|
|
|
|
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
|
|
|
|
|
2023-02-15 13:32:58 -06:00
|
|
|
let cg_clif_dylib = if let Some(name) = use_backend {
|
|
|
|
CodegenBackend::Builtin(name)
|
|
|
|
} else {
|
|
|
|
CodegenBackend::Local(build_backend::build_backend(
|
|
|
|
&dirs,
|
|
|
|
channel,
|
|
|
|
&bootstrap_host_compiler,
|
|
|
|
use_unstable_features,
|
|
|
|
))
|
|
|
|
};
|
2022-07-30 06:50:05 -05:00
|
|
|
match command {
|
2022-12-01 11:42:29 -06:00
|
|
|
Command::Prepare => {
|
|
|
|
// Handled above
|
|
|
|
}
|
2022-07-30 06:50:05 -05:00
|
|
|
Command::Test => {
|
2022-12-01 08:54:37 -06:00
|
|
|
tests::run_tests(
|
|
|
|
&dirs,
|
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2023-02-12 08:01:32 -06:00
|
|
|
use_unstable_features,
|
2023-06-05 10:15:48 -05:00
|
|
|
&skip_tests.iter().map(|test| &**test).collect::<Vec<_>>(),
|
2022-12-01 08:54:37 -06:00
|
|
|
&cg_clif_dylib,
|
2023-01-14 06:53:33 -06:00
|
|
|
&bootstrap_host_compiler,
|
2023-02-13 04:11:45 -06:00
|
|
|
rustup_toolchain_name.as_deref(),
|
2023-01-14 07:04:40 -06:00
|
|
|
target_triple.clone(),
|
2022-12-01 08:54:37 -06:00
|
|
|
);
|
2023-01-16 05:21:37 -06:00
|
|
|
}
|
|
|
|
Command::AbiCafe => {
|
|
|
|
if bootstrap_host_compiler.triple != target_triple {
|
|
|
|
eprintln!("Abi-cafe doesn't support cross-compilation");
|
|
|
|
process::exit(1);
|
2023-01-13 06:16:11 -06:00
|
|
|
}
|
2023-02-13 04:11:45 -06:00
|
|
|
abi_cafe::run(
|
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&dirs,
|
|
|
|
&cg_clif_dylib,
|
|
|
|
rustup_toolchain_name.as_deref(),
|
|
|
|
&bootstrap_host_compiler,
|
|
|
|
);
|
2022-07-30 06:50:05 -05:00
|
|
|
}
|
2022-08-06 15:24:38 -05:00
|
|
|
Command::Build => {
|
|
|
|
build_sysroot::build_sysroot(
|
2022-12-01 08:54:37 -06:00
|
|
|
&dirs,
|
2022-08-06 07:34:55 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-08-28 11:46:09 -05:00
|
|
|
&cg_clif_dylib,
|
2023-01-14 06:53:33 -06:00
|
|
|
&bootstrap_host_compiler,
|
2023-02-13 04:11:45 -06:00
|
|
|
rustup_toolchain_name.as_deref(),
|
2023-01-14 07:04:40 -06:00
|
|
|
target_triple,
|
2022-08-06 07:34:55 -05:00
|
|
|
);
|
|
|
|
}
|
2023-01-05 11:57:35 -06:00
|
|
|
Command::Bench => {
|
|
|
|
build_sysroot::build_sysroot(
|
|
|
|
&dirs,
|
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&cg_clif_dylib,
|
2023-01-14 06:53:33 -06:00
|
|
|
&bootstrap_host_compiler,
|
2023-02-13 04:11:45 -06:00
|
|
|
rustup_toolchain_name.as_deref(),
|
2023-01-14 07:04:40 -06:00
|
|
|
target_triple,
|
2023-01-05 11:57:35 -06:00
|
|
|
);
|
2023-02-10 03:45:50 -06:00
|
|
|
bench::benchmark(&dirs, &bootstrap_host_compiler);
|
2023-01-05 11:57:35 -06:00
|
|
|
}
|
2022-07-30 04:32:54 -05:00
|
|
|
}
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|