]> git.lizzy.rs Git - rust.git/blobdiff - y.rs
Only deny warnings for cg_clif build itself
[rust.git] / y.rs
diff --git a/y.rs b/y.rs
index 7971e713082f88e21aca49a5edd9a82266f85624..98b114de91078910d97a788605f64e59790ff95a 100755 (executable)
--- a/y.rs
+++ b/y.rs
@@ -15,8 +15,8 @@
 //! 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::fs;
-use std::path::{Path, PathBuf};
+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 build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR]");
+    eprintln!("  ./y.rs prepare");
+    eprintln!(
+        "  ./y.rs build [--debug] [--sysroot none|clif|llvm] [--target-dir DIR] [--no-unstable-features]"
+    );
 }
 
 macro_rules! arg_error {
@@ -62,6 +70,8 @@ enum SysrootKind {
 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() {
@@ -69,7 +79,8 @@ fn main() {
             if args.next().is_some() {
                 arg_error!("./x.rs prepare doesn't expect arguments");
             }
-            todo!();
+            prepare::prepare();
+            process::exit(0);
         }
         Some("build") => Command::Build,
         Some(flag) if flag.starts_with('-') => arg_error!("Expected command found flag {}", flag),
@@ -83,6 +94,7 @@ fn main() {
     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" => {
@@ -100,6 +112,7 @@ fn main() {
                     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),
         }
@@ -107,6 +120,8 @@ fn main() {
 
     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()
     };
@@ -116,26 +131,28 @@ fn main() {
         } 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()
     };
 
-    let cg_clif_dylib = build_backend::build_backend(channel);
+    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_dylib,
+        cg_clif_build_dir,
         &host_triple,
         &target_triple,
     );
 }
-
-#[track_caller]
-fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
-    let src = src.as_ref();
-    let dst = dst.as_ref();
-    if let Err(_) = fs::hard_link(src, dst) {
-        fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed
-    }
-}