Skip to content

Commit dc30258

Browse files
committed
Pass --cfg=bootstrap for proc_macros or build scripts built by stage0
Cargo ignores RUSTFLAGS when building proc macro crates. However, sometimes rustc_macro needs to have conditional compilation when there are breaking changes to the `libproc_macro` API (see for example tell the difference between stage 0 and stage 1. Another alternative is to unconditionally build rustc_macros with the master libstd instead of the beta one (i.e. use `--sysroot stage0-sysroot`), but that led to strange and maddening errors: ``` error[E0460]: found possibly newer version of crate `std` which `proc_macro2` depends on --> /home/joshua/.local/lib/cargo/registry/src/github.com-1ecc6299db9ec823/tracing-attributes-0.1.13/src/lib.rs:90:5 | 90 | use proc_macro2::TokenStream; | ^^^^^^^^^^^ | = note: perhaps that crate needs to be recompiled? = note: the following crate versions were found: crate `std`: /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/stage0-sysroot/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-b3602c301b71cc3d.rmeta crate `proc_macro2`: /home/joshua/rustc2/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps/libproc_macro2-a83c1f01610c129e.rlib ```
1 parent c4c2ab5 commit dc30258

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/bootstrap/bin/rustc.rs

+7
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ fn main() {
124124
cmd.arg("-C").arg("target-feature=-crt-static");
125125
}
126126
}
127+
128+
if stage == "0" {
129+
// Cargo doesn't pass RUSTFLAGS to proc_macros:
130+
// https://github.com/rust-lang/cargo/issues/4423
131+
// Set `--cfg=bootstrap` explicitly instead.
132+
cmd.arg("--cfg=bootstrap");
133+
}
127134
}
128135

129136
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {

0 commit comments

Comments
 (0)