@@ -21,8 +21,8 @@ use std::process::{Child, Command};
2121use std:: time:: Instant ;
2222
2323use shared_helpers:: {
24- dylib_path, dylib_path_var, exe, maybe_dump, parse_rustc_stage, parse_rustc_verbose ,
25- parse_value_from_args,
24+ FLAGS_FOR_RUSTC , dylib_path, dylib_path_var, exe, maybe_dump, parse_rustc_stage,
25+ parse_rustc_verbose , parse_value_from_args,
2626} ;
2727
2828#[ path = "../utils/shared_helpers.rs" ]
@@ -145,6 +145,35 @@ fn main() {
145145 cmd. arg ( "-Z" ) . arg ( "on-broken-pipe=kill" ) ;
146146 }
147147
148+ // In `cargo.rs` we add the `FLAGS_FOR_RUSTC` flags for all `compiler/`
149+ // crates to RUSTFLAGS. However, RUSTFLAGS is ignored for `compiler/` proc
150+ // macro crates, because RUSTFLAGS is ignored when `--target` is given. So,
151+ // we add the `FLAGS_FOR_RUSTC` flags directly to the command here if they
152+ // are also in RUSTFLAGS.
153+ let crate_type = parse_value_from_args ( & orig_args, "--crate-type" ) ;
154+ if crate_type == Some ( "proc-macro" ) {
155+ if let Ok ( rustflags) = env:: var ( "RUSTFLAGS" ) {
156+ // Count how many of flags from `FLAGS_FOR_RUSTC` are in RUSTFLAGS.
157+ let n = FLAGS_FOR_RUSTC . iter ( ) . filter ( |& flag| rustflags. contains ( flag) ) . count ( ) ;
158+ if n == FLAGS_FOR_RUSTC . len ( ) {
159+ // All the FLAGS_FOR_RUSTC flags are in RUSTFLAGS, which means
160+ // this is a `compiler/` proc macro crate. Insert the flags
161+ // directly into the command.
162+ for flag in shared_helpers:: FLAGS_FOR_RUSTC {
163+ cmd. arg ( flag) ;
164+ }
165+ } else if n == 0 {
166+ // None of the FLAGS_FOR_RUSTC flags are in RUSTFLAGS.
167+ // Therefore it's a non-`compiler/` proc macro crate:
168+ // third-party, clippy, etc. Do nothing.
169+ } else {
170+ // Some but not all of the FLAGS_FOR_RUSTC flags are in
171+ // RUSTFLAGS. Huh?
172+ panic ! ( "RUSTFLAGS is missing some expected flags" ) ;
173+ }
174+ }
175+ }
176+
148177 if target. is_some ( ) {
149178 // The stage0 compiler has a special sysroot distinct from what we
150179 // actually downloaded, so we just always pass the `--sysroot` option,
@@ -165,7 +194,6 @@ fn main() {
165194 cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
166195 }
167196
168- let crate_type = parse_value_from_args ( & orig_args, "--crate-type" ) ;
169197 // `-Ztls-model=initial-exec` must not be applied to proc-macros, see
170198 // issue https://github.com/rust-lang/rust/issues/100530
171199 if env:: var ( "RUSTC_TLS_MODEL_INITIAL_EXEC" ) . is_ok ( )
0 commit comments