rules_cc icon indicating copy to clipboard operation
rules_cc copied to clipboard

undeclared inclusions if additional_compiler_inputs is in the root of the repo

Open keith opened this issue 1 month ago • 0 comments

repro.zip

With this BUILD file in the root of the repo:

load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
    name = "lib",
    srcs = ["lib.cc"],
    additional_compiler_inputs = [
        "foo.txt",
    ],
    copts = [
        "-std=c++23",
        "-Wno-c23-extensions",
    ],
    local_defines = [
        "THING=\\\"$(execpath foo.txt)\\\"",
    ],
)

If you build this target with 9.0.0rc3 + https://github.com/bazelbuild/rules_cc/commit/943f3b07b58d47b0175b0d103059f29d6d1b0491 you get:

% CC=clang USE_BAZEL_VERSION=last_rc bazel build :lib
INFO: Analyzed target //:lib (1 packages loaded, 3 targets configured).
ERROR: /tmp/repro/BUILD.bazel:3:11: Compiling lib.cc failed: absolute path inclusion(s) found in rule '//:lib':
the source file 'lib.cc' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain):
  '/tmp/repro/foo.txt'
Target //:lib failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.741s, Critical Path: 0.43s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

If you use the exact same structure in a nested directory it works as expected:

% CC=clang USE_BAZEL_VERSION=last_rc bazel build nested:lib
INFO: Analyzed target //nested:lib (1 packages loaded, 3 targets configured).
INFO: Found 1 target...
Target //nested:lib up-to-date:
  bazel-bin/nested/liblib.a
  bazel-bin/nested/liblib.so
INFO: Elapsed time: 0.141s, Critical Path: 0.00s
INFO: 1 process: 4 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action

keith avatar Dec 09 '25 19:12 keith