Bazel cc_toolchain dependency declarations headers

982 views
Skip to first unread message

Carlos Galvez

unread,
Jun 29, 2021, 8:01:59 AM6/29/21
to bazel-discuss
Hi,

I'm trying to configure a CC toolchain based on x86 GCC. I want to download a specific version of GCC instead of using whatever the user has installed on their machine.

I'm following this guide:

And get stuck in point 8: Bazel is saying I have not declared dependencies to headers:

this rule is missing dependency declarations for the following files included by 'hello/main.cpp':
  '/home/user/.cache/bazel/_bazel_user/4fd10b035034e53930a3873d63a730b2/external/gcc/usr/include/stdc-predef.h'
  '/home/user/.cache/bazel/_bazel_user/4fd10b035034e53930a3873d63a730b2/external/gcc/usr/include/c++/7/iostream'

I have added the sysroot as per the instructions:

    cxx_builtin_include_directories = [
        "/usr/include",
        "%sysroot%/usr/include/c++/7/",
        "%sysroot%/usr/include/x86_64-linux-gnu",
        "%sysroot%/usr/include",
        "%sysroot%/usr/lib/gcc/x86_64-linux-gnu/7/include",
        "%sysroot%/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed",
    ],
    sysroot="external/gcc_x86",

Why is it not working?

Thanks!
/Carlos

Austin Schuh

unread,
Jul 1, 2021, 1:02:16 AM7/1/21
to Carlos Galvez, bazel-discuss
Check out:

That is a working toolchain we've got setup to do both cross compilation and to use a compiler that Bazel downloads.

Austin

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0d51c9bc-e9b5-4e58-8ea0-0209ee3163b1n%40googlegroups.com.

Konstantin

unread,
Jul 1, 2021, 10:51:21 AM7/1/21
to bazel-discuss
You need to add " external/gcc/usr/include" to  cxx_builtin_include_directories list.

Konstantin

Carlos Galvez

unread,
Jul 1, 2021, 10:55:06 AM7/1/21
to bazel-discuss
Thanks, I've tried both approaches without success. Also it seems "no-canonical-headers" is important, but it still doesn't work.

It seems the problem is that GCC will always use absolute paths in its default search paths, unlike cross-compilers, which will use relative paths if "no-canonical-headers" is active. Quite a pity...

Konstantin

unread,
Jul 1, 2021, 11:01:13 AM7/1/21
to bazel-discuss
You mean "no-canonical-prefixes", right?

Carlos Galvez

unread,
Jul 1, 2021, 11:03:47 AM7/1/21
to bazel-discuss
Yes, sorry, mixed it up with a similar flag.

Konstantin

unread,
Jul 1, 2021, 11:06:43 AM7/1/21
to bazel-discuss
I see GCC also has "no-canonical-system-headers". Have not tried it though - we use Clang. 

Carlos Galvez

unread,
Jul 5, 2021, 8:28:15 AM7/5/21
to bazel-discuss
 @austin  I looked at your toolchain a bit more in depth and have some follow-up questions:

* What decides where you put the ")%" part? sometimes you put it in the middle of the path, sometimes at the end of it.
* I see you still need to disable the default include and link paths and set them manually via isystem, why is that? 

If I set my include paths manually like you do, then I don't need to write anything in cxx_builtin_directories and Bazel is happy.

Sumanth Murali

unread,
Apr 19, 2022, 7:14:43 PM4/19/22
to bazel-discuss
What was the solution for this?
I have tried using custom_builtin_include_directories and isystem for include paths, and still seem to get errors like
This rule is missing dependency declarations for the following files included 

Konstantin

unread,
Apr 19, 2022, 8:52:23 PM4/19/22
to bazel-discuss
Could you share a repro?
Reply all
Reply to author
Forward
0 new messages