@@ -924,17 +924,29 @@ def build_bootstrap_cmd(self, env):
924924 # default toolchain is not nightly.
925925 #
926926 # But that setting has the collateral effect of rust-analyzer also
927- # passing RUSTC_BOOTSTRAP=1 to all x.py invocations too (the various overrideCommand).
928- # For compiling bootstrap that can cause spurious rebuilding of bootstrap when
929- # rust-analyzer x.py invocations are interleaved with handwritten ones on the
930- # command line.
927+ # passing RUSTC_BOOTSTRAP=1 to all x.py invocations too (the various
928+ # overrideCommand).
931929 #
932- # Set RUSTC_BOOTSTRAP=1 consistently.
930+ # Set a consistent RUSTC_BOOTSTRAP=1 here to prevent spurious rebuilds
931+ # of bootstrap when rust-analyzer x.py invocations are interleaved with
932+ # handwritten ones on the command line.
933933 env ["RUSTC_BOOTSTRAP" ] = "1"
934934
935- default_rustflags = "" if env .get ("RUSTFLAGS_BOOTSTRAP" , "" ) else "-Zallow-features="
936-
937- env .setdefault ("RUSTFLAGS" , default_rustflags )
935+ # If any of RUSTFLAGS or RUSTFLAGS_BOOTSTRAP are present and nonempty,
936+ # we allow arbitrary compiler flags in there, including unstable ones
937+ # such as `-Zthreads=8`.
938+ #
939+ # But if there aren't custom flags being passed to bootstrap, then we
940+ # cancel the RUSTC_BOOTSTRAP=1 from above by passing `-Zallow-features=`
941+ # to ensure unstable language or library features do not accidentally
942+ # get introduced into bootstrap over time. Distros rely on being able to
943+ # compile bootstrap with a variety of their toolchains, not necessarily
944+ # the same as Rust's CI uses.
945+ if env .get ("RUSTFLAGS" , "" ) or env .get ("RUSTFLAGS_BOOTSTRAP" , "" ):
946+ # Preserve existing RUSTFLAGS.
947+ env .setdefault ("RUSTFLAGS" , "" )
948+ else :
949+ env ["RUSTFLAGS" ] = "-Zallow-features="
938950
939951 target_features = []
940952 if self .get_toml ("crt-static" , build_section ) == "true" :
0 commit comments