bazelbuild / bazelbuild/rules_cc

[toolchains] `allowlist_include_directories` does not work on non-absolute paths

Open
#277 12 comments 0 reactions 1 assignee Claimed by @armandomontanez View on GitHub
category: toolchains P3
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

A while back while rolling through Bazel updates I noticed changes in behaviors to `cxx_builtin_include_directories` (`allowlist_include_directories` in rule-based toolchains) where it seemed to stop properly allowlisting toolchain builtin include paths.
Inspired by https://github.com/bazelbuild/bazel/pull/23615, I wanted to create a minimal reproducer, which is pretty easy:

```diff
diff --git a/examples/rule_based_toolchain/toolchain/BUILD.bazel b/examples/rule_based_toolchain/toolchain/BUILD.bazel
index 58e3540..b95f795 100644
--- a/examples/rule_based_toolchain/toolchain/BUILD.bazel
+++ b/examples/rule_based_toolchain/toolchain/BUILD.bazel
@@ -24,7 +24,6 @@ cc_toolchain(
],
"//conditions:default": [],
}) + [
- "//toolchain/args:no_canonical_prefixes",
"//toolchain/args:warnings",
],
enabled_features = ["@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features"],
diff --git a/examples/rule_based_toolchain/toolchain/tools/BUILD.bazel b/examples/rule_based_toolchain/toolchain/tools/BUILD.bazel
index ccd0060..9f57c0c 100644
--- a/examples/rule_based_toolchain/toolchain/tools/BUILD.bazel
+++ b/examples/rule_based_toolchain/toolchain/tools/BUILD.bazel
@@ -64,6 +64,16 @@ cc_tool(
":exec_platform_builtin_headers",
":exec_platform_multicall_support_files",
],
+ allowlist_include_directories = [
+ "@linux_sysroot//:usr-include-x86_64-linux-gnu",
+ ] + select({
+ "//constraint:linux_aarch64": [
+ "@clang-linux-aarch64//:lib-clang-include",
+ ],
+ "//constraint:linux_x86_64": [
+ "@clang-linux-x86_64//:lib-clang-include",
+ ],
+ }),
)

cc_tool(
@@ -76,6 +86,16 @@ cc_tool(
":exec_platform_builtin_headers",
":exec_platform_multicall_support_files",
],
+ allowlist_include_directories = select({
+ "//constraint:linux_aarch64": [
+ "@clang-linux-aarch64//:include-c++-v1",
+ "@clang-linux-aarch64//:include-x86_64-unknown-linux-gnu-c++-v1",
+ ],
+ "//constraint:linux_x86_64": [
+ "@clang-linux-x86_64//:include-c++-v1",
+ "@clang-linux-x86_64//:include-x86_64-unknown-linux-gnu-c++-v1",
+ ],
+ }),
)

cc_tool(
```

This fails as seen below:
```
[...]/rules_cc/examples/rule_based_toolchain$ bazel test //...
INFO: Analyzed 42 targets (0 packages loaded, 29 targets configured).
ERROR: /usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/googletest~/BUILD.bazel:86:11: Compiling googletest/src/gtest-filepath.cc failed: absolute path inclusion(s) found in rule '@@googletest~//:gtest':
the source file 'googletest/src/gtest-filepath.cc' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain):
'/usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/_main~_repo_rules~clang-linux-x86_64/include/c++/v1/string'
'/usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/_main~_repo_rules~clang-linux-x86_64/include/c++/v1/__algorithm/max.h'
'/usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/_main~_repo_rules~clang-linux-x86_64/include/c++/v1/__algorithm/comp.h'
'/usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/_main~_repo_rules~clang-linux-x86_64/include/c++/v1/__config'
'/usr/local/google/home/amontanez/.cache/bazel/_bazel_amontanez/e38ec8e746bf3d11672a536413f07932/external/_main~_repo_rules~clang-linux-x86_64/include/x86_64-unknown-linux-gnu/c++/v1/__config_site'
[many more]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.