Bazel and libc++ support

58 views
Skip to first unread message

jeffb...@google.com

unread,
Jul 6, 2019, 5:34:53 PM7/6/19
to bazel-discuss
Hi all! Home hacking project to better learn Bazel.

I'm trying to convince Bazel to let me use libc++ on Debian, and the system path autodetection is missing one of the directories for the include files:

If I setup my build with:

export CC=/usr/lib/llvm-8/bin/clang
export CXX=/usr/lib/llvm-8/bin/clang++

.bazelrc:
build:libc++ --action_env=CC
build:libc++ --action_env=CXX
build:libc++ --action_env=CXXFLAGS=--stdlib=libc++
build:libc++ --action_env=PATH

I get the following error:
ERROR: /home/jeffbailey/Programming/gittree/galactic-bloodshed/gb/BUILD:147:1: undeclared inclusion(s) in rule '//gb:gblib':
this rule is missing dependency declarations for the following files included by 'gb/survey.cc':
'/usr/lib/llvm-8/include/c++/v1/stddef.h'
'/usr/lib/llvm-8/include/c++/v1/cstdint'

Looking at external/local_config_cc/BUILD, I see:
cxx_builtin_include_directories = ["/usr/local/include",
"/usr/lib/llvm-8/lib/clang/8.0.0/include",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/include/c++/8",
"/usr/include/x86_64-linux-gnu/c++/8",
"/usr/include/c++/8/backward",
"/usr/include/clang/8.0.0/include"],

If I add:
"/usr/lib/llvm-8/include/c++/v1",

To that list it works fine.

Reading src/main/java/com/google/devtools/build/lib/skylarkbuildapi/cpp/CcModuleApi.java and the documentation for cxx_builtin_include_directories, it suggests that the paths are determined by gcc -E -xc++ - -v, so I checked on the paths from the compiler by doing:
$CC -stdlib=libc++ -E -xc++ - -v

Which gives:
/usr/lib/llvm-8/bin/../include/c++/v1
/usr/include/clang/8.0.1/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include

Is that command actually used to do the detection? Is there another way that I should be showing Bazel what the system include paths are? Or have I tripped across a bug?

Thanks!

Tks,
Jeff Bailey

Marcel Hlopko

unread,
Jul 8, 2019, 2:18:43 AM7/8/19
to jeffb...@google.com, bazel-discuss
Hi Jeff,

the easiest way to get libc++ with Bazel's autoconfigured C++ toolchain is to set environment variable BAZEL_LINKOPTS=-lc++:-lc++abi:-lm (tweak to your liking). If you want to link it statically, take a look and modify the command from https://github.com/bazelbuild/bazel/pull/8660 (you'll need to use the latest RC or build Bazel from HEAD). 

Happy hacking :)

--
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/c8d50d3b-4b1b-44ce-a974-d0d7fa560449%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Jeff Bailey

unread,
Jul 8, 2019, 2:53:22 AM7/8/19
to Marcel Hlopko, bazel-discuss
Thanks!  Will that cause it to get the right header files?  That seems like it would wind up linking the libc++ library against the libstdc++ includes.
Google Logo
Jeff Bailey
Manager, Android Open Source Project
jeffb...@google.com

Marcel Hlopko

unread,
Jul 8, 2019, 11:02:37 AM7/8/19
to Jeff Bailey, bazel-discuss
That depends on how you built your clang. You can pass -nostdinc and -nostdinc++ if it's looking into wrong places (pass -v to  see all the places it's looking into). You can do that either using BAZEL_CXXOPTS (defaults to -std=c++0x) or using plain --copt Bazel options.

Jeff Bailey

unread,
Jul 8, 2019, 5:12:27 PM7/8/19
to Marcel Hlopko, bazel-discuss
I'm using the clang-8 (and friends) packages from Debian unstable, so I'll poke at it a bit and see what I can figure out.

Thanks!

Google Logo
Jeff Bailey
Manager, Android Open Source Project
jeffb...@google.com

Reply all
Reply to author
Forward
0 new messages