Cannot change Bazel compiler target

2,992 views
Skip to first unread message

max.g...@gmail.com

unread,
Jan 23, 2016, 3:23:58 PM1/23/16
to bazel-discuss
I'm trying to build TensorFlow from source, but I've been running into a compilation issue that seem to be related to the compiler. The problem is documented in this Github issue: https://github.com/tensorflow/tensorflow/issues/439.

I'm tried changing the compiler target to gcc-4.8 by modifying the GCC variable in osx_gcc_wrapper.sh, but Bazel always uses the default Xcode clang compiler. It seems that nothing in this file is being read, as introducing syntax errors in this file does not prevent compilation from proceeding.

I should note that I'm using Bazel 0.1.4, that I used the installer found in the Github releases page, and that I installed it locally. The osx_gcc_wrapper.sh file that I'm editing resides in ~/.bazel/base_workspace/tools/cpp/.

Is there another osx_gcc_wrapper.sh that I should be modifying? Maybe there is a cached version of this file that I need to delete? Thanks in advance for your help.

- Max

Brian Silverman

unread,
Jan 23, 2016, 4:23:48 PM1/23/16
to max.g...@gmail.com, bazel-discuss
Recent versions of bazel use a copy of osx_gcc_wrapper.sh that's compiled into the binary (it gets extracted to bazel-out/../../bazel-tools). If you want to use an edited version without recompiling Bazel, copy ~/.bazel/base_workspace/tools/cpp into your TensorFlow source directory (so you have my_tensorflow_src/WORKSPACE and my_tensorflow_src/tools/cpp/CROSSTOOL). Then if you run bazel with "--crosstool_top=//tools/cpp:toolchain" it should use that copy instead of the compiled-in one.


--
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/6b26b1ca-352f-4fa7-bf18-82f6843c2577%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

max.g...@gmail.com

unread,
Jan 24, 2016, 2:34:25 AM1/24/16
to bazel-discuss, max.g...@gmail.com
This worked, thanks! I'm now running into a new issue:
gcc-4.8: error trying to exec 'cc1plus': execvp: No such file or directory

I suspected that it had something to do with the crosstool ((https://github.com/bazelbuild/bazel/blob/master/tools/cpp/CROSSTOOL#L186-L277), so I tried changing paths to the preprocessor and changing some linker flags, but didn't have any luck.

I'm targeting gcc-4.8, which I've installed via Homebrew. The only line I've changed in osx_gcc_wrapper.sh is: GCC="/usr/local/bin/gcc-4.8".

Brian Silverman

unread,
Jan 24, 2016, 2:45:18 AM1/24/16
to max.g...@gmail.com, bazel-discuss
That would be due to the sandbox not including anything under /usr/local. You could add a new_local_repository(path = '/usr/local', ...) and then add the various files to the appropriate filegroups in CROSSTOOL, or use --spawn_strategy=standalone to disable the sandbox. Getting a different compiler working in the sandbox is hard, so you probably want to just disable it.

I'm hoping to get to writing something about how to get a custom compiler working in the sandbox on the wiki tomorrow if you want to go that route.

max.g...@gmail.com

unread,
Jan 24, 2016, 2:53:44 AM1/24/16
to bazel-discuss, max.g...@gmail.com
I tried disabling the sandbox, but I'm still encountering the error. This is what I'm running:

bazel build -c opt //tensorflow/tools/pip_package:build_pip_package --spawn_strategy=standalone --crosstool_top=//tools/cpp:toolchain --verbose_failure

Brian Silverman

unread,
Jan 24, 2016, 1:53:29 PM1/24/16
to Max Gillett, bazel-discuss
That error means your GCC is having trouble finding pieces of itself. If it works when called directly from a shell, it's probably related to some environment variable (eg PATH). Try setting PATH in osx_gcc_wrapper.sh to the same thing it's set to in a shell. If that doesn't work, you can try other environment variables, but I have no idea which ones. -canonical-prefixes/-no-canonical-prefixes might help too (try both, and be aware that CROSSTOOL might be passing -no-canonical-prefixes). You might also try searching the Internet for other people having similar issues with this toolchain.

Hu David

unread,
Jan 25, 2016, 4:05:37 AM1/25/16
to bazel-discuss, max.g...@gmail.com
Brian,

Really appreciate you will put some documentation about custom compiler in Bazel.

It would be nice if you could also have some example on this feature.
It seems like what I need but I cannot figure out how to adopt it. Thanks.

Hu David

unread,
Jan 25, 2016, 4:14:01 AM1/25/16
to bazel-discuss, max.g...@gmail.com
Brian,

What I want to do is, download a custom toolchain tarball from http & use it to compile the project.
Not sure how exactly the steps to do that. Thanks.
Reply all
Reply to author
Forward
0 new messages