-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bootstrap: RUSTFLAGS_*_BOOTSTRAP does not affect build scripts #94007
Comments
I just tried a quick-n-dirty build where I removed the line above that adds Line 1325 in c5c610a
with
I believe that happens due to the hard-coding of Line 727 in c5c610a
This assumption is also present here: Lines 1241 to 1251 in c5c610a
|
For others who run into this, this patch worked for me against Rust 1.58.1, though should almost certainly not be upstreamed in its current form: diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 6ba1b1b6036..d389209150f 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -898,11 +898,7 @@ pub fn cargo(
Color::Auto => {} // nothing to do
}
- if cmd != "install" {
- cargo.arg("--target").arg(target.rustc_target_arg());
- } else {
- assert_eq!(target, compiler.host);
- }
+ assert_eq!(target, compiler.host);
// Set a flag for `check`/`clippy`/`fix`, so that certain build
// scripts can do less work (i.e. not building/requiring LLVM).
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs
index 007ca9f7f5a..a6859b297aa 100644
--- a/src/bootstrap/compile.rs
+++ b/src/bootstrap/compile.rs
@@ -1225,12 +1225,7 @@ pub fn run_cargo(
// `target_deps_dir` looks like $dir/$target/release/deps
let target_deps_dir = target_root_dir.join("deps");
// `host_root_dir` looks like $dir/release
- let host_root_dir = target_root_dir
- .parent()
- .unwrap() // chop off `release`
- .parent()
- .unwrap() // chop off `$target`
- .join(target_root_dir.file_name().unwrap());
+ let host_root_dir = target_root_dir.clone();
// Spawn Cargo slurping up its JSON output. We'll start building up the
// `deps` array of all files it generated along with a `toplevel` array of
diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
index 1667dfc3f85..04a7036cf4b 100644
--- a/src/bootstrap/lib.rs
+++ b/src/bootstrap/lib.rs
@@ -729,8 +733,8 @@ fn stage_out(&self, compiler: Compiler, mode: Mode) -> PathBuf {
/// Returns the root output directory for all Cargo output in a given stage,
/// 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())
+ fn cargo_out(&self, compiler: Compiler, mode: Mode, _target: TargetSelection) -> PathBuf {
+ self.stage_out(compiler, mode).join(self.cargo_dir())
}
/// Root output directory for LLVM compiled for `target` |
Yeah, I'm pretty sure this needs upstream support in Cargo if we want a nice workaround (somehow). Locally to rustbuild, we could manually pass through opts in our wrapper shim in theory, but I would prefer not to try to fix this in rustbuild rather than upstream, but if there's a -Z flag or similar that could get passed that would likely be fine. |
Unfortunately I don't think there's a |
Yes, I meant that given the backwards compat concern with just changing RUSTFLAGS behavior in Cargo, a -Z flag to opt-in may be one path forward. |
Fuchsia also just ran into this in #94003 🤔 |
The -Z flag is |
This is what |
Interestingly, the patch I posted above (and probably more generally when the bootstrap rustflags are applied to build scripts) somehow trips up
Still digging into why that is. The
@cuviper given your knowledge of
Which suggests that the problem may be somewhere higher up that |
I only added |
Ah, right, so these flags would be applied to the compilation of You make a good point though that I'll probably also need to update the vendored |
I missed the early Lines 1281 to 1289 in 6bf3008
Still figuring out how to properly replace that check. My earlier patch seems to fail to find the |
I wonder if I'm running into the fact that with EDIT: Looking at the root cause for rust-lang/cargo#10206, I don't think any workaround will work here — either |
Fix for the Cargo issue is in rust-lang/cargo#10395. |
When rust-lang/cargo#10395 lands, I think there's still an open question about what Rust's bootstrap logic should do. Should it generate a |
autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
Bump autocfg to 1.1.0 autocfg 1.1.0 makes it so that rustflags from the build are correctly passed to the compiler probes, which in turn means those probes more accurately reflect the outer build conditions. This is particularly important if rustflags includes _required_ `-Clink-arg=` flags without which builds will fail, as older versions of `autocfg` will then fail the probe and erroneously report the probed feature as unavailable. See also rust-lang#94007 (comment)
I think we're seeing this in Chromium, when trying to bootstrap our Rust toolchain: https://issues.chromium.org/issues/40280340 |
In #123593 (comment), I attempted to solve the issue with the host This isn't a bug, so.. @rustbot label -C-bug |
Given that bootstrapping is inherently somewhat a hacky flow, I would prefer leaving such solutions (e.g., generating a [host] section in .cargo/config) to be handled externally, as long as it's feasible and not significantly more complex than handling them in the bootstrap. |
I would like to use a |
The |
That'll work without |
Based on how other configs can be set using env vars, I expect |
It's unclear if this should be a bug report for Rust's bootstrap or not, but it feels like it's appropriate if only for tracking the problem for when others run into the same. I think closing this is also reasonable.
When
RUSTFLAGS_BOOTSTRAP
/RUSTFLAGS_NOT_BOOSTRAP
is passed to tox.py
(gets picked up here), those variables are forwarded asRUSTFLAGS
here:rust/src/bootstrap/builder.rs
Line 1856 in c5c610a
This works most of the time. However, there is a known bug in Cargo (rust-lang/cargo#5754 / rust-lang/cargo#4423) that makes it so that if
--target
is passed to acargo
invocation, even if the passed triple is the same as the host triple,RUSTFLAGS
is not passed to build scripts. And since bootstrap always passes--target
,RUSTFLAGS_*_BOOTSTRAP
do not take effect for builds scripts:rust/src/bootstrap/builder.rs
Line 1001 in c5c610a
This is problematic when
RUSTFLAGS
includes arguments that are critical to building, most notably in the form of-Clink-arg
s without which any attempt to link may fail.There isn't an obvious fix to the problem beyond fixing the upstream problem(s) in Cargo. One possibility is to detect when
target == host
in the bootstrap logic and avoid passing--target
tocargo
in that instance. That way build scripts will respectRUSTFLAGS
again, though it may still pose a problem for cross-compiling use-cases, I'm not sure?Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: