Skip to content

Request: rename includes to system_includes in cc_* functions #20267

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

Open
carlosgalvezp opened this issue Nov 20, 2023 · 9 comments · May be fixed by #25750 or coderabbit-test/bazel#4
Open

Request: rename includes to system_includes in cc_* functions #20267

carlosgalvezp opened this issue Nov 20, 2023 · 9 comments · May be fixed by #25750 or coderabbit-test/bazel#4
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

@carlosgalvezp
Copy link

carlosgalvezp commented Nov 20, 2023

Currently, includes is misleading, since the name does not in any way reflect the fact that the headers will be included as system headers. This goes against developer expectations.

System headers should rarely be used on own code, because all C++ tools (compilers, static analyzers, etc) will ignore warnings in such headers.

It would be a lot clearer and easy to spot during code review if includes was renamed to system_includes.

@carlosgalvezp carlosgalvezp changed the title Request: rename "includes" to "system_includes" in cc_* functions Request: rename includes to system_includes in cc_* functions Nov 20, 2023
@carlosgalvezp carlosgalvezp changed the title Request: rename includes to system_includes in cc_* functions Request: rename includes to system_includes in cc_* functions Nov 20, 2023
@fmeum
Copy link
Collaborator

fmeum commented Nov 20, 2023

@buildbreaker2021 For context, is includes used for any first-party code in google3?

@comius
Copy link
Contributor

comius commented Nov 27, 2023

The attribute is used in our third party.

Improving docs and renaming the attr could help.

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed untriaged labels Nov 27, 2023
@jerrymarino
Copy link
Contributor

A good number of rules in iOS ecosystem add includes use this for both the objc and cc rules. One other consideration is some c++ compilers like clang provide a feature known as "SYSTEM include" path which often has a different usage than Bazel's -I or includes flag:

  -isystem <directory>    Add directory to SYSTEM include search path

@peakschris
Copy link

We use "includes =" a lot for our own includes. We also use it for 3rd party includes that we import via repo rules. It would be good to be able to get Bazel to apply -isystem for 3rd party includes and -I for ours.

I can think of a number of solutions. The simplest is perhaps a transitive_copts option that would give a lot of flexibility.

@carlosgalvezp
Copy link
Author

To clarify: I do not want to remove includes. I want it to be renamed so it's more clear what it does, and avoids misuse.

@armandomontanez
Copy link

This is a huge stumbling block, would love to see an attribute rename to make this harder to get wrong.

keith added a commit to keith/bazel that referenced this issue Apr 1, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267
@keith
Copy link
Member

keith commented Apr 1, 2025

I'm proposing an alternative solution to this here: #25750

keith added a commit to keith/bazel that referenced this issue Apr 1, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267
@armandomontanez
Copy link

There was an alternate proposal here that suggested fixing this by having system_include_dirs and include_dirs attributes.

keith added a commit to keith/bazel that referenced this issue Apr 1, 2025
Previously even though the attribute was named `includes`, the paths
added there were actually propagated through the `system_includes`
attribute of compilation context. This lead to crosstools passing these
flags with `-isystem` which was unexpected for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

Fixes bazelbuild#20267
@keith
Copy link
Member

keith commented Apr 1, 2025

thanks I hadn't seen that! here's an option that adds system_includes on cc_library/cc_binary #25751

keith added a commit to keith/bazel that referenced this issue Apr 2, 2025
Previously even though the attribute was named `includes`, the paths
added there were actually propagated through the `system_includes`
attribute of compilation context. This lead to crosstools passing these
flags with `-isystem` which was unexpected for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

Fixes bazelbuild#20267
keith added a commit to keith/bazel that referenced this issue Apr 2, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267
keith added a commit to keith/bazel that referenced this issue Apr 2, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267
keith added a commit to keith/bazel that referenced this issue Apr 2, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267
keith added a commit to keith/bazel that referenced this issue Apr 2, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267

RELNOTES[INC]: Use `-I` instead of `-isystem` for `cc_library` / `cc_binary` `includes` attr. To use `-isystem` for only external repositories, you can pass `--features=external_include_paths --host_features=external_include_paths`. To use `-isystem` for a single `cc_library` / `cc_binary` `includes`, you can set `features = ["system_include_paths"],` on the target
keith added a commit to keith/bazel that referenced this issue Apr 3, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267

RELNOTES[INC]: Use `-I` instead of `-isystem` for `cc_library` / `cc_binary` `includes` attr. To use `-isystem` for only external repositories, you can pass `--features=external_include_paths --host_features=external_include_paths`. To use `-isystem` for a single `cc_library` / `cc_binary` `includes`, you can set `features = ["system_include_paths"],` on the target
keith added a commit to keith/bazel that referenced this issue Apr 3, 2025
Previously even though the attribute was named `includes` it was passed
through the `system_includes` field of the compilation context. This
resulted in toolchains passing these include paths with `-isystem`,
which is unexpected if you use this for first party code.

Many non bazel-first projects have header directory structures that
require custom include paths be propagated throughout the graph, the
alternative to `includes` is to use `strip_include_prefix`. The downside
of `strip_include_prefix` is that you add 1 include path per
`cc_library`, even if the libraries are in the same package. With
`includes` these are deduplicated. In the case of LLVM using `includes`
reduced the number of search paths on the order of hundreds.

If users want to use `-isystem` for third party code that uses
`includes`, they can pass `--features=external_include_paths --host_features=external_include_paths`

If there are first party libraries users want to use `-isystem` with,
they can use `features = ["system_include_paths"]`

Fixes bazelbuild#20267

RELNOTES[INC]: Use `-I` instead of `-isystem` for `cc_library` / `cc_binary` `includes` attr. To use `-isystem` for only external repositories, you can pass `--features=external_include_paths --host_features=external_include_paths`. To use `-isystem` for a single `cc_library` / `cc_binary` `includes`, you can set `features = ["system_include_paths"],` on the target
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
8 participants