Skip to content
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

External targets cc targets do not add the exec root to include paths #16690

Open
UebelAndre opened this issue Nov 8, 2022 · 3 comments
Open
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@UebelAndre
Copy link
Contributor

Description of the bug:

I have a reproduction at https://github.com/UebelAndre/bazel_include_repro with steps to reproduce the issue.

Currently C++ targets which have a mutual external dependency fail to compile with an error similar to the following:

+ pushd /Users/user/Code/bazel_include_repro/repo_a
+ bazel test //...
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).
INFO: Found 1 target and 1 test target...
ERROR: /private/var/tmp/_bazel_user/8c14b48967f1ce9aa170fa8eaa724499/external/repo_b/lib/BUILD.bazel:3:11: Compiling lib/repo_b.cc failed: (Aborted): wrapped_clang_pp failed: error executing command external/local_config_cc/wrapped_clang_pp '-D_FORTIFY_SOURCE=1' -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -O0 -DDEBUG '-std=c++11' ... (remaining 31 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
external/repo_b/lib/repo_b.cc:3:10: fatal error: 'external/repo_c/lib/repo_c.h' file not found
#include "external/repo_c/lib/repo_c.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error in child process '/usr/bin/xcrun'. 1
INFO: Elapsed time: 0.576s, Critical Path: 0.44s
INFO: 4 processes: 4 internal.
FAILED: Build did NOT complete successfully
//lib:repo_test                                                       NO STATUS

FAILED: Build did NOT complete successfully

After inspecting the subcommands it seems external dependencies do not get any flags which add the execroot to the include path. This then causes failures when building repo_b which depends on repo_c.

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

Again, I have a reproduction at https://github.com/UebelAndre/bazel_include_repro with steps to reproduce the issue.

An archive can be found below.

url checksum
bazel_include_repro-30262c2b9fa13b294cec060c02ea3e54b9b21be9.zip 921afd3cc42d9ac2e47228635935aec40acabe4344fd2a58a432cbd905d4f04a

Which operating system are you running Bazel on?

Linux, MacOS

What is the output of bazel info release?

release 5.3.2

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

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

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

No response

@UebelAndre
Copy link
Contributor Author

#11293 seems related

@sgowroji sgowroji added type: bug team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Nov 8, 2022
@UebelAndre
Copy link
Contributor Author

A workaround can be achieved by using --per_file_copt

diff --git a/.bazelrc b/.bazelrc
new file mode 100644
index 0000000..23660ac
--- /dev/null
+++ b/.bazelrc
@@ -0,0 +1 @@
+build --per_file_copt=external/repo_a/.*,external/repo_b/.*,external/repo_c/.*@-I.
diff --git a/repo_a/.bazelrc b/repo_a/.bazelrc
new file mode 100644
index 0000000..5520968
--- /dev/null
+++ b/repo_a/.bazelrc
@@ -0,0 +1,2 @@
+build -s
+build --per_file_copt=external/repo_b/.*,external/repo_c/.*@-I.

@Wyverald
Copy link
Member

We have a similar problem in Python -- ideally, the repository name shouldn't be part of your include path. If you just wrote #include "lib/repo_c.h" (without the external/repo_c/ part), everything should work fine -- that is, unless you have a lib directory in some other repo.

I understand that isn't perfect and will keep this in mind.

@Wyverald Wyverald added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

3 participants