2022-02-23 04:49:34 -06:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::process;
|
|
|
|
|
2023-02-09 05:38:16 -06:00
|
|
|
use self::utils::{is_ci, is_ci_opt, Compiler};
|
2022-08-24 11:40:58 -05:00
|
|
|
|
2022-10-23 09:22:55 -05:00
|
|
|
mod abi_cafe;
|
2023-01-24 11:56:42 -06:00
|
|
|
mod bench;
|
2022-02-23 04:49:34 -06:00
|
|
|
mod build_backend;
|
|
|
|
mod build_sysroot;
|
|
|
|
mod config;
|
2022-12-14 12:30:46 -06:00
|
|
|
mod path;
|
2022-02-23 04:49:34 -06:00
|
|
|
mod prepare;
|
|
|
|
mod rustc_info;
|
2022-08-24 11:40:58 -05:00
|
|
|
mod tests;
|
2022-02-23 04:49:34 -06:00
|
|
|
mod utils;
|
|
|
|
|
|
|
|
fn usage() {
|
2023-01-24 11:56:42 -06:00
|
|
|
eprintln!("{}", include_str!("usage.txt"));
|
2022-02-23 04:49:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! arg_error {
|
|
|
|
($($err:tt)*) => {{
|
|
|
|
eprintln!($($err)*);
|
|
|
|
usage();
|
|
|
|
std::process::exit(1);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2022-08-24 11:40:58 -05:00
|
|
|
#[derive(PartialEq, Debug)]
|
2022-02-23 04:49:34 -06:00
|
|
|
enum Command {
|
2022-12-14 12:30:46 -06:00
|
|
|
Prepare,
|
2022-02-23 04:49:34 -06:00
|
|
|
Build,
|
2022-08-24 11:40:58 -05:00
|
|
|
Test,
|
2023-01-24 11:56:42 -06:00
|
|
|
AbiCafe,
|
|
|
|
Bench,
|
2022-02-23 04:49:34 -06:00
|
|
|
}
|
|
|
|
|
2022-08-24 11:40:58 -05:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-02-23 04:49:34 -06:00
|
|
|
pub(crate) enum SysrootKind {
|
|
|
|
None,
|
|
|
|
Clif,
|
|
|
|
Llvm,
|
|
|
|
}
|
|
|
|
|
2023-04-29 07:00:43 -05:00
|
|
|
pub(crate) fn main() {
|
2023-01-24 11:56:42 -06:00
|
|
|
if env::var("RUST_BACKTRACE").is_err() {
|
|
|
|
env::set_var("RUST_BACKTRACE", "1");
|
|
|
|
}
|
2022-02-23 04:49:34 -06:00
|
|
|
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
|
|
|
|
|
2022-08-24 11:40:58 -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");
|
2023-01-24 11:56:42 -06:00
|
|
|
|
2023-02-09 05:38:16 -06:00
|
|
|
if !is_ci_opt() {
|
|
|
|
// Enable the Cranelift verifier
|
|
|
|
env::set_var("CG_CLIF_ENABLE_VERIFIER", "1");
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
|
2022-02-23 04:49:34 -06:00
|
|
|
let mut args = env::args().skip(1);
|
|
|
|
let command = match args.next().as_deref() {
|
2022-12-14 12:30:46 -06:00
|
|
|
Some("prepare") => Command::Prepare,
|
2022-02-23 04:49:34 -06:00
|
|
|
Some("build") => Command::Build,
|
2022-08-24 11:40:58 -05:00
|
|
|
Some("test") => Command::Test,
|
2023-01-24 11:56:42 -06:00
|
|
|
Some("abi-cafe") => Command::AbiCafe,
|
|
|
|
Some("bench") => Command::Bench,
|
2022-02-23 04:49:34 -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-14 12:30:46 -06:00
|
|
|
let mut out_dir = PathBuf::from(".");
|
2022-02-23 04:49:34 -06:00
|
|
|
let mut channel = "release";
|
|
|
|
let mut sysroot_kind = SysrootKind::Clif;
|
|
|
|
let mut use_unstable_features = true;
|
|
|
|
while let Some(arg) = args.next().as_deref() {
|
|
|
|
match arg {
|
2022-12-14 12:30:46 -06:00
|
|
|
"--out-dir" => {
|
|
|
|
out_dir = PathBuf::from(args.next().unwrap_or_else(|| {
|
|
|
|
arg_error!("--out-dir requires argument");
|
2022-02-23 04:49:34 -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,
|
|
|
|
flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
|
|
|
|
arg => arg_error!("Unexpected argument {}", arg),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
let bootstrap_host_compiler = Compiler::bootstrap_with_triple(
|
|
|
|
std::env::var("HOST_TRIPLE")
|
|
|
|
.ok()
|
|
|
|
.or_else(|| config::get_value("host"))
|
|
|
|
.unwrap_or_else(|| rustc_info::get_host_triple()),
|
|
|
|
);
|
|
|
|
let target_triple = std::env::var("TARGET_TRIPLE")
|
|
|
|
.ok()
|
|
|
|
.or_else(|| config::get_value("target"))
|
|
|
|
.unwrap_or_else(|| bootstrap_host_compiler.triple.clone());
|
2022-02-23 04:49:34 -06:00
|
|
|
|
2022-12-14 12:30:46 -06:00
|
|
|
// FIXME allow changing the location of these dirs using cli arguments
|
|
|
|
let current_dir = std::env::current_dir().unwrap();
|
|
|
|
out_dir = current_dir.join(out_dir);
|
|
|
|
let dirs = path::Dirs {
|
|
|
|
source_dir: current_dir.clone(),
|
|
|
|
download_dir: out_dir.join("download"),
|
|
|
|
build_dir: out_dir.join("build"),
|
|
|
|
dist_dir: out_dir.join("dist"),
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
if command == Command::Prepare {
|
|
|
|
prepare::prepare(&dirs);
|
|
|
|
process::exit(0);
|
|
|
|
}
|
|
|
|
|
2023-01-24 11:56:42 -06:00
|
|
|
env::set_var("RUSTC", "rustc_should_be_set_explicitly");
|
|
|
|
env::set_var("RUSTDOC", "rustdoc_should_be_set_explicitly");
|
|
|
|
|
|
|
|
let cg_clif_dylib = build_backend::build_backend(
|
|
|
|
&dirs,
|
|
|
|
channel,
|
|
|
|
&bootstrap_host_compiler,
|
|
|
|
use_unstable_features,
|
|
|
|
);
|
2022-08-24 11:40:58 -05:00
|
|
|
match command {
|
2022-12-14 12:30:46 -06:00
|
|
|
Command::Prepare => {
|
|
|
|
// Handled above
|
|
|
|
}
|
2022-08-24 11:40:58 -05:00
|
|
|
Command::Test => {
|
|
|
|
tests::run_tests(
|
2022-12-14 12:30:46 -06:00
|
|
|
&dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-10-23 09:22:55 -05:00
|
|
|
&cg_clif_dylib,
|
2023-01-24 11:56:42 -06:00
|
|
|
&bootstrap_host_compiler,
|
|
|
|
target_triple.clone(),
|
2022-08-24 11:40:58 -05:00
|
|
|
);
|
2023-01-24 11:56:42 -06:00
|
|
|
}
|
|
|
|
Command::AbiCafe => {
|
|
|
|
if bootstrap_host_compiler.triple != target_triple {
|
|
|
|
eprintln!("Abi-cafe doesn't support cross-compilation");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
abi_cafe::run(channel, sysroot_kind, &dirs, &cg_clif_dylib, &bootstrap_host_compiler);
|
|
|
|
}
|
|
|
|
Command::Build => {
|
|
|
|
build_sysroot::build_sysroot(
|
|
|
|
&dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-10-23 09:22:55 -05:00
|
|
|
&cg_clif_dylib,
|
2023-01-24 11:56:42 -06:00
|
|
|
&bootstrap_host_compiler,
|
|
|
|
target_triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
);
|
|
|
|
}
|
2023-01-24 11:56:42 -06:00
|
|
|
Command::Bench => {
|
2022-08-24 11:40:58 -05:00
|
|
|
build_sysroot::build_sysroot(
|
2022-12-14 12:30:46 -06:00
|
|
|
&dirs,
|
2022-08-24 11:40:58 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
2022-10-23 09:22:55 -05:00
|
|
|
&cg_clif_dylib,
|
2023-01-24 11:56:42 -06:00
|
|
|
&bootstrap_host_compiler,
|
|
|
|
target_triple,
|
2022-08-24 11:40:58 -05:00
|
|
|
);
|
2023-01-24 11:56:42 -06:00
|
|
|
bench::benchmark(&dirs, &bootstrap_host_compiler);
|
2022-08-24 11:40:58 -05:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 04:49:34 -06:00
|
|
|
}
|