How do I use Bazel to build with clang++?

3,299 views
Skip to first unread message

Ahmed Fakhry

unread,
Nov 15, 2016, 5:11:37 PM11/15/16
to bazel-discuss
In BUCK, this is quit easy. One would specify the compiler binaries in the [cxx] section of the .buckconfig file.  I tried to find something similar in Bazel, but couldn't.

Brian Silverman

unread,
Nov 15, 2016, 7:46:39 PM11/15/16
to Ahmed Fakhry, bazel-discuss
Try setting the environment variable CC=clang when you build. With newer versions, --client_env=CC=clang on the command line or in tools/bazel.rc should work too.

I wrote clang instead of clang++ because Bazel uses the C frontend for compiling C++ code (with GCC and Clang at least) because the C frontend will compile both C and C++, but the C++ frontend will interpret C code as C++ which doesn't work.

tools/cpp/cc_configure.bzl looks for that CC environment variable when it's configuring the C/C++ toolchain if you're interested in the implementation.

On Tue, Nov 15, 2016 at 5:11 PM, 'Ahmed Fakhry' via bazel-discuss <bazel-...@googlegroups.com> wrote:
In BUCK, this is quit easy. One would specify the compiler binaries in the [cxx] section of the .buckconfig file.  I tried to find something similar in Bazel, but couldn't.

--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/8d90fc1f-82bc-47df-a29d-e2523c18e59c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Damien Martin-guillerez

unread,
Nov 16, 2016, 12:46:33 AM11/16/16
to Brian Silverman, Ahmed Fakhry, bazel-discuss
On Wed, Nov 16, 2016 at 1:46 AM Brian Silverman <bsilve...@gmail.com> wrote:
Try setting the environment variable CC=clang when you build. With newer versions, --client_env=CC=clang on the command line or in tools/bazel.rc should work too.

--client_env=CC=clang has not yet any effect on C++ compilation (but this is going to happen, see http://cr.bazel.build/6697).
 

I wrote clang instead of clang++ because Bazel uses the C frontend for compiling C++ code (with GCC and Clang at least) because the C frontend will compile both C and C++, but the C++ frontend will interpret C code as C++ which doesn't work.

tools/cpp/cc_configure.bzl looks for that CC environment variable when it's configuring the C/C++ toolchain if you're interested in the implementation.
On Tue, Nov 15, 2016 at 5:11 PM, 'Ahmed Fakhry' via bazel-discuss <bazel-...@googlegroups.com> wrote:
In BUCK, this is quit easy. One would specify the compiler binaries in the [cxx] section of the .buckconfig file.  I tried to find something similar in Bazel, but couldn't.

--
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.

--
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/CAP01z6LTSh5kC4NHu76wQQ%2BUb4OzqfPOqN-up%3D8_hHwbpt4Y_A%40mail.gmail.com.

yi.wan...@gmail.com

unread,
Dec 10, 2016, 7:32:35 AM12/10/16
to bazel-discuss, afa...@google.com
On Tuesday, November 15, 2016 at 4:46:39 PM UTC-8, Brian Silverman wrote:
> Try setting the environment variable CC=clang when you build. With newer versions, --client_env=CC=clang on the command line or in tools/bazel.rc should work too.
>
>
>
> I wrote clang instead of clang++ because Bazel uses the C frontend for compiling C++ code (with GCC and Clang at least) because the C frontend will compile both C and C++, but the C++ frontend will interpret C code as C++ which doesn't work.
>
>
> tools/cpp/cc_configure.bzl looks for that CC environment variable when it's configuring the C/C++ toolchain if you're interested in the implementation.
>
>
>
> On Tue, Nov 15, 2016 at 5:11 PM, 'Ahmed Fakhry' via bazel-discuss <bazel-...@googlegroups.com> wrote:
>
> In BUCK, this is quit easy. One would specify the compiler binaries in the [cxx] section of the .buckconfig file.  I tried to find something similar in Bazel, but couldn't.
>
>
>
>
> --
>
> 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.
CC=clang doesn't work with me in a Docker çontainer based on Ubuntu 16.04:

root@22c046161c61:/learn-bazel# CC=clang CXX=clang++ bazel build ...
WARNING: Sandboxed execution is not supported on your system and thus hermeticity of actions cannot be guaranteed. See http://bazel.build/docs/bazel-user-manual.html#sandboxing for more information. You can turn off this warning via --ignore_unsupported_sandboxing.
INFO: Found 3 targets...
INFO: From Compiling lib/hello-greet.cc:
clang: warning: -Wl,-z,-relro,-z,now: 'linker' input unused
INFO: From Compiling main/hello-time.cc:
clang: warning: -Wl,-z,-relro,-z,now: 'linker' input unused
ERROR: /learn-bazel/lib/BUILD:1:1: Linking of rule '//lib:hello-greet' failed: process-wrapper failed: error executing command /root/.cache/bazel/_bazel_root/12e2eee6c4198c9fb4d44bfabadbc184/execroot/learn-bazel/_bin/process-wrapper -1 5 - - external/bazel_tools/tools/cpp/link_dynamic_library.sh no ignored ignored ignored ... (remaining 11 argument(s) skipped).
clang: error: unsupported option '-pass-exit-codes'
INFO: Elapsed time: 1.810s, Critical Path: 0.23s

The Dockerfile is at https://github.com/wangkuiyi/learn-bazel/blob/master/clang/Dockerfile
Reply all
Reply to author
Forward
0 new messages