@@ -248,23 +248,25 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
248248 args. extend ( compiler:: features_args ( unit) ) ;
249249 args. extend ( compiler:: check_cfg_args ( unit) ) ;
250250
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+ }
258259
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+ }
263264
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+ }
268270 }
269271 }
270272 }
@@ -285,7 +287,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
285287 args,
286288 unstable_opts,
287289 linker : self . compilation . target_linker ( unit. kind ) . clone ( ) ,
288- script_meta ,
290+ script_metas ,
289291 env : artifact:: get_env ( & self , self . unit_deps ( unit) ) ?,
290292 } ) ;
291293 }
@@ -420,29 +422,40 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
420422 & self . bcx . unit_graph [ unit]
421423 }
422424
423- /// Returns the `RunCustomBuild` Unit associated with the given Unit.
425+ /// Returns the `RunCustomBuild` Units associated with the given Unit.
424426 ///
425427 /// 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 > > {
427429 if unit. mode . is_run_custom_build ( ) {
428- return Some ( unit. clone ( ) ) ;
430+ return Some ( vec ! [ unit. clone( ) ] ) ;
429431 }
430- self . bcx . unit_graph [ unit]
432+
433+ let build_script_units: Vec < Unit > = self . bcx . unit_graph [ unit]
431434 . iter ( )
432- . find ( |unit_dep| {
435+ . filter ( |unit_dep| {
433436 unit_dep. unit . mode . is_run_custom_build ( )
434437 && unit_dep. unit . pkg . package_id ( ) == unit. pkg . package_id ( )
435438 } )
436439 . 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+ }
437446 }
438447
439448 /// Returns the metadata hash for the `RunCustomBuild` Unit associated with
440449 /// the given unit.
441450 ///
442451 /// 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+ } )
446459 }
447460
448461 /// Returns the metadata hash for a `RunCustomBuild` unit.
@@ -480,11 +493,11 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
480493 /// Returns a [`UnitOutput`] which represents some information about the
481494 /// output of a unit.
482495 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) ;
484497 UnitOutput {
485498 unit : unit. clone ( ) ,
486499 path : path. to_path_buf ( ) ,
487- script_meta ,
500+ script_metas ,
488501 }
489502 }
490503
0 commit comments