about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-13 10:11:45 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-05-22 17:17:05 +0000
commita2f720d9fe12a0981a14fd16f84cb8b23c284432 (patch)
tree72bf520fddbf2d7a78cf204bab284008afe5e60a
parent22befab611db45f5448d09db63e67fb72bd9af0c (diff)
downloadrust-a2f720d9fe12a0981a14fd16f84cb8b23c284432.tar.gz
rust-a2f720d9fe12a0981a14fd16f84cb8b23c284432.zip
Allow building and testing without rustup
This can be done by installing the nightly specified in
rust-toolchain.toml and then pointing the CARGO, RUSTC and RUSTDOC env
vars to the right executables.
-rw-r--r--build_system/abi_cafe.rs2
-rw-r--r--build_system/build_sysroot.rs18
-rw-r--r--build_system/mod.rs20
-rw-r--r--build_system/rustc_info.rs9
-rw-r--r--build_system/tests.rs3
-rw-r--r--build_system/usage.txt5
-rw-r--r--scripts/cargo-clif.rs13
-rw-r--r--scripts/rustc-clif.rs13
-rw-r--r--scripts/rustdoc-clif.rs13
9 files changed, 78 insertions, 18 deletions
diff --git a/build_system/abi_cafe.rs b/build_system/abi_cafe.rs
index 5b49a2e01d0..8ffd4852083 100644
--- a/build_system/abi_cafe.rs
+++ b/build_system/abi_cafe.rs
@@ -16,6 +16,7 @@ pub(crate) fn run(
     sysroot_kind: SysrootKind,
     dirs: &Dirs,
     cg_clif_dylib: &Path,
+    rustup_toolchain_name: Option<&str>,
     bootstrap_host_compiler: &Compiler,
 ) {
     ABI_CAFE_REPO.fetch(dirs);
@@ -27,6 +28,7 @@ pub(crate) fn run(
         sysroot_kind,
         cg_clif_dylib,
         bootstrap_host_compiler,
+        rustup_toolchain_name,
         bootstrap_host_compiler.triple.clone(),
     );
 
diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs
index 67c4cfa4417..d2e712941bf 100644
--- a/build_system/build_sysroot.rs
+++ b/build_system/build_sysroot.rs
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
 use std::process::{self, Command};
 
 use super::path::{Dirs, RelPath};
-use super::rustc_info::{get_file_name, get_rustc_version, get_toolchain_name};
+use super::rustc_info::{get_file_name, get_rustc_version};
 use super::utils::{remove_dir_if_exists, spawn_and_wait, try_hard_link, CargoProject, Compiler};
 use super::SysrootKind;
 
@@ -17,6 +17,7 @@ pub(crate) fn build_sysroot(
     sysroot_kind: SysrootKind,
     cg_clif_dylib_src: &Path,
     bootstrap_host_compiler: &Compiler,
+    rustup_toolchain_name: Option<&str>,
     target_triple: String,
 ) -> Compiler {
     eprintln!("[BUILD] sysroot {:?}", sysroot_kind);
@@ -41,18 +42,29 @@ pub(crate) fn build_sysroot(
 
     // Build and copy rustc and cargo wrappers
     let wrapper_base_name = get_file_name(&bootstrap_host_compiler.rustc, "____", "bin");
-    let toolchain_name = get_toolchain_name();
     for wrapper in ["rustc-clif", "rustdoc-clif", "cargo-clif"] {
         let wrapper_name = wrapper_base_name.replace("____", wrapper);
 
         let mut build_cargo_wrapper_cmd = Command::new(&bootstrap_host_compiler.rustc);
         let wrapper_path = DIST_DIR.to_path(dirs).join(&wrapper_name);
         build_cargo_wrapper_cmd
-            .env("TOOLCHAIN_NAME", toolchain_name.clone())
             .arg(RelPath::SCRIPTS.to_path(dirs).join(&format!("{wrapper}.rs")))
             .arg("-o")
             .arg(&wrapper_path)
             .arg("-Cstrip=debuginfo");
+        if let Some(rustup_toolchain_name) = &rustup_toolchain_name {
+            build_cargo_wrapper_cmd
+                .env("TOOLCHAIN_NAME", rustup_toolchain_name)
+                .env_remove("CARGO")
+                .env_remove("RUSTC")
+                .env_remove("RUSTDOC");
+        } else {
+            build_cargo_wrapper_cmd
+                .env_remove("TOOLCHAIN_NAME")
+                .env("CARGO", &bootstrap_host_compiler.cargo)
+                .env("RUSTC", &bootstrap_host_compiler.rustc)
+                .env("RUSTDOC", &bootstrap_host_compiler.rustdoc);
+        }
         spawn_and_wait(build_cargo_wrapper_cmd);
         try_hard_link(wrapper_path, BIN_DIR.to_path(dirs).join(wrapper_name));
     }
diff --git a/build_system/mod.rs b/build_system/mod.rs
index 58b21f64d37..d1d6f34dcff 100644
--- a/build_system/mod.rs
+++ b/build_system/mod.rs
@@ -103,6 +103,14 @@ pub(crate) fn main() {
         }
     }
 
+    let rustup_toolchain_name = match (env::var("CARGO"), env::var("RUSTC"), env::var("RUSTDOC")) {
+        (Ok(_), Ok(_), Ok(_)) => None,
+        (Err(_), Err(_), Err(_)) => Some(rustc_info::get_toolchain_name()),
+        _ => {
+            eprintln!("All of CARGO, RUSTC and RUSTDOC need to be set or none must be set");
+            process::exit(1);
+        }
+    };
     let bootstrap_host_compiler = {
         let cargo = rustc_info::get_cargo_path();
         let rustc = rustc_info::get_rustc_path();
@@ -173,6 +181,7 @@ pub(crate) fn main() {
                 sysroot_kind,
                 &cg_clif_dylib,
                 &bootstrap_host_compiler,
+                rustup_toolchain_name.as_deref(),
                 target_triple.clone(),
             );
         }
@@ -181,7 +190,14 @@ pub(crate) fn main() {
                 eprintln!("Abi-cafe doesn't support cross-compilation");
                 process::exit(1);
             }
-            abi_cafe::run(channel, sysroot_kind, &dirs, &cg_clif_dylib, &bootstrap_host_compiler);
+            abi_cafe::run(
+                channel,
+                sysroot_kind,
+                &dirs,
+                &cg_clif_dylib,
+                rustup_toolchain_name.as_deref(),
+                &bootstrap_host_compiler,
+            );
         }
         Command::Build => {
             build_sysroot::build_sysroot(
@@ -190,6 +206,7 @@ pub(crate) fn main() {
                 sysroot_kind,
                 &cg_clif_dylib,
                 &bootstrap_host_compiler,
+                rustup_toolchain_name.as_deref(),
                 target_triple,
             );
         }
@@ -200,6 +217,7 @@ pub(crate) fn main() {
                 sysroot_kind,
                 &cg_clif_dylib,
                 &bootstrap_host_compiler,
+                rustup_toolchain_name.as_deref(),
                 target_triple,
             );
             bench::benchmark(&dirs, &bootstrap_host_compiler);
diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs
index 63f41ad5662..c14b4fdaf33 100644
--- a/build_system/rustc_info.rs
+++ b/build_system/rustc_info.rs
@@ -34,6 +34,9 @@ pub(crate) fn get_toolchain_name() -> String {
 }
 
 pub(crate) fn get_cargo_path() -> PathBuf {
+    if let Ok(cargo) = std::env::var("CARGO") {
+        return PathBuf::from(cargo);
+    }
     let cargo_path = Command::new("rustup")
         .stderr(Stdio::inherit())
         .args(&["which", "cargo"])
@@ -44,6 +47,9 @@ pub(crate) fn get_cargo_path() -> PathBuf {
 }
 
 pub(crate) fn get_rustc_path() -> PathBuf {
+    if let Ok(rustc) = std::env::var("RUSTC") {
+        return PathBuf::from(rustc);
+    }
     let rustc_path = Command::new("rustup")
         .stderr(Stdio::inherit())
         .args(&["which", "rustc"])
@@ -54,6 +60,9 @@ pub(crate) fn get_rustc_path() -> PathBuf {
 }
 
 pub(crate) fn get_rustdoc_path() -> PathBuf {
+    if let Ok(rustdoc) = std::env::var("RUSTDOC") {
+        return PathBuf::from(rustdoc);
+    }
     let rustc_path = Command::new("rustup")
         .stderr(Stdio::inherit())
         .args(&["which", "rustdoc"])
diff --git a/build_system/tests.rs b/build_system/tests.rs
index 3af74e1e97c..40bcf1e0c1e 100644
--- a/build_system/tests.rs
+++ b/build_system/tests.rs
@@ -217,6 +217,7 @@ pub(crate) fn run_tests(
     sysroot_kind: SysrootKind,
     cg_clif_dylib: &Path,
     bootstrap_host_compiler: &Compiler,
+    rustup_toolchain_name: Option<&str>,
     target_triple: String,
 ) {
     if config::get_bool("testsuite.no_sysroot") {
@@ -226,6 +227,7 @@ pub(crate) fn run_tests(
             SysrootKind::None,
             cg_clif_dylib,
             bootstrap_host_compiler,
+            rustup_toolchain_name,
             target_triple.clone(),
         );
 
@@ -251,6 +253,7 @@ pub(crate) fn run_tests(
             sysroot_kind,
             cg_clif_dylib,
             bootstrap_host_compiler,
+            rustup_toolchain_name,
             target_triple.clone(),
         );
         // Rust's build system denies a couple of lints that trigger on several of the test
diff --git a/build_system/usage.txt b/build_system/usage.txt
index e7b4f0af2d9..1aee083f8df 100644
--- a/build_system/usage.txt
+++ b/build_system/usage.txt
@@ -30,8 +30,9 @@ OPTIONS:
             Require Cargo.lock and cache are up to date
 
 REQUIREMENTS:
-    * Rustup: The build system has a hard coded dependency on rustup to install the right nightly
-      version and make sure it is used where necessary.
+    * Rustup: By default rustup is used to install the right nightly version. If you don't want to
+      use rustup, you can manually install the nightly version indicated by rust-toolchain.toml and
+      point the CARGO, RUSTC and RUSTDOC env vars to the right executables.
     * Git: `./y.rs prepare` uses git for applying patches and on Windows for downloading test repos.
     * Curl and tar (non-Windows only): Used by `./y.rs prepare` to download a single commit for
       repos. Git will be used to clone the whole repo when using Windows.
diff --git a/scripts/cargo-clif.rs b/scripts/cargo-clif.rs
index e2db7d03a9d..0d5d9f7db01 100644
--- a/scripts/cargo-clif.rs
+++ b/scripts/cargo-clif.rs
@@ -28,8 +28,13 @@ fn main() {
     env::set_var("RUSTFLAGS", env::var("RUSTFLAGS").unwrap_or(String::new()) + &rustflags);
     env::set_var("RUSTDOCFLAGS", env::var("RUSTDOCFLAGS").unwrap_or(String::new()) + &rustflags);
 
-    // Ensure that the right toolchain is used
-    env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
+    let cargo = if let Some(cargo) = option_env!("CARGO") {
+        cargo
+    } else {
+        // Ensure that the right toolchain is used
+        env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
+        "cargo"
+    };
 
     let args: Vec<_> = match env::args().nth(1).as_deref() {
         Some("jit") => {
@@ -64,10 +69,10 @@ fn main() {
     };
 
     #[cfg(unix)]
-    panic!("Failed to spawn cargo: {}", Command::new("cargo").args(args).exec());
+    panic!("Failed to spawn cargo: {}", Command::new(cargo).args(args).exec());
 
     #[cfg(not(unix))]
     std::process::exit(
-        Command::new("cargo").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
+        Command::new(cargo).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
     );
 }
diff --git a/scripts/rustc-clif.rs b/scripts/rustc-clif.rs
index 7ef3488672d..df94b80b34f 100644
--- a/scripts/rustc-clif.rs
+++ b/scripts/rustc-clif.rs
@@ -30,14 +30,19 @@ fn main() {
     }
     args.extend(passed_args);
 
-    // Ensure that the right toolchain is used
-    env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
+    let rustc = if let Some(rustc) = option_env!("RUSTC") {
+        rustc
+    } else {
+        // Ensure that the right toolchain is used
+        env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
+        "rustc"
+    };
 
     #[cfg(unix)]
-    panic!("Failed to spawn rustc: {}", Command::new("rustc").args(args).exec());
+    panic!("Failed to spawn rustc: {}", Command::new(rustc).args(args).exec());
 
     #[cfg(not(unix))]
     std::process::exit(
-        Command::new("rustc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
+        Command::new(rustc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
     );
 }
diff --git a/scripts/rustdoc-clif.rs b/scripts/rustdoc-clif.rs
index 72024e0d494..36a00dc676e 100644
--- a/scripts/rustdoc-clif.rs
+++ b/scripts/rustdoc-clif.rs
@@ -30,14 +30,19 @@ fn main() {
     }
     args.extend(passed_args);
 
-    // Ensure that the right toolchain is used
-    env::set_var("RUSTUP_TOOLCHAIN", env!("TOOLCHAIN_NAME"));
+    let rustdoc = if let Some(rustdoc) = option_env!("RUSTDOC") {
+        rustdoc
+    } else {
+        // Ensure that the right toolchain is used
+        env::set_var("RUSTUP_TOOLCHAIN", option_env!("TOOLCHAIN_NAME").expect("TOOLCHAIN_NAME"));
+        "rustdoc"
+    };
 
     #[cfg(unix)]
-    panic!("Failed to spawn rustdoc: {}", Command::new("rustdoc").args(args).exec());
+    panic!("Failed to spawn rustdoc: {}", Command::new(rustdoc).args(args).exec());
 
     #[cfg(not(unix))]
     std::process::exit(
-        Command::new("rustdoc").args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
+        Command::new(rustdoc).args(args).spawn().unwrap().wait().unwrap().code().unwrap_or(1),
     );
 }