about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbit-aloo <sshourya17@gmail.com>2025-09-21 19:43:43 +0530
committerbit-aloo <sshourya17@gmail.com>2025-09-21 20:58:15 +0530
commitafe380dd58170b55b100a659f05017b1149d0ec9 (patch)
tree37a6a37d99e68b50250ca372e53666841ab7aac1
parent671aabd4eb1a56a09b989abc021bee32750ee59b (diff)
downloadrust-afe380dd58170b55b100a659f05017b1149d0ec9.tar.gz
rust-afe380dd58170b55b100a659f05017b1149d0ec9.zip
initialize out with CARGO_TARGET_DIR and then go for manifest and then for current
-rw-r--r--src/bootstrap/src/core/config/config.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index 003cf3f2f9c..1f3b90d324f 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -630,9 +630,13 @@ impl Config {
         let llvm_assertions = llvm_assertions.unwrap_or(false);
         let mut target_config = HashMap::new();
         let mut channel = "dev".to_string();
-        let out = flags_build_dir
-            .or(build_build_dir.map(PathBuf::from))
-            .unwrap_or_else(|| PathBuf::from("build"));
+        let out = if cfg!(test) {
+            test_build_dir()
+        } else {
+            flags_build_dir
+                .or_else(|| build_build_dir.map(PathBuf::from))
+                .unwrap_or_else(|| PathBuf::from("build"))
+        };
 
         // NOTE: Bootstrap spawns various commands with different working directories.
         // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -683,11 +687,6 @@ impl Config {
         };
 
         let initial_rustc = build_rustc.unwrap_or_else(|| {
-            let out = if cfg!(test) {
-                std::env::current_dir().unwrap().ancestors().nth(2).unwrap().join("build")
-            } else {
-                out.clone()
-            };
             download_beta_toolchain(&dwn_ctx, &out);
             let target = if cfg!(test) { get_host_target() } else { host_target };
 
@@ -2481,3 +2480,15 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> {
         })
         .collect()
 }
+
+fn test_build_dir() -> PathBuf {
+    env::var_os("CARGO_TARGET_DIR")
+        .map(|value| Path::new(&value).parent().unwrap().to_path_buf())
+        .unwrap_or_else(|| {
+            let base = option_env!("CARGO_MANIFEST_DIR")
+                .map(PathBuf::from)
+                .unwrap_or_else(|| std::env::current_dir().expect("failed to get current dir"));
+
+            base.ancestors().nth(2).unwrap_or_else(|| Path::new(".")).join("build")
+        })
+}