@@ -1381,18 +1381,29 @@ impl<'a> Builder<'a> {
1381
1381
// this), as well as #63012 which is the tracking issue for this
1382
1382
// feature on the rustc side.
1383
1383
cargo. arg ( "-Zbinary-dep-depinfo" ) ;
1384
- match mode {
1385
- Mode :: ToolBootstrap => {
1386
- // Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
1387
- rustflags. arg ( "-Zallow-features=binary-dep-depinfo" ) ;
1388
- }
1389
- Mode :: ToolStd => {
1390
- // Right now this is just compiletest and a few other tools that build on stable.
1391
- // Allow them to use `feature(test)`, but nothing else.
1392
- rustflags. arg ( "-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span" ) ;
1384
+ let allow_features = match mode {
1385
+ Mode :: ToolBootstrap | Mode :: ToolStd => {
1386
+ // Restrict the allowed features so we don't depend on nightly
1387
+ // accidentally.
1388
+ //
1389
+ // binary-dep-depinfo is used by rustbuild itself for all
1390
+ // compilations.
1391
+ //
1392
+ // Lots of tools depend on proc_macro2 and proc-macro-error.
1393
+ // Those have build scripts which assume nightly features are
1394
+ // available if the `rustc` version is "nighty" or "dev". See
1395
+ // bin/rustc.rs for why that is a problem. Instead of labeling
1396
+ // those features for each individual tool that needs them,
1397
+ // just blanket allow them here.
1398
+ //
1399
+ // If this is ever removed, be sure to add something else in
1400
+ // its place to keep the restrictions in place (or make a way
1401
+ // to unset RUSTC_BOOTSTRAP).
1402
+ "binary-dep-depinfo,proc_macro_span,proc_macro_span_shrink,proc_macro_diagnostic"
1403
+ . to_string ( )
1393
1404
}
1394
- Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => { }
1395
- }
1405
+ Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
1406
+ } ;
1396
1407
1397
1408
cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
1398
1409
@@ -1915,7 +1926,7 @@ impl<'a> Builder<'a> {
1915
1926
}
1916
1927
}
1917
1928
1918
- Cargo { command : cargo, rustflags, rustdocflags }
1929
+ Cargo { command : cargo, rustflags, rustdocflags, allow_features }
1919
1930
}
1920
1931
1921
1932
/// Ensure that a given step is built, returning its output. This will
@@ -2094,6 +2105,7 @@ pub struct Cargo {
2094
2105
command : Command ,
2095
2106
rustflags : Rustflags ,
2096
2107
rustdocflags : Rustflags ,
2108
+ allow_features : String ,
2097
2109
}
2098
2110
2099
2111
impl Cargo {
@@ -2138,6 +2150,18 @@ impl Cargo {
2138
2150
self . command . current_dir ( dir) ;
2139
2151
self
2140
2152
}
2153
+
2154
+ /// Adds nightly-only features that this invocation is allowed to use.
2155
+ ///
2156
+ /// By default, all nightly features are allowed. Once this is called, it
2157
+ /// will be restricted to the given set.
2158
+ pub fn allow_features ( & mut self , features : & str ) -> & mut Cargo {
2159
+ if !self . allow_features . is_empty ( ) {
2160
+ self . allow_features . push ( ',' ) ;
2161
+ }
2162
+ self . allow_features . push_str ( features) ;
2163
+ self
2164
+ }
2141
2165
}
2142
2166
2143
2167
impl From < Cargo > for Command {
@@ -2152,6 +2176,10 @@ impl From<Cargo> for Command {
2152
2176
cargo. command . env ( "RUSTDOCFLAGS" , rustdocflags) ;
2153
2177
}
2154
2178
2179
+ if !cargo. allow_features . is_empty ( ) {
2180
+ cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
2181
+ }
2182
+
2155
2183
cargo. command
2156
2184
}
2157
2185
}
0 commit comments