-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Comments
This same idea was also mentioned here: #13803 (comment) |
+1 for local_includes. I think this can be achived with 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
) |
It seems like the behavior people are asking for here was recently added as "strip_include_prefix" https://bazel.build/reference/be/c-cpp#cc_library.strip_include_prefix This name is non-intuitive and IMO it would be much better if "local_includes" was used as suggested in this issue. Is there a way an alias could be added? |
I thought that attribute has been there for ages, and I'm missing how it's the same as local_includes |
I had thought it was added about a year ago? Maybe not. From a bazel user perspective, when exposing headers from a cc_library often people reach for
If it was named |
Oh I see, and you take advantage of the workspace root by default being on the include path? |
No these are all relative paths, not directly on the workspace root. See an example of the pigweed project recently working through migrating off extensive use of |
Thinking about this more, Really you want control over whether |
Non.-propagation is a key feature of the request. This isn't about the headers exposed by the library, but the internal headers used by it. |
Got it, makes sense to leave local_includes for that purpose. I guess I wish there was a better name for what strip_include_prefix does. |
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.
The text was updated successfully, but these errors were encountered: