X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=y.rs;h=f177b91c2c4876a4ac7b62dd653a3e4ea0857453;hb=acf93987bc43dc2f9aba0984ec60131f17dc40fb;hp=62debc117c354e84ec785ebb52672f6c6c7d40b6;hpb=fe6a2892a6dd285774c3b1c84a2de45209454ce6;p=rust.git diff --git a/y.rs b/y.rs index 62debc117c3..f177b91c2c4 100755 --- a/y.rs +++ b/y.rs @@ -1,9 +1,9 @@ #!/usr/bin/env bash -#![allow()] /*This line is ignored by bash +#![deny(unsafe_code)] /*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 +rustc $0 -o ${0/.rs/.bin} -Cdebuginfo=1 exec ${0/.rs/.bin} $@ */ @@ -15,123 +15,17 @@ //! for example: //! //! ```shell -//! $ rustc y.rs -o build/y.bin -//! $ build/y.bin +//! $ rustc y.rs -o y.bin +//! $ ./y.bin //! ``` //! //! # Naming //! //! 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/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]"); -} - -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"); - - 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; - 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 - } 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 { - host_triple.clone() - }; - - let cg_clif_dylib = build_backend::build_backend(channel); - build_sysroot::build_sysroot( - channel, - sysroot_kind, - &target_dir, - cg_clif_dylib, - &host_triple, - &target_triple, - ); + build_system::main(); }