@@ -78,6 +78,26 @@ fn cfgs(config: &Config) -> Result<Vec<Cfg>, Errored> {
78
78
Ok ( cfgs)
79
79
}
80
80
81
+ pub ( crate ) fn has_build_std ( info : & DependencyBuilder ) -> bool {
82
+ let mut args = info. program . args . iter ( ) ;
83
+
84
+ while let Some ( arg) = args. next ( ) {
85
+ if arg == "-Z" {
86
+ if let Some ( arg) = args. next ( ) . map ( |arg| arg. to_string_lossy ( ) ) {
87
+ if arg. starts_with ( "build-std" ) {
88
+ return true ;
89
+ }
90
+ }
91
+ }
92
+
93
+ if arg. to_string_lossy ( ) . starts_with ( "-Zbuild-std" ) {
94
+ return true ;
95
+ }
96
+ }
97
+
98
+ false
99
+ }
100
+
81
101
/// Compiles dependencies and returns the crate names and corresponding rmeta files.
82
102
fn build_dependencies_inner (
83
103
config : & Config ,
@@ -166,15 +186,18 @@ fn build_dependencies_inner(
166
186
. target
167
187
. crate_types
168
188
. iter ( )
169
- . all ( |ctype| !matches ! ( ctype. as_str( ) , "proc-macro" | "lib" ) )
189
+ . all ( |ctype| !matches ! ( ctype. as_str( ) , "proc-macro" | "lib" | "rlib" ) )
170
190
{
171
191
continue ;
172
192
}
173
193
for filename in & artifact. filenames {
174
194
import_paths. insert ( filename. parent ( ) . unwrap ( ) . into ( ) ) ;
175
195
}
176
196
let package_id = artifact. package_id ;
177
- if let Some ( prev) = artifacts. insert ( package_id. clone ( ) , Ok ( artifact. filenames ) ) {
197
+ if let Some ( prev) = artifacts. insert (
198
+ package_id. clone ( ) ,
199
+ Ok ( ( artifact. target . name , artifact. filenames ) ) ,
200
+ ) {
178
201
artifacts. insert (
179
202
package_id. clone ( ) ,
180
203
Err ( format ! (
@@ -252,7 +275,7 @@ fn build_dependencies_inner(
252
275
. unwrap ( ) ;
253
276
254
277
// Then go over all of its dependencies
255
- let dependencies = root
278
+ let mut dependencies = root
256
279
. dependencies
257
280
. iter ( )
258
281
. filter ( |dep| matches ! ( dep. kind, DependencyKind :: Normal ) )
@@ -284,7 +307,7 @@ fn build_dependencies_inner(
284
307
let id = & package. id ;
285
308
// Return the name chosen in `Cargo.toml` and the path to the corresponding artifact
286
309
match artifacts. remove ( id) {
287
- Some ( Ok ( artifacts) ) => Some ( Ok ( ( name. replace ( '-' , "_" ) , artifacts) ) ) ,
310
+ Some ( Ok ( ( _ , artifacts) ) ) => Some ( Ok ( ( name. replace ( '-' , "_" ) , artifacts) ) ) ,
288
311
Some ( Err ( what) ) => Some ( Err ( Errored {
289
312
command : Command :: new ( what) ,
290
313
errors : vec ! [ ] ,
@@ -306,6 +329,28 @@ fn build_dependencies_inner(
306
329
. collect :: < Result < Vec < _ > , Errored > > ( ) ?;
307
330
let import_paths = import_paths. into_iter ( ) . collect ( ) ;
308
331
let import_libs = import_libs. into_iter ( ) . collect ( ) ;
332
+
333
+ if has_build_std ( info) {
334
+ let mut build_std_crates = HashSet :: new ( ) ;
335
+ build_std_crates. insert ( "core" ) ;
336
+ build_std_crates. insert ( "alloc" ) ;
337
+ build_std_crates. insert ( "proc_macro" ) ;
338
+ build_std_crates. insert ( "panic_unwind" ) ;
339
+ build_std_crates. insert ( "compiler_builtins" ) ;
340
+ build_std_crates. insert ( "std" ) ;
341
+ build_std_crates. insert ( "test" ) ;
342
+ build_std_crates. insert ( "panic_abort" ) ;
343
+
344
+ for ( name, artifacts) in artifacts
345
+ . into_iter ( )
346
+ . filter_map ( |( _, artifacts) | artifacts. ok ( ) )
347
+ {
348
+ if build_std_crates. remove ( name. as_str ( ) ) {
349
+ dependencies. push ( ( format ! ( "noprelude:{name}" ) , artifacts) ) ;
350
+ }
351
+ }
352
+ }
353
+
309
354
return Ok ( Dependencies {
310
355
dependencies,
311
356
import_paths,
@@ -381,6 +426,11 @@ pub fn build_dependencies(
381
426
) -> Result < Vec < OsString > , Errored > {
382
427
let dependencies = build_dependencies_inner ( config, info) ?;
383
428
let mut args = vec ! [ ] ;
429
+
430
+ if has_build_std ( info) {
431
+ args. push ( "-Zunstable-options" . into ( ) ) ;
432
+ }
433
+
384
434
for ( name, artifacts) in dependencies. dependencies {
385
435
for dependency in artifacts {
386
436
args. push ( "--extern" . into ( ) ) ;
0 commit comments