Skip to content

Conversation

@karolzwolak
Copy link
Member

@karolzwolak karolzwolak commented Nov 13, 2025

Before this PR extra flags from env variables like RUSTFLAGS had lower precedence than bootstrap flags. This PR changes that, and tus makes overriding flags passed to the compiler easier and more reliable.
This is technically a breaking change — but it only affects people using these env variables.

This change was discussed on zulip by members of bootstrap team.

r? @Kobzol

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Nov 13, 2025
@karolzwolak karolzwolak force-pushed the bootstrap-rustflags-precedence branch 2 times, most recently from ce939ab to 456ce9a Compare November 13, 2025 15:59
@karolzwolak
Copy link
Member Author

See also #148795 and #148782 for more context.

@rust-log-analyzer

This comment has been minimized.

@karolzwolak karolzwolak force-pushed the bootstrap-rustflags-precedence branch from 456ce9a to e0750a1 Compare November 13, 2025 16:35
// #71458.
let mut rustdocflags = rustflags.clone();
rustdocflags.propagate_rustflag_envs(build_compiler_stage);
rustdocflags.propagate_cargo_env("RUSTDOCFLAGS");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To uphold the rule that RUSTDOCFLAGS have preference, the env. vars. for rustdocflags should be only propagated after bootstrap sets its flags, right? Near line 1360.

Actually, now that I think about it, the changes from this PR are not enough. Because after being created, the Cargo struct has a rustflag method, which is used in other places in bootstrap to configure additional flags.

So if we really want the external env. var. to override everything, we should only do the actual propagation in impl From<Cargo> for BootstrapCommand, where the rustflags are "materialized".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right on both counts. Kinda sloppy on my side. Will fix that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a comment at the place the env. vars. will be propagated to explain why we do it in this way. Thank you!

Copy link
Member Author

@karolzwolak karolzwolak Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I think it should work now. I also added that comment and slightly changed the name of the PR.

I tested it and seems to be working.
I've run RUSTFLAGS="-Clinker=clang -Clink-arg=--ld-path=wild --verbose" x build and collected the RUSTFLAGS that are send to cargo. They now are at the end as expected.

diff --git a/before b/after
index 65643d6..8dfc789 100644
--- a/before
+++ b/after
@@ -1,8 +1,4 @@
 RUSTFLAGS=
--Clinker=clang
--Clink-arg=--ld-path=wild
---verbose
---cfg=bootstrap
 --cfg=windows_raw_dylib
 -Csymbol-mangling-version=v0
 -Zunstable-options
@@ -21,3 +17,7 @@ RUSTFLAGS=
 -Zdefault-visibility=protected
 -Clto=off
 -Clink-args=-Wl,--icf=all
+-Clinker=clang
+-Clink-arg=--ld-path=wild
+--verbose
+--cfg=bootstrap

EDIT: I've got the filenames mixed up in the diff (I used a for after and b for before 🤦)

@karolzwolak karolzwolak force-pushed the bootstrap-rustflags-precedence branch from e0750a1 to a0015a3 Compare November 14, 2025 17:52
@karolzwolak karolzwolak changed the title Flags from env variables like RUSTFLAGS now have precedence over bootstrap own flags and not the other way around. Flags from *FLAGS* env vars now have precedence over bootstrap own flags and not the other way around. Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants