@@ -159,14 +159,31 @@ impl SysrootBuilder {
159
159
/// Prepare to create a new sysroot in the given folder (that folder should later be passed to
160
160
/// rustc via `--sysroot`), for the given target.
161
161
pub fn new ( sysroot_dir : & Path , target : impl Into < OsString > ) -> Self {
162
+ let default_flags = & [
163
+ // This is usually set by bootstrap via `RUSTC_FORCE_UNSTABLE`.
164
+ "-Zforce-unstable-if-unmarked" ,
165
+ // Don't fail when there are lints.
166
+ // The whole point of this crate is to build the standard library in nonstandard
167
+ // configurations, which may trip lints due to untested combinations of cfgs.
168
+ // Cargo applies --cap-lints=allow or --cap-lints=warn when handling -Zbuild-std, which we
169
+ // of course are not using:
170
+ // https://github.com/rust-lang/cargo/blob/2ce45605d9db521b5fd6c1211ce8de6055fdb24e/src/cargo/core/compiler/mod.rs#L899
171
+ // https://github.com/rust-lang/cargo/blob/2ce45605d9db521b5fd6c1211ce8de6055fdb24e/src/cargo/core/compiler/unit.rs#L102-L109
172
+ // All the standard library crates are path dependencies, and they also sometimes pull in
173
+ // separately-maintained crates like backtrace by treating their crate roots as module
174
+ // roots. If we do not cap lints, we can get lint failures outside core or std.
175
+ // We cannot set --cap-lints=allow because Cargo needs to parse warnings to understand the
176
+ // output of --print=file-names for crate-types that the target does not support.
177
+ "--cap-lints=warn" ,
178
+ ] ;
162
179
SysrootBuilder {
163
180
sysroot_dir : sysroot_dir. to_owned ( ) ,
164
181
target : target. into ( ) ,
165
182
config : SysrootConfig :: WithStd {
166
183
std_features : vec ! [ ] ,
167
184
} ,
168
185
mode : BuildMode :: Build ,
169
- rustflags : vec ! [ ] ,
186
+ rustflags : default_flags . iter ( ) . map ( Into :: into ) . collect ( ) ,
170
187
cargo : None ,
171
188
rustc_version : None ,
172
189
}
@@ -375,25 +392,6 @@ path = "lib.rs"
375
392
None => rustc_version:: version_meta ( ) ?,
376
393
} ;
377
394
378
- // The whole point of this crate is to build the standard library in nonstandard
379
- // configurations, which may trip lints due to untested combinations of cfgs.
380
- // Cargo applies --cap-lints=allow or --cap-lints=warn when handling -Zbuild-std, which we
381
- // of course are not using:
382
- // https://github.com/rust-lang/cargo/blob/2ce45605d9db521b5fd6c1211ce8de6055fdb24e/src/cargo/core/compiler/mod.rs#L899
383
- // https://github.com/rust-lang/cargo/blob/2ce45605d9db521b5fd6c1211ce8de6055fdb24e/src/cargo/core/compiler/unit.rs#L102-L109
384
- // All the standard library crates are path dependencies, and they also sometimes pull in
385
- // separately-maintained crates like backtrace by treating their crate roots as module
386
- // roots. If we do not cap lints, we can get lint failures outside core or std.
387
- // We cannot set --cap-lints=allow because Cargo needs to parse warnings to understand the
388
- // output of --print=file-names for crate-types that the target does not support.
389
- if !self . rustflags . iter ( ) . any ( |flag| {
390
- // FIXME: OsStr::as_encoded_bytes is cleaner here
391
- flag. to_str ( )
392
- . map_or ( false , |f| f. starts_with ( "--cap-lints" ) )
393
- } ) {
394
- self . rustflags . push ( "--cap-lints=warn" . into ( ) ) ;
395
- }
396
-
397
395
// Check if we even need to do anything.
398
396
let cur_hash = self . sysroot_compute_hash ( src_dir, & rustc_version) ?;
399
397
if self . sysroot_read_hash ( ) == Some ( cur_hash) {
@@ -432,9 +430,7 @@ path = "lib.rs"
432
430
cmd. arg ( "--target" ) ;
433
431
cmd. arg ( & self . target ) ;
434
432
// Set rustflags.
435
- let mut flags = self . rustflags ;
436
- flags. push ( "-Zforce-unstable-if-unmarked" . into ( ) ) ;
437
- cmd. env ( "CARGO_ENCODED_RUSTFLAGS" , encode_rustflags ( & flags) ) ;
433
+ cmd. env ( "CARGO_ENCODED_RUSTFLAGS" , encode_rustflags ( & self . rustflags ) ) ;
438
434
// Make sure the results end up where we expect them.
439
435
let build_target_dir = build_dir. path ( ) . join ( "target" ) ;
440
436
cmd. env ( "CARGO_TARGET_DIR" , & build_target_dir) ;
0 commit comments