From 0bdcd2c85d8ae408250fcf78ff8d6264ab6d5b39 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 7 Apr 2024 17:41:41 +0300 Subject: [PATCH 1/2] propagate `--target` only if target is not host Passing `--target` alters `RUSTFLAGS` in the build scripts. Since there is no reason to pass them when building for the host triple, exclude them if the target is the host triple. Signed-off-by: onur-ozkan --- src/bootstrap/src/core/builder.rs | 5 ++--- src/bootstrap/src/lib.rs | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 9555be481e695..c3031033fecbd 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1343,10 +1343,9 @@ impl<'a> Builder<'a> { Color::Auto => {} // nothing to do } - if cmd != "install" { + if target != compiler.host { + assert!(cmd != "install", "`x install` can only be called for the host triple."); cargo.arg("--target").arg(target.rustc_target_arg()); - } else { - assert_eq!(target, compiler.host); } if self.config.rust_optimize.is_release() { diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index bcb8260b15aa8..d009fd4b6bffd 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -797,7 +797,13 @@ impl Build { /// running a particular compiler, whether or not we're building the /// standard library, and targeting the specified architecture. fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf { - self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir()) + let stage_out = self.stage_out(compiler, mode); + + if self.config.build == target { + stage_out.join(self.cargo_dir()) + } else { + stage_out.join(&*target.triple).join(self.cargo_dir()) + } } /// Root output directory of LLVM for `target` From e612cbd98757f7c4f2eb074f377ce78f4d281677 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 7 Apr 2024 19:07:36 +0300 Subject: [PATCH 2/2] add test for `Build::cargo_out` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/builder/tests.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 178df633cec68..635e89e48cba1 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -128,6 +128,27 @@ fn validate_path_remap() { }); } +#[test] +fn validate_cargo_output() { + let build = Build::new(configure("test", &["A"], &["A"])); + + let out = build.cargo_out( + Compiler { host: TargetSelection::default(), stage: 1 }, + Mode::Rustc, + TargetSelection::default(), + ); + + assert!(out.ends_with("stage1-rustc/release")); + + let out = build.cargo_out( + Compiler { host: TargetSelection::default(), stage: 1 }, + Mode::Rustc, + TargetSelection::from_user("B"), + ); + + assert!(out.ends_with("stage1-rustc/B/release")); +} + #[test] fn test_exclude() { let mut config = configure("test", &["A"], &["A"]);