From 63b8d9b6898ec926f9eafa372506b6722d583694 Mon Sep 17 00:00:00 2001
From: Joshua Nelson <jnelson@cloudflare.com>
Date: Wed, 14 Sep 2022 21:54:16 -0500
Subject: [PATCH] Allow using vendoring when running bootstrap from outside the
 current working directory

---
 src/bootstrap/bootstrap.py | 3 ++-
 src/bootstrap/builder.rs   | 3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index cc08ae5f99f0e..25037bd0faaa9 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -771,7 +771,8 @@ def build_bootstrap(self, color):
         elif color == "never":
             args.append("--color=never")
 
-        run(args, env=env, verbose=self.verbose)
+        # Run this from the source directory so cargo finds .cargo/config
+        run(args, env=env, verbose=self.verbose, cwd=self.rust_root)
 
     def build_triple(self):
         """Build triple as in LLVM
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 14e8ebd6876b4..6a07ac6b007cb 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -1325,6 +1325,9 @@ impl<'a> Builder<'a> {
     ) -> Cargo {
         let mut cargo = Command::new(&self.initial_cargo);
         let out_dir = self.stage_out(compiler, mode);
+        // Run cargo from the source root so it can find .cargo/config.
+        // This matters when using vendoring and the working directory is outside the repository.
+        cargo.current_dir(&self.src);
 
         // Codegen backends are not yet tracked by -Zbinary-dep-depinfo,
         // so we need to explicitly clear out if they've been updated.