You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
includes and defines should not propagate further than direct dependents #3271
cc_library's defines and includes attributes propagate to all transitive dependents. This leads to unwanted includes and defines. There should be finer control that affects only the direct dependents.
Have you found anything relevant by searching the web?
The recommendation of "All include paths should be relative to the workspace directory." requires changing existing code which try to avoid for migrating existing code. copts does not propagate but it requires all the dependents (in case they need the header) to add the copts.
Our code are modularized into separate directories, e.g.
moduleA/a.c
moduleA/a.h
moduleB/b.c
moduleB/b.h
moduleC/c.c
moduleC/c.h
And each .c file doesn't use the path from workspace root. Dependency of moduleB on moduleA will put the flag -ImoduleA in compilation arguments. As you can imagine the list of -I that we'll need in copts will get long down the dependency graph. The alternative route that Bazel provides (i.e. includes) affect all transitive dependents which is not desirable.
We may have a scenario that happens to defines as well where we want -D to be passed down to direct dependents but not further.
Any more comments for this FR? The fact is I do want the copts and includes to be propogated, but only the direct dependents. Right now I have to do this copts = ["-I%s/something" % PACKAGE_NAME] for all direct dependents which is very terse. includes and defines however are very intrusive that affects all transitive dependents.
Can you please elaborate on the use case more? Right now we have behaviors that only affect srcs (such as copts), or is fully transitive (like defines). Not having much experience with GN/GYP builds, nor with the chromium build, is this 'only-direct-dependants' thing something that needs to be done often in practice? Isn't it more future-proof to allow fully transitive behavior (or maybe the dependants should actually be srcs)? I guess I need more convincing of the importance of this feature in the wild.
Activity
hlopko commentedon Jun 27, 2017
We have #2670 for includes, would that solve your problems? Do you have an usecase for doing the same for defines?
kchodorow commentedon Jun 27, 2017
Also, as Ming mentioned, you can use copts. That does not propagate. That's actually what we recommend: https://bazel.build/versions/master/docs/best-practices.html#include-paths.
hlopko commentedon Jun 27, 2017
+1 what Kristina said, although we're aware that
coptsare not platform independent and require usingselectto make them so.hhclam commentedon Jun 27, 2017
The recommendation of "All include paths should be relative to the workspace directory." requires changing existing code which try to avoid for migrating existing code. copts does not propagate but it requires all the dependents (in case they need the header) to add the copts.
Our code are modularized into separate directories, e.g.
moduleA/a.c
moduleA/a.h
moduleB/b.c
moduleB/b.h
moduleC/c.c
moduleC/c.h
And each .c file doesn't use the path from workspace root. Dependency of moduleB on moduleA will put the flag -ImoduleA in compilation arguments. As you can imagine the list of -I that we'll need in copts will get long down the dependency graph. The alternative route that Bazel provides (i.e. includes) affect all transitive dependents which is not desirable.
We may have a scenario that happens to defines as well where we want -D to be passed down to direct dependents but not further.
I think a feature like "direct_dependent_copts" will work great for these cases. This allows a rule to affect the copts to its direct dependents only. This is similar to "direct_dependent_settings" in GYP: https://gyp.gsrc.io/docs/InputFormatReference.md#Dependent-Settings that the Chromium project used before. The tricky bit is when a rule wants to re-export copts from its parent, GYP solved this problem with "export_dependent_settings": https://chromium.googlesource.com/experimental/chromium/src/+/refs/wip/bajones/webvr/tools/gn/docs/cookbook.md#Dependent-settings. GN does it with "public_deps". And in Bazel this could be solved by "reexport_deps".
It seems to me this is a missing feature to fine tune the propagation of includes, copts and defines.
hhclam commentedon Aug 7, 2017
Any more comments for this FR? The fact is I do want the copts and includes to be propogated, but only the direct dependents. Right now I have to do this copts = ["-I%s/something" % PACKAGE_NAME] for all direct dependents which is very terse. includes and defines however are very intrusive that affects all transitive dependents.
hlopko commentedon Aug 16, 2017
Can you please elaborate on the use case more? Right now we have behaviors that only affect srcs (such as copts), or is fully transitive (like defines). Not having much experience with GN/GYP builds, nor with the chromium build, is this 'only-direct-dependants' thing something that needs to be done often in practice? Isn't it more future-proof to allow fully transitive behavior (or maybe the dependants should actually be srcs)? I guess I need more convincing of the importance of this feature in the wild.
oquenchil commentedon May 12, 2020
Duplicate of #11369