@@ -343,7 +343,11 @@ fn compute_deps(
343
343
if unit. target . is_custom_build ( ) {
344
344
return Ok ( ret) ;
345
345
}
346
- ret. extend ( dep_build_script ( unit, unit_for, state) ?) ;
346
+ ret. extend (
347
+ dep_build_script ( unit, unit_for, state) ?
348
+ . into_iter ( )
349
+ . flatten ( ) ,
350
+ ) ;
347
351
348
352
// If this target is a binary, test, example, etc, then it depends on
349
353
// the library of the same package. The call to `resolve.deps` above
@@ -645,7 +649,11 @@ fn compute_deps_doc(
645
649
}
646
650
647
651
// Be sure to build/run the build script for documented libraries.
648
- ret. extend ( dep_build_script ( unit, unit_for, state) ?) ;
652
+ ret. extend (
653
+ dep_build_script ( unit, unit_for, state) ?
654
+ . into_iter ( )
655
+ . flatten ( ) ,
656
+ ) ;
649
657
650
658
// If we document a binary/example, we need the library available.
651
659
if unit. target . is_bin ( ) || unit. target . is_example ( ) {
@@ -731,54 +739,57 @@ fn dep_build_script(
731
739
unit : & Unit ,
732
740
unit_for : UnitFor ,
733
741
state : & State < ' _ , ' _ > ,
734
- ) -> CargoResult < Option < UnitDep > > {
735
- unit. pkg
736
- . targets ( )
737
- . iter ( )
738
- . find ( |t| t. is_custom_build ( ) )
739
- . map ( |t| {
740
- // The profile stored in the Unit is the profile for the thing
741
- // the custom build script is running for.
742
- let profile = state. profiles . get_profile_run_custom_build ( & unit. profile ) ;
743
- // UnitFor::for_custom_build is used because we want the `host` flag set
744
- // for all of our build dependencies (so they all get
745
- // build-override profiles), including compiling the build.rs
746
- // script itself.
747
- //
748
- // If `is_for_host_features` here is `false`, that means we are a
749
- // build.rs script for a normal dependency and we want to set the
750
- // CARGO_FEATURE_* environment variables to the features as a
751
- // normal dep.
752
- //
753
- // If `is_for_host_features` here is `true`, that means that this
754
- // package is being used as a build dependency or proc-macro, and
755
- // so we only want to set CARGO_FEATURE_* variables for the host
756
- // side of the graph.
757
- //
758
- // Keep in mind that the RunCustomBuild unit and the Compile
759
- // build.rs unit use the same features. This is because some
760
- // people use `cfg!` and `#[cfg]` expressions to check for enabled
761
- // features instead of just checking `CARGO_FEATURE_*` at runtime.
762
- // In the case with the new feature resolver (decoupled host
763
- // deps), and a shared dependency has different features enabled
764
- // for normal vs. build, then the build.rs script will get
765
- // compiled twice. I believe it is not feasible to only build it
766
- // once because it would break a large number of scripts (they
767
- // would think they have the wrong set of features enabled).
768
- let script_unit_for = unit_for. for_custom_build ( ) ;
769
- new_unit_dep_with_profile (
770
- state,
771
- unit,
772
- & unit. pkg ,
773
- t,
774
- script_unit_for,
775
- unit. kind ,
776
- CompileMode :: RunCustomBuild ,
777
- profile,
778
- IS_NO_ARTIFACT_DEP ,
779
- )
780
- } )
781
- . transpose ( )
742
+ ) -> CargoResult < Option < Vec < UnitDep > > > {
743
+ Some (
744
+ unit. pkg
745
+ . targets ( )
746
+ . iter ( )
747
+ . filter ( |t| t. is_custom_build ( ) )
748
+ . map ( |t| {
749
+ // The profile stored in the Unit is the profile for the thing
750
+ // the custom build script is running for.
751
+ let profile = state. profiles . get_profile_run_custom_build ( & unit. profile ) ;
752
+ // UnitFor::for_custom_build is used because we want the `host` flag set
753
+ // for all of our build dependencies (so they all get
754
+ // build-override profiles), including compiling the build.rs
755
+ // script itself.
756
+ //
757
+ // If `is_for_host_features` here is `false`, that means we are a
758
+ // build.rs script for a normal dependency and we want to set the
759
+ // CARGO_FEATURE_* environment variables to the features as a
760
+ // normal dep.
761
+ //
762
+ // If `is_for_host_features` here is `true`, that means that this
763
+ // package is being used as a build dependency or proc-macro, and
764
+ // so we only want to set CARGO_FEATURE_* variables for the host
765
+ // side of the graph.
766
+ //
767
+ // Keep in mind that the RunCustomBuild unit and the Compile
768
+ // build.rs unit use the same features. This is because some
769
+ // people use `cfg!` and `#[cfg]` expressions to check for enabled
770
+ // features instead of just checking `CARGO_FEATURE_*` at runtime.
771
+ // In the case with the new feature resolver (decoupled host
772
+ // deps), and a shared dependency has different features enabled
773
+ // for normal vs. build, then the build.rs script will get
774
+ // compiled twice. I believe it is not feasible to only build it
775
+ // once because it would break a large number of scripts (they
776
+ // would think they have the wrong set of features enabled).
777
+ let script_unit_for = unit_for. for_custom_build ( ) ;
778
+ new_unit_dep_with_profile (
779
+ state,
780
+ unit,
781
+ & unit. pkg ,
782
+ t,
783
+ script_unit_for,
784
+ unit. kind ,
785
+ CompileMode :: RunCustomBuild ,
786
+ profile,
787
+ IS_NO_ARTIFACT_DEP ,
788
+ )
789
+ } )
790
+ . collect ( ) ,
791
+ )
792
+ . transpose ( )
782
793
}
783
794
784
795
/// Choose the correct mode for dependencies.
0 commit comments