@@ -766,6 +766,8 @@ pub struct UnitFor {
766766 /// A target for `build.rs` or any of its dependencies, or a proc-macro or
767767 /// any of its dependencies. This enables `build-override` profiles for
768768 /// these targets.
769+ ///
770+ /// An invariant is that if `build_dep` is true, `host` must be true.
769771 host : bool ,
770772 /// A target for a build dependency (or any of its dependencies). This is
771773 /// used for computing features of build dependencies independently of
@@ -775,7 +777,28 @@ pub struct UnitFor {
775777 /// for a non-host package sets this to `false` because it wants the
776778 /// features of the non-host package (whereas `host` is true because the
777779 /// build script is being built for the host). `build_dep` becomes `true`
778- /// for build-dependencies, or any of their dependencies.
780+ /// for build-dependencies, or any of their dependencies. For example, with
781+ /// this dependency tree:
782+ ///
783+ /// ```text
784+ /// foo
785+ /// ├── foo build.rs
786+ /// │ └── shared_dep (BUILD dependency)
787+ /// │ └── shared_dep build.rs
788+ /// └── shared_dep (Normal dependency)
789+ /// └── shared_dep build.rs
790+ /// ```
791+ ///
792+ /// In this example, `foo build.rs` is HOST=true, BUILD_DEP=false. This is
793+ /// so that `foo build.rs` gets the profile settings for build scripts
794+ /// (HOST=true) and features of foo (BUILD_DEP=false) because build scripts
795+ /// need to know which features their package is being built with.
796+ ///
797+ /// But in the case of `shared_dep`, when built as a build dependency,
798+ /// both flags are true (it only wants the build-dependency features).
799+ /// When `shared_dep` is built as a normal dependency, then `shared_dep
800+ /// build.rs` is HOST=true, BUILD_DEP=false for the same reasons that
801+ /// foo's build script is set that way.
779802 build_dep : bool ,
780803 /// How Cargo processes the `panic` setting or profiles. This is done to
781804 /// handle test/benches inheriting from dev/release, as well as forcing
@@ -883,6 +906,9 @@ impl UnitFor {
883906 /// This is part of the machinery responsible for handling feature
884907 /// decoupling for build dependencies in the new feature resolver.
885908 pub fn with_build_dep ( mut self , build_dep : bool ) -> UnitFor {
909+ if build_dep {
910+ assert ! ( self . host) ;
911+ }
886912 self . build_dep = self . build_dep || build_dep;
887913 self
888914 }
0 commit comments