@@ -90,6 +90,14 @@ fn build_dependencies_inner(
90
90
build. arg ( format ! ( "--target={target}" ) ) ;
91
91
}
92
92
93
+ if let Some ( packages) = & info. build_std {
94
+ if packages. is_empty ( ) {
95
+ build. arg ( "-Zbuild-std" ) ;
96
+ } else {
97
+ build. arg ( format ! ( "-Zbuild-std={packages}" ) ) ;
98
+ }
99
+ }
100
+
93
101
// Reusable closure for setting up the environment both for artifact generation and `cargo_metadata`
94
102
let set_locking = |cmd : & mut Command | {
95
103
if let OutputConflictHandling :: Error = config. output_conflict_handling {
@@ -166,15 +174,18 @@ fn build_dependencies_inner(
166
174
. target
167
175
. crate_types
168
176
. iter ( )
169
- . all ( |ctype| !matches ! ( ctype. as_str( ) , "proc-macro" | "lib" ) )
177
+ . all ( |ctype| !matches ! ( ctype. as_str( ) , "proc-macro" | "lib" | "rlib" ) )
170
178
{
171
179
continue ;
172
180
}
173
181
for filename in & artifact. filenames {
174
182
import_paths. insert ( filename. parent ( ) . unwrap ( ) . into ( ) ) ;
175
183
}
176
184
let package_id = artifact. package_id ;
177
- if let Some ( prev) = artifacts. insert ( package_id. clone ( ) , Ok ( artifact. filenames ) ) {
185
+ if let Some ( prev) = artifacts. insert (
186
+ package_id. clone ( ) ,
187
+ Ok ( ( artifact. target . name , artifact. filenames ) ) ,
188
+ ) {
178
189
artifacts. insert (
179
190
package_id. clone ( ) ,
180
191
Err ( format ! (
@@ -252,7 +263,7 @@ fn build_dependencies_inner(
252
263
. unwrap ( ) ;
253
264
254
265
// Then go over all of its dependencies
255
- let dependencies = root
266
+ let mut dependencies = root
256
267
. dependencies
257
268
. iter ( )
258
269
. filter ( |dep| matches ! ( dep. kind, DependencyKind :: Normal ) )
@@ -284,7 +295,7 @@ fn build_dependencies_inner(
284
295
let id = & package. id ;
285
296
// Return the name chosen in `Cargo.toml` and the path to the corresponding artifact
286
297
match artifacts. remove ( id) {
287
- Some ( Ok ( artifacts) ) => Some ( Ok ( ( name. replace ( '-' , "_" ) , artifacts) ) ) ,
298
+ Some ( Ok ( ( _ , artifacts) ) ) => Some ( Ok ( ( name. replace ( '-' , "_" ) , artifacts) ) ) ,
288
299
Some ( Err ( what) ) => Some ( Err ( Errored {
289
300
command : Command :: new ( what) ,
290
301
errors : vec ! [ ] ,
@@ -306,6 +317,28 @@ fn build_dependencies_inner(
306
317
. collect :: < Result < Vec < _ > , Errored > > ( ) ?;
307
318
let import_paths = import_paths. into_iter ( ) . collect ( ) ;
308
319
let import_libs = import_libs. into_iter ( ) . collect ( ) ;
320
+
321
+ if info. build_std . is_some ( ) {
322
+ let mut build_std_crates = HashSet :: new ( ) ;
323
+ build_std_crates. insert ( "core" ) ;
324
+ build_std_crates. insert ( "alloc" ) ;
325
+ build_std_crates. insert ( "proc_macro" ) ;
326
+ build_std_crates. insert ( "panic_unwind" ) ;
327
+ build_std_crates. insert ( "compiler_builtins" ) ;
328
+ build_std_crates. insert ( "std" ) ;
329
+ build_std_crates. insert ( "test" ) ;
330
+ build_std_crates. insert ( "panic_abort" ) ;
331
+
332
+ for ( name, artifacts) in artifacts
333
+ . into_iter ( )
334
+ . filter_map ( |( _, artifacts) | artifacts. ok ( ) )
335
+ {
336
+ if build_std_crates. remove ( name. as_str ( ) ) {
337
+ dependencies. push ( ( format ! ( "noprelude:{name}" ) , artifacts) ) ;
338
+ }
339
+ }
340
+ }
341
+
309
342
return Ok ( Dependencies {
310
343
dependencies,
311
344
import_paths,
@@ -329,13 +362,17 @@ pub struct DependencyBuilder {
329
362
/// The command to run can be changed from `cargo` to any custom command to build the
330
363
/// dependencies in `crate_manifest_path`.
331
364
pub program : CommandBuilder ,
365
+ /// Build with [`build-std`](https://doc.rust-lang.org/1.78.0/cargo/reference/unstable.html#build-std),
366
+ /// which requires the nightly toolchain. The [`String`] can contain the standard library crates to build.
367
+ pub build_std : Option < String > ,
332
368
}
333
369
334
370
impl Default for DependencyBuilder {
335
371
fn default ( ) -> Self {
336
372
Self {
337
373
crate_manifest_path : PathBuf :: from ( "Cargo.toml" ) ,
338
374
program : CommandBuilder :: cargo ( ) ,
375
+ build_std : None ,
339
376
}
340
377
}
341
378
}
@@ -381,6 +418,11 @@ pub fn build_dependencies(
381
418
) -> Result < Vec < OsString > , Errored > {
382
419
let dependencies = build_dependencies_inner ( config, info) ?;
383
420
let mut args = vec ! [ ] ;
421
+
422
+ if info. build_std . is_some ( ) {
423
+ args. push ( "-Zunstable-options" . into ( ) ) ;
424
+ }
425
+
384
426
for ( name, artifacts) in dependencies. dependencies {
385
427
for dependency in artifacts {
386
428
args. push ( "--extern" . into ( ) ) ;
0 commit comments