diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2022-01-09 19:30:07 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2022-01-09 19:30:07 +0100 |
| commit | 4dbd3196f9c810b7b985e579cb6f13ce907a8286 (patch) | |
| tree | 55308a04b8662a8e0a164b1c605ffff2652c9c81 | |
| parent | f328359787c19f27d93506e537442f417d5e86f5 (diff) | |
| download | rust-4dbd3196f9c810b7b985e579cb6f13ce907a8286.tar.gz rust-4dbd3196f9c810b7b985e579cb6f13ce907a8286.zip | |
Move most code from y.rs to build_system/mod.rs
y.rs can't be rustfmt'ed without making it no longer be a valid bash script.
| -rw-r--r-- | build_system/build_backend.rs | 2 | ||||
| -rw-r--r-- | build_system/build_sysroot.rs | 10 | ||||
| -rw-r--r-- | build_system/mod.rs | 127 | ||||
| -rw-r--r-- | build_system/prepare.rs | 4 | ||||
| -rwxr-xr-x | y.rs | 133 |
5 files changed, 138 insertions, 138 deletions
diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 1382c7e5379..0a56eb131ed 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -49,7 +49,7 @@ pub(crate) fn build_backend( cmd.env("RUSTFLAGS", rustflags); eprintln!("[BUILD] rustc_codegen_cranelift"); - crate::utils::spawn_and_wait(cmd); + super::utils::spawn_and_wait(cmd); Path::new("target").join(host_triple).join(channel) } diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 2956fb698e1..c9c003d4610 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -3,9 +3,9 @@ use std::fs; use std::path::{Path, PathBuf}; use std::process::{self, Command}; -use crate::rustc_info::{get_file_name, get_rustc_version}; -use crate::utils::{spawn_and_wait, try_hard_link}; -use crate::SysrootKind; +use super::rustc_info::{get_file_name, get_rustc_version}; +use super::utils::{spawn_and_wait, try_hard_link}; +use super::SysrootKind; pub(crate) fn build_sysroot( channel: &str, @@ -52,7 +52,7 @@ pub(crate) fn build_sysroot( .arg("-g"); spawn_and_wait(build_cargo_wrapper_cmd); - let default_sysroot = crate::rustc_info::get_default_sysroot(); + let default_sysroot = super::rustc_info::get_default_sysroot(); let rustlib = target_dir.join("lib").join("rustlib"); let host_rustlib_lib = rustlib.join(host_triple).join("lib"); @@ -167,7 +167,7 @@ fn build_clif_sysroot_for_triple( let build_dir = Path::new("build_sysroot").join("target").join(triple).join(channel); - if !crate::config::get_bool("keep_sysroot") { + if !super::config::get_bool("keep_sysroot") { // Cleanup the target dir with the exception of build scripts and the incremental cache for dir in ["build", "deps", "examples", "native"] { if build_dir.join(dir).exists() { diff --git a/build_system/mod.rs b/build_system/mod.rs new file mode 100644 index 00000000000..b228da3981f --- /dev/null +++ b/build_system/mod.rs @@ -0,0 +1,127 @@ +use std::env; +use std::path::PathBuf; +use std::process; + +mod build_backend; +mod build_sysroot; +mod config; +mod prepare; +mod rustc_info; +mod utils; + +fn usage() { + eprintln!("Usage:"); + eprintln!(" ./y.rs prepare"); + eprintln!( + " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" + ); +} + +macro_rules! arg_error { + ($($err:tt)*) => {{ + eprintln!($($err)*); + usage(); + std::process::exit(1); + }}; +} + +enum Command { + Build, +} + +#[derive(Copy, Clone)] +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"); + + 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"); + } + prepare::prepare(); + process::exit(0); + } + 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; + 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), + } + } + + 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); + } + + let cg_clif_build_dir = + build_backend::build_backend(channel, &host_triple, use_unstable_features); + build_sysroot::build_sysroot( + channel, + sysroot_kind, + &target_dir, + cg_clif_build_dir, + &host_triple, + &target_triple, + ); +} diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 561e2ed7b00..76ea506b6ac 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -5,8 +5,8 @@ use std::fs; use std::path::Path; use std::process::Command; -use crate::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; -use crate::utils::{copy_dir_recursively, spawn_and_wait}; +use super::rustc_info::{get_file_name, get_rustc_path, get_rustc_version}; +use super::utils::{copy_dir_recursively, spawn_and_wait}; pub(crate) fn prepare() { prepare_sysroot(); diff --git a/y.rs b/y.rs index 98b114de910..18528d54297 100755 --- a/y.rs +++ b/y.rs @@ -23,136 +23,9 @@ exec ${0/.rs/.bin} $@ //! //! The name `y.rs` was chosen to not conflict with rustc's `x.py`. -use std::env; -use std::path::PathBuf; -use std::process; - -#[path = "build_system/build_backend.rs"] -mod build_backend; -#[path = "build_system/build_sysroot.rs"] -mod build_sysroot; -#[path = "build_system/config.rs"] -mod config; -#[path = "build_system/prepare.rs"] -mod prepare; -#[path = "build_system/rustc_info.rs"] -mod rustc_info; -#[path = "build_system/utils.rs"] -mod utils; - -fn usage() { - eprintln!("Usage:"); - eprintln!(" ./y.rs prepare"); - eprintln!( - " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]" - ); -} - -macro_rules! arg_error { - ($($err:tt)*) => {{ - eprintln!($($err)*); - usage(); - std::process::exit(1); - }}; -} - -enum Command { - Build, -} - -#[derive(Copy, Clone)] -enum SysrootKind { - None, - Clif, - Llvm, -} +#[path = "build_system/mod.rs"] +mod build_system; 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"); - - 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"); - } - prepare::prepare(); - process::exit(0); - } - 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; - 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), - } - } - - let host_triple = if let Ok(host_triple) = std::env::var("HOST_TRIPLE") { - host_triple - } else if let Some(host_triple) = crate::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) = crate::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); - } - - let cg_clif_build_dir = - build_backend::build_backend(channel, &host_triple, use_unstable_features); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - &target_dir, - cg_clif_build_dir, - &host_triple, - &target_triple, - ); + build_system::main(); } |
