2021-06-08 12:33:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#![allow()] /*This line is ignored by bash
|
|
|
|
# This block is ignored by rustc
|
|
|
|
set -e
|
|
|
|
echo "[BUILD] y.rs" 1>&2
|
|
|
|
rustc $0 -o ${0/.rs/.bin} -g
|
|
|
|
exec ${0/.rs/.bin} $@
|
|
|
|
*/
|
|
|
|
|
|
|
|
//! The build system for cg_clif
|
|
|
|
//!
|
|
|
|
//! # Manual compilation
|
|
|
|
//!
|
|
|
|
//! If your system doesn't support shell scripts you can manually compile and run this file using
|
|
|
|
//! for example:
|
|
|
|
//!
|
|
|
|
//! ```shell
|
2021-08-04 07:23:27 +00:00
|
|
|
//! $ rustc y.rs -o y.bin
|
|
|
|
//! $ ./y.bin
|
2021-06-08 12:33:25 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! # Naming
|
|
|
|
//!
|
|
|
|
//! The name `y.rs` was chosen to not conflict with rustc's `x.py`.
|
|
|
|
|
|
|
|
use std::env;
|
2021-06-11 16:50:01 +00:00
|
|
|
use std::path::PathBuf;
|
2021-06-08 12:33:25 +00:00
|
|
|
use std::process;
|
|
|
|
|
|
|
|
#[path = "build_system/build_backend.rs"]
|
|
|
|
mod build_backend;
|
|
|
|
#[path = "build_system/build_sysroot.rs"]
|
|
|
|
mod build_sysroot;
|
2021-07-04 13:10:06 +00:00
|
|
|
#[path = "build_system/config.rs"]
|
|
|
|
mod config;
|
2021-06-11 16:50:01 +00:00
|
|
|
#[path = "build_system/prepare.rs"]
|
|
|
|
mod prepare;
|
2021-06-08 12:33:25 +00:00
|
|
|
#[path = "build_system/rustc_info.rs"]
|
|
|
|
mod rustc_info;
|
2021-06-11 16:50:01 +00:00
|
|
|
#[path = "build_system/utils.rs"]
|
|
|
|
mod utils;
|
2021-06-08 12:33:25 +00:00
|
|
|
|
|
|
|
fn usage() {
|
|
|
|
eprintln!("Usage:");
|
2021-06-11 16:50:01 +00:00
|
|
|
eprintln!(" ./y.rs prepare");
|
2021-06-08 12:33:25 +00:00
|
|
|
eprintln!(" ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]");
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! arg_error {
|
|
|
|
($($err:tt)*) => {{
|
|
|
|
eprintln!($($err)*);
|
|
|
|
usage();
|
|
|
|
std::process::exit(1);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Command {
|
|
|
|
Build,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
enum SysrootKind {
|
|
|
|
None,
|
|
|
|
Clif,
|
|
|
|
Llvm,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
env::set_var("CG_CLIF_DISPLAY_CG_TIME", "1");
|
|
|
|
env::set_var("CG_CLIF_DISABLE_INCR_CACHE", "1");
|
2021-06-18 11:27:56 +00:00
|
|
|
// The target dir is expected in the default location. Guard against the user changing it.
|
|
|
|
env::set_var("CARGO_TARGET_DIR", "target");
|
2021-06-08 12:33:25 +00:00
|
|
|
|
|
|
|
let mut args = env::args().skip(1);
|
|
|
|
let command = match args.next().as_deref() {
|
|
|
|
Some("prepare") => {
|
|
|
|
if args.next().is_some() {
|
|
|
|
arg_error!("./x.rs prepare doesn't expect arguments");
|
|
|
|
}
|
2021-06-11 16:50:01 +00:00
|
|
|
prepare::prepare();
|
|
|
|
process::exit(0);
|
2021-06-08 12:33:25 +00:00
|
|
|
}
|
|
|
|
Some("build") => Command::Build,
|
|
|
|
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;
|
|
|
|
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"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
flag if flag.starts_with("-") => arg_error!("Unknown flag {}", flag),
|
|
|
|
arg => arg_error!("Unexpected argument {}", arg),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") {
|
|
|
|
host_triple
|
2021-07-04 13:10:06 +00:00
|
|
|
} else if let Some(host_triple) = crate::config::get_value("host") {
|
|
|
|
host_triple
|
2021-06-08 12:33:25 +00:00
|
|
|
} 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
|
|
|
|
}
|
2021-07-04 13:10:06 +00:00
|
|
|
} else if let Some(target_triple) = crate::config::get_value("target") {
|
|
|
|
target_triple
|
2021-06-08 12:33:25 +00:00
|
|
|
} else {
|
|
|
|
host_triple.clone()
|
|
|
|
};
|
|
|
|
|
2021-06-19 12:07:56 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-07-04 16:15:13 +00:00
|
|
|
let cg_clif_build_dir = build_backend::build_backend(channel, &host_triple);
|
2021-06-08 12:33:25 +00:00
|
|
|
build_sysroot::build_sysroot(
|
|
|
|
channel,
|
|
|
|
sysroot_kind,
|
|
|
|
&target_dir,
|
2021-07-04 16:15:13 +00:00
|
|
|
cg_clif_build_dir,
|
2021-06-08 12:33:25 +00:00
|
|
|
&host_triple,
|
|
|
|
&target_triple,
|
|
|
|
);
|
|
|
|
}
|