Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: local_includes for cc_library, making an easy path for good cross-platform hygiene #16472

Open
cpsauer opened this issue Oct 14, 2022 · 2 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@cpsauer
Copy link
Contributor

cpsauer commented Oct 14, 2022

Hi wonderful Bazelers,

This is a small-scope cc feature request.

As background: cc_library lets you specify include directories for its headers, automatically handling the package. This is very nice for interface headers but bad problematic for implementation headers you don't want to propagate to dependents. The docs steer you to add -I flags to copts to handle that case.

The problem is that this leads people to write code that won't work with toolchains where the flags are different. And needing to figure out that you have to use package_name() (which doesn't handle the external workspace case) tends to lead users to just make all includes public, propagating them to all dependencies. Bad times.

A fairly simple new parameter, local_includes could solve this well, I'd propose. What do you think?

Thanks,
Chris
(ex-Googler)
P.S. Edited from the template for clarity, brevity, and friendliness.

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Oct 26, 2022
@cameron-martin
Copy link
Contributor

This same idea was also mentioned here: #13803 (comment)

@kon72
Copy link

kon72 commented Feb 2, 2024

+1 for local_includes.

I think this can be achived with implementation_deps

def custom_cc_library(
        name,
        local_includes = [],
        implementation_deps = [],
        **kwargs):
    native.cc_library(
        name = name + "_local_includes",
        includes = local_includes,
        visibility = ["//visibility:private"],
    )

    native.cc_library(
        name = name,
        implementation_deps = implementation_deps + [name + "_local_includes"],
        **kwargs
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants