Skip to content

Add an option to cc_* rules that lets one specify include directories only for the current rule #2670

Closed

Description

@lberki

Currently, this is done by copts=["-I<dir>"] .This has two problems:

  • The actual include path depends on whether the rule is in the main repository or not (it shouldn't, but it'll take a lot of time to fix that)
  • It encodes knowledge about the compiler used in the BUILD file.

Thus, it'd be better to express this in a compiler-independent way just like we have the includes and defines attributes.

Activity

  1. added
    P2
    on Mar 13, 2017
  2. dflems commented on Mar 13, 2017

    @dflems
    Contributor

    This would solve a lot of problems we're having migrating a large legacy library to build with bazel. Having an option like private_includes or something of that nature on cc_* rules would be enormously beneficial and make our current setup less fragile.

  3. added this to the 0.6 milestone on Mar 14, 2017
  4. c-parsons commented on Jun 21, 2017

    @c-parsons
    Contributor

    Any work going on with this?
    I've looked, and it doesn't look like there's a good workaround for this other than an actual native code change.

    IIUC, it just looks like we need an alternate attribute which acts identically to "includes" except that it does not propagate these values up to dependents.

  5. dflems commented on Jun 21, 2017

    @dflems
    Contributor

    @c-parsons: We could work around it pretty readily if we had a way to get the path to the directory represented by the current BUILD file. I know you can get that from a skylark rule, but we use some pretty simple macro wrappers and that feels a bit overkill.

  6. c-parsons commented on Jun 21, 2017

    @c-parsons
    Contributor

    Correct -- You can get it from a rule context either natively or in skylark.
    But skylark macros don't have a rule context object -- they are not actual rules but simple expansions.
    So unfortunately I don't think there's a workaround within a macro.

    I agree that writing a skylark rule for this is overkill, especially when it would be infeasible to emulate cc_library except with the added attribute.
    We're better off fixing this natively, IMO

  7. dflems commented on Jun 26, 2017

    @dflems
    Contributor

    I think I was able to figure out a (perhaps less-than-ideal) workaround for this.

    In our wrapper macro for objc_library, I added a new field called private_includes. If our macro sees this field, it creates a header-only objc_library and adds it to non_propagated_deps so the includes aren't passed to anyone who depends upon the library:

    def my_objc_library(**args):
        include_dirs = args.pop('private_includes', None)
        if include_dirs:
            priv_name = args['name'] + '_incl_private'
            native.objc_library(
                name = priv_name,
                includes = include_dirs,
                hdrs = native.glob([dir + '/**/*.h' for dir in include_dirs]),
                visibility = ['//visibility:private'],
            )
            args['non_propagated_deps'] = args.pop('non_propagated_deps', []) + [':' + priv_name]
    
        native.objc_library(**args)

    @c-parsons Do you think this could serve as an interim solution until we get support for this natively?

  8. c-parsons commented on Jun 26, 2017

    @c-parsons
    Contributor

    This is a really nice idea, indeed. This workaround LGTM. Does it work for you?

  9. dflems commented on Jun 26, 2017

    @dflems
    Contributor

    @c-parsons: Yup, already migrated everything to use this approach 😄

  10. modified the milestones: , 0.6 on Sep 3, 2017
  11. silvester747 commented on Oct 12, 2017

    @silvester747

    The workaround using objc_library looks pretty good, but there does not seem to be an equivalent for cc_library, or is there?

  12. 8 remaining items

  13. removed this from the milestone on Mar 14, 2019
  14. alanfalloon commented on Mar 29, 2019

    @alanfalloon
    Contributor

    Does this work-around still work? I don't see a non_propagated_deps attribute on objc_library. Any chance we will see a real option soon?

    Having a makefile variable with the current package path so that I could write copts=["-I$(PACKAGEDIR)/include"] would also work for me.

  15. meisterT commented on May 12, 2020

    @meisterT
    Member
  16. oquenchil commented on May 12, 2020

    @oquenchil
    Contributor

    Duplicate of #6790

  17. added a commit that references this issue on Dec 4, 2020
  18. added a commit that references this issue on Feb 28, 2021
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

    P2duplicateteam-Rules-CPPtype: feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions