diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index ad256c2e97be2..1c2bb467ef2fa 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1001,9 +1001,12 @@ def bootstrap_out(self): >>> rb = RustBuild() >>> rb.build_dir = "build" - >>> rb.bootstrap_binary() == os.path.join("build", "bootstrap") + >>> rb.bootstrap_out() == os.path.join("build", "bootstrap", rb.build) True """ + return os.path.join(self.bootstrap_cargo_target_dir(), self.build) + + def bootstrap_cargo_target_dir(self): return os.path.join(self.build_dir, "bootstrap") def bootstrap_binary(self): @@ -1011,7 +1014,7 @@ def bootstrap_binary(self): >>> rb = RustBuild() >>> rb.build_dir = "build" - >>> rb.bootstrap_binary() == os.path.join("build", "bootstrap", + >>> rb.bootstrap_binary() == os.path.join("build", "bootstrap", rb.build, ... "debug", "bootstrap") True """ @@ -1033,8 +1036,7 @@ def build_bootstrap(self): print("::endgroup::") def build_bootstrap_cmd(self, env): - """For tests.""" - build_dir = os.path.join(self.build_dir, "bootstrap") + build_dir = self.bootstrap_cargo_target_dir() if self.clean and os.path.exists(build_dir): shutil.rmtree(build_dir) # `CARGO_BUILD_TARGET` breaks bootstrap build. @@ -1120,10 +1122,14 @@ def build_bootstrap_cmd(self, env): self.cargo(), "build", "--jobs=" + self.jobs, + "--target", + self.build, "--manifest-path", os.path.join(self.rust_root, "src/bootstrap/Cargo.toml"), "-Zroot-dir=" + self.rust_root, + "--bins", ] + # verbose cargo output is very noisy, so only enable it with -vv args.extend("--verbose" for _ in range(self.verbose - 1)) if self.verbose < 0: diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 1dbe997d23f3a..bf02aa7865f29 100644 --- a/src/bootstrap/bootstrap_test.py +++ b/src/bootstrap/bootstrap_test.py @@ -238,6 +238,21 @@ def test_cargoflags(self): args, _ = self.build_args(env={"CARGOFLAGS": "--timings"}) self.assertTrue("--timings" in args) + def test_build_bootstrap_uses_explicit_build_target(self): + args, _ = self.build_args( + configure_args=[ + "--set", + "build.cargo=" + sys.executable, + "--set", + "build.rustc=" + sys.executable, + ], + args=["--build", "host-tuple"], + ) + expected_build = os.environ.get("BUILD_PLATFORM", "host-tuple") + self.assertEqual(args[1], "build") + self.assertTrue("--bins" in args) + self.assertEqual(args[args.index("--target") + 1], expected_build) + def test_warnings(self): for toml_warnings in ["false", "true", None]: configure_args = []