bazelbuild / rules_cc

C++ Rules for Bazel
https://bazel.build
Apache License 2.0
176 stars 88 forks source link

virtual includes and headers only cc_library. #191

Closed lromor closed 1 year ago

lromor commented 1 year ago

Description of the problem / feature request:

I'm trying to port to bazel a library. The library uses system includes (say #include <dir/foo.h>) also internally. The headers are included both using double quotes and angle brackets. Externally is used mostly via angle brackets.

I made a simple repository that mocks the situation:

When I try to compile bazel build //dir:foo I get:

dir/foo.cc:3:10: fatal error: dir/foo.h: No such file or directory
    3 | #include <dir/foo.h>

By inspecting the sandbox with and adding more verbosity, the command is the following:

 (cd /home/lromor/.cache/bazel/_bazel_lromor/72cb75e6582d64c688eee6d6659304e6/sandbox/linux-sandbox/2/execroot/__main__ && \
  exec env - \
    PATH=<redacted> \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /home/lromor/.cache/bazel/_bazel_lromor/install/50a5a3eaeaa5297d31568ab6a3a702d9/linux-sandbox -t 15 -w /home/lromor/.cache/bazel/_bazel_lromor/72cb75e6582d64c688eee6d6659304e6/sandbox/linux-sandbox/2/execroot/__main__ -w /tmp -w /dev/shm -S /home/lromor/.cache/bazel/_bazel_lromor/72cb75e6582d64c688eee6d6659304e6/sandbox/linux-sandbox/2/stats.out -D -- /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/k8-fastbuild/bin/dir/_objs/foo/foo.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/dir/_objs/foo/foo.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY=""' -iquote . -iquote bazel-out/k8-fastbuild/bin -Ibazel-out/k8-fastbuild/bin/dir/_virtual_includes/dir_headers -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c dir/foo.cc -o bazel-out/k8-fastbuild/bin/dir/_objs/foo/foo.pic.o)

As you can see, bazel-out/k8-fastbuild/bin/dir/_virtual_includes/dir_headers is included, but there's no such directory or path in the sandbox environment.

Feature requests: what underlying problem are you trying to solve with this feature?

Since it's impossible to add includes = ["."] because it would import the root workspace as include. And since adding the prefix and virtual includes is not working, it' impossible for me to let source files including #include <dir/foo.h> to work effectively.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Example

What operating system are you running Bazel on?

Debian

What's the output of bazel info release?

release 6.2.1

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

N/A

What version of rules_cc do you use? Can you paste the workspace rule used to fetch rules_cc? What other relevant dependencies does your project have?

N/A, I also used both the latest version of rules_cc and the "embedded" version already present in bazel.

What Bazel options do you use to trigger the issue? What C++ toolchain do you use?

System toolchain.

Have you found anything relevant by searching the web?

Not really.

Any other information, logs, or outputs that you want to share?

Already added in the first question.

lromor commented 1 year ago

Closing and moving this issue to bazelbuild/bazel#18913