2022-01-09 12:30:07 -06:00
|
|
|
use std::env;
|
2022-07-30 06:50:05 -05:00
|
|
|
use std::path::PathBuf;
|
2022-01-09 12:30:07 -06:00
|
|
|
use std::process;
|
|
|
|
|
2022-08-05 07:57:19 -05:00
|
|
|
use self::utils::is_ci;
|
|
|
|
|
2022-08-06 07:34:55 -05:00
|
|
|
mod abi_checker;
|
2022-01-09 12:30:07 -06:00
|
|
|
mod build_backend;
|
|
|
|
mod build_sysroot;
|
|
|
|
mod config;
|
|
|
|
mod prepare;
|
|
|
|
mod rustc_info;
|
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() {
|
|
|
|
eprintln!("Usage:");
|
|
|
|
eprintln!(" ./y.rs prepare");
|
|
|
|
eprintln!(
|
|
|
|
" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
|
|
|
|
);
|
2022-07-30 04:32:54 -05:00
|
|
|
eprintln!(
|
|
|
|
" ./y.rs test [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
|
|
|
|
);
|
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 {
|
|
|
|
Build,
|
2022-07-30 04:32:54 -05:00
|
|
|
Test,
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|
|
|
|
|
2022-07-30 04:32:54 -05:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2022-01-09 12:30:07 -06:00
|
|
|
pub(crate) enum SysrootKind {
|
|
|
|
None,
|
|
|
|
Clif,
|
|
|
|
Llvm,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
|
|
|
|
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
|
|
|
|
// The target dir is expected in the default location. Guard against the user changing it.
|
|
|
|
env::set_var("CARGO_TARGET_DIR", "target");
|
|
|
|
|
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-01-09 12:30:07 -06:00
|
|
|
let mut args = env::args().skip(1);
|
|
|
|
let command = match args.next().as_deref() {
|
|
|
|
Some("prepare") => {
|
|
|
|
if args.next().is_some() {
|
2022-07-30 07:06:37 -05:00
|
|
|
arg_error!("./y.rs prepare doesn't expect arguments");
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|
2022-07-30 17:04:59 -05:00
|
|
|
prepare::prepare();
|
2022-01-09 12:30:07 -06:00
|
|
|
process::exit(0);
|
|
|
|
}
|
|
|
|
Some("build") => Command::Build,
|
2022-07-30 04:32:54 -05:00
|
|
|
Some("test") => Command::Test,
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut target_dir = PathBuf::from("build");
|
|
|
|
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 {
|
|
|
|
"--target-dir" => {
|
|
|
|
target_dir = PathBuf::from(args.next().unwrap_or_else(|| {
|
|
|
|
arg_error!("--target-dir requires argument");
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
"--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),
|
|
|
|
}
|
|
|
|
}
|
2022-02-13 11:33:30 -06:00
|
|
|
target_dir = std::env::current_dir().unwrap().join(target_dir);
|
2022-01-09 12:30:07 -06:00
|
|
|
|
2022-07-30 17:04:59 -05:00
|
|
|
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
|
|
|
host_triple
|
|
|
|
} else if let Some(host_triple) = config::get_value("host") {
|
|
|
|
host_triple
|
|
|
|
} else {
|
|
|
|
rustc_info::get_host_triple()
|
|
|
|
};
|
|
|
|
let target_triple = if let Ok(target_triple) = std::env::var("TARGET_TRIPLE") {
|
|
|
|
if target_triple != "" {
|
|
|
|
target_triple
|
|
|
|
} else {
|
|
|
|
host_triple.clone() // Empty target triple can happen on GHA
|
|
|
|
}
|
|
|
|
} else if let Some(target_triple) = config::get_value("target") {
|
|
|
|
target_triple
|
|
|
|
} else {
|
|
|
|
host_triple.clone()
|
|
|
|
};
|
|
|
|
|
|
|
|
if target_triple.ends_with("-msvc") {
|
|
|
|
eprintln!("The MSVC toolchain is not yet supported by rustc_codegen_cranelift.");
|
|
|
|
eprintln!("Switch to the MinGW toolchain for Windows support.");
|
|
|
|
eprintln!("Hint: You can use `rustup set default-host x86_64-pc-windows-gnu` to");
|
|
|
|
eprintln!("set the global default target to MinGW");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
|
2022-07-31 05:15:56 -05:00
|
|
|
let cg_clif_build_dir =
|
|
|
|
build_backend::build_backend(channel, &host_triple, use_unstable_features);
|
2022-07-30 06:50:05 -05:00
|
|
|
match command {
|
|
|
|
Command::Test => {
|
|
|
|
tests::run_tests(
|
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&target_dir,
|
|
|
|
&cg_clif_build_dir,
|
|
|
|
&host_triple,
|
|
|
|
&target_triple,
|
|
|
|
);
|
2022-08-06 15:24:38 -05:00
|
|
|
|
|
|
|
abi_checker::run(
|
2022-07-30 06:50:05 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&target_dir,
|
|
|
|
&cg_clif_build_dir,
|
|
|
|
&host_triple,
|
|
|
|
&target_triple,
|
|
|
|
);
|
|
|
|
}
|
2022-08-06 15:24:38 -05:00
|
|
|
Command::Build => {
|
|
|
|
build_sysroot::build_sysroot(
|
2022-08-06 07:34:55 -05:00
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&target_dir,
|
|
|
|
&cg_clif_build_dir,
|
|
|
|
&host_triple,
|
|
|
|
&target_triple,
|
|
|
|
);
|
|
|
|
}
|
2022-07-30 04:32:54 -05:00
|
|
|
}
|
2022-01-09 12:30:07 -06:00
|
|
|
}
|