@@ -248,23 +248,25 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
248
248
args. extend ( compiler:: features_args ( unit) ) ;
249
249
args. extend ( compiler:: check_cfg_args ( unit) ) ;
250
250
251
- let script_meta = self . find_build_script_metadata ( unit) ;
252
- if let Some ( meta) = script_meta {
253
- if let Some ( output) = self . build_script_outputs . lock ( ) . unwrap ( ) . get ( meta) {
254
- for cfg in & output. cfgs {
255
- args. push ( "--cfg" . into ( ) ) ;
256
- args. push ( cfg. into ( ) ) ;
257
- }
251
+ let script_metas = self . find_build_script_metadatas ( unit) ;
252
+ if let Some ( meta_vec) = script_metas. clone ( ) {
253
+ for meta in meta_vec {
254
+ if let Some ( output) = self . build_script_outputs . lock ( ) . unwrap ( ) . get ( meta) {
255
+ for cfg in & output. cfgs {
256
+ args. push ( "--cfg" . into ( ) ) ;
257
+ args. push ( cfg. into ( ) ) ;
258
+ }
258
259
259
- for check_cfg in & output. check_cfgs {
260
- args. push ( "--check-cfg" . into ( ) ) ;
261
- args. push ( check_cfg. into ( ) ) ;
262
- }
260
+ for check_cfg in & output. check_cfgs {
261
+ args. push ( "--check-cfg" . into ( ) ) ;
262
+ args. push ( check_cfg. into ( ) ) ;
263
+ }
263
264
264
- for ( lt, arg) in & output. linker_args {
265
- if lt. applies_to ( & unit. target , unit. mode ) {
266
- args. push ( "-C" . into ( ) ) ;
267
- args. push ( format ! ( "link-arg={}" , arg) . into ( ) ) ;
265
+ for ( lt, arg) in & output. linker_args {
266
+ if lt. applies_to ( & unit. target , unit. mode ) {
267
+ args. push ( "-C" . into ( ) ) ;
268
+ args. push ( format ! ( "link-arg={}" , arg) . into ( ) ) ;
269
+ }
268
270
}
269
271
}
270
272
}
@@ -285,7 +287,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
285
287
args,
286
288
unstable_opts,
287
289
linker : self . compilation . target_linker ( unit. kind ) . clone ( ) ,
288
- script_meta ,
290
+ script_metas ,
289
291
env : artifact:: get_env ( & self , self . unit_deps ( unit) ) ?,
290
292
} ) ;
291
293
}
@@ -420,29 +422,40 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
420
422
& self . bcx . unit_graph [ unit]
421
423
}
422
424
423
- /// Returns the `RunCustomBuild` Unit associated with the given Unit.
425
+ /// Returns the `RunCustomBuild` Units associated with the given Unit.
424
426
///
425
427
/// If the package does not have a build script, this returns None.
426
- pub fn find_build_script_unit ( & self , unit : & Unit ) -> Option < Unit > {
428
+ pub fn find_build_script_units ( & self , unit : & Unit ) -> Option < Vec < Unit > > {
427
429
if unit. mode . is_run_custom_build ( ) {
428
- return Some ( unit. clone ( ) ) ;
430
+ return Some ( vec ! [ unit. clone( ) ] ) ;
429
431
}
430
- self . bcx . unit_graph [ unit]
432
+
433
+ let build_script_units: Vec < Unit > = self . bcx . unit_graph [ unit]
431
434
. iter ( )
432
- . find ( |unit_dep| {
435
+ . filter ( |unit_dep| {
433
436
unit_dep. unit . mode . is_run_custom_build ( )
434
437
&& unit_dep. unit . pkg . package_id ( ) == unit. pkg . package_id ( )
435
438
} )
436
439
. map ( |unit_dep| unit_dep. unit . clone ( ) )
440
+ . collect ( ) ;
441
+ if build_script_units. is_empty ( ) {
442
+ None
443
+ } else {
444
+ Some ( build_script_units)
445
+ }
437
446
}
438
447
439
448
/// Returns the metadata hash for the `RunCustomBuild` Unit associated with
440
449
/// the given unit.
441
450
///
442
451
/// If the package does not have a build script, this returns None.
443
- pub fn find_build_script_metadata ( & self , unit : & Unit ) -> Option < UnitHash > {
444
- let script_unit = self . find_build_script_unit ( unit) ?;
445
- Some ( self . get_run_build_script_metadata ( & script_unit) )
452
+ pub fn find_build_script_metadatas ( & self , unit : & Unit ) -> Option < Vec < UnitHash > > {
453
+ self . find_build_script_units ( unit) . map ( |units| {
454
+ units
455
+ . iter ( )
456
+ . map ( |u| self . get_run_build_script_metadata ( u) )
457
+ . collect ( )
458
+ } )
446
459
}
447
460
448
461
/// Returns the metadata hash for a `RunCustomBuild` unit.
@@ -480,11 +493,11 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
480
493
/// Returns a [`UnitOutput`] which represents some information about the
481
494
/// output of a unit.
482
495
pub fn unit_output ( & self , unit : & Unit , path : & Path ) -> UnitOutput {
483
- let script_meta = self . find_build_script_metadata ( unit) ;
496
+ let script_metas = self . find_build_script_metadatas ( unit) ;
484
497
UnitOutput {
485
498
unit : unit. clone ( ) ,
486
499
path : path. to_path_buf ( ) ,
487
- script_meta ,
500
+ script_metas ,
488
501
}
489
502
}
490
503
0 commit comments