Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set c++ compiler on OS X with bazel?

Tags:

c++

macos

bazel

How can you tell bazel to use a different C++ compiler on OS X?

bazel build --action_env CC=/path/to/compiler //:target

works on linux.

But -s shows that bazel always runs with external/local_config_cc/wrapped_clang (clang) on OSX regardless of what CC is.

like image 898
Ryan Burn Avatar asked Dec 04 '17 00:12

Ryan Burn


3 Answers

CC correctly works only when you use the C++-only toolchain. If you have Xcode installed, bazel will detect this and automatically pick a different toolchain, the one that supports both C++ and ObjC. This toolchain can only use Xcode-provided clang.

This is unfortunate and I propose two solutions:

  1. File a feature request for bazel to make it possible to select which toolchain is used. This will allow you to tell bazel that even though you have Xcode installed, you want to use C++ only toolchain with a custom compiler. This is quite simple and doable in a short time.
  2. File a feature request for bazel to make it possible to select which compiler is used with C++/ObjC toolchain. I cannot comment on viability of this, I know next to nothing about osx, and I have no idea if it makes any sense to compile ObjC with a compiler that is not provided with Xcode...
like image 95
hlopko Avatar answered Oct 03 '22 02:10

hlopko


Actually with the latest version of bazel specifying

BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
build --action_env CC=/path/to/compiler  [...]

does work, in the sense that the specified compiler is used. However there is still a problem with the compiler flags. If the compiler flags of the old compiler are incompatible with the new one, there is a problem. I still have to find out how to change compiler flags.

like image 38
Federico Carminati Avatar answered Oct 03 '22 01:10

Federico Carminati


Use --crosstool_top.

See also --host_crosstool_top and --apple_crosstool_top.

like image 29
László Avatar answered Oct 03 '22 01:10

László