Skip to content

includes and defines should not propagate further than direct dependents #3271

Closed

Description

@hhclam

Description of feature request:

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?

An opposite example of the existing behavior in Bazel is GN from the Chromium project. Their default behavior of public_configs only affect direct dependents: https://chromium.googlesource.com/chromium/src/tools/gn/+/HEAD/docs/reference.md#public_configs
They define the all_dependent_configs to affect all dependents transitively but it is strongly discouraged.
https://chromium.googlesource.com/chromium/src/tools/gn/+/HEAD/docs/reference.md#all_dependent_configs
With Bazel I have only one option.

Activity

  1. hlopko commented on Jun 27, 2017

    @hlopko
    Member

    We have #2670 for includes, would that solve your problems? Do you have an usecase for doing the same for defines?

  2. self-assigned this
    on Jun 27, 2017
  3. added
    P3
    on Jun 27, 2017
  4. kchodorow commented on Jun 27, 2017

    @kchodorow
    Contributor

    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.

  5. hlopko commented on Jun 27, 2017

    @hlopko
    Member

    +1 what Kristina said, although we're aware that copts are not platform independent and require using select to make them so.

  6. hhclam commented on Jun 27, 2017

    @hhclam
    ContributorAuthor

    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.

  7. hhclam commented on Aug 7, 2017

    @hhclam
    ContributorAuthor

    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.

  8. hlopko commented on Aug 16, 2017

    @hlopko
    Member

    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.

  9. added
    team-Rules-CPP
    and removed on Oct 11, 2018
  10. removed their assignment
    on Dec 6, 2019
  11. added
    untriaged
    on May 11, 2020
  12. oquenchil commented on May 12, 2020

    @oquenchil
    Contributor

    Duplicate of #11369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3team-Rules-CPPtype: feature requestunder investigationuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions