@@ -515,6 +515,31 @@ fn dep_build_script<'a>(
515
515
. bcx
516
516
. profiles
517
517
. get_profile_run_custom_build ( & unit. profile ) ;
518
+ // UnitFor::new_build is used because we want the `host` flag set
519
+ // for all of our build dependencies (so they all get
520
+ // build-override profiles), including compiling the build.rs
521
+ // script itself.
522
+ //
523
+ // If `is_for_build_dep` here is `false`, that means we are a
524
+ // build.rs script for a normal dependency and we want to set the
525
+ // CARGO_FEATURE_* environment variables to the features as a
526
+ // normal dep.
527
+ //
528
+ // If `is_for_build_dep` here is `true`, that means that this
529
+ // package is being used as a build dependency, and so we only
530
+ // want to set CARGO_FEATURE_* variables for the build-dependency
531
+ // side of the graph.
532
+ //
533
+ // Keep in mind that the RunCustomBuild unit and the Compile
534
+ // build.rs unit use the same features. This is because some
535
+ // people use `cfg!` and `#[cfg]` expressions to check for enabled
536
+ // features instead of just checking `CARGO_FEATURE_*` at runtime.
537
+ // In the case with `-Zfeatures=build_dep`, and a shared
538
+ // dependency has different features enabled for normal vs. build,
539
+ // then the build.rs script will get compiled twice. I believe it
540
+ // is not feasible to only build it once because it would break a
541
+ // large number of scripts (they would think they have the wrong
542
+ // set of features enabled).
518
543
let script_unit_for = UnitFor :: new_build ( unit_for. is_for_build_dep ( ) ) ;
519
544
new_unit_dep_with_profile (
520
545
state,
0 commit comments