Bazel 0.5.2 custom toolchain, incorrectly invoking archive program (gcc "ar") when building tensorflow?

191 Views Asked by At

Trying to use a custom toolchain to build a target that depends on tensorflow, my CROSSTOOL and toolchain BUILD files seem fine. However when building a target (that depends on tensorflow) bazel errors in the following:

>>>>>> #@org_tensorflow//tensorflow/core:version_lib [action 'Linking external/org_tensorflow/tensorflow/core/libversion_lib.a']
cd blah/blach && \ exec env - \ PWD=/proc/self/cwd \ 
path/to/linux-gnu-gcc-ar @bazel-out/local_linux-opt/bin/external/external/org_tensorflow/tensorflow/core/libversion_lib.a-2.params

The error is in the calling of "ar" itself, it should be called with the contents of the file, not the file itself.

ERROR: path/to/tensorflow/core/BUILD:1033:1:1 Linking of rule 
'@org_tensorflow//tensorflow/core:version_lib' failed: x86_64-unknown-linux-
gnu-gcc-ar failed: error executing command 
(cd blah/blach && \ exec env - \ PWD=/proc/self/cwd \ 
path/to/linux-gnu-gcc-ar @bazel-out/local_linux-
opt/bin/external/external/org_tensorflow/tensorflow/core/libversion_lib.a-
2.params) : com.google.devtools.build.lib.shell.BadExitStatusException: 
Process exited with status 1.
path/to/ar: invalid option --'@'
Usage: ar [emulation options] [-]{dmpqrstx}[abcDfilMNoPsSTuvV] [--plugin 
<name>] [member-name] [count] archive-file file... etc.

Now cat'ing

bazel-out/local_linux/opt/bin/external/external/org_tensorflow/tensorflow/core/libversion_lib.a-2.params

I get exactly what should be the argumets to 'ar', that is I get:

 rcsD bazel-out/local_linux-opt/bin/external/org_tensorflow/tensorflow/core/libversion_lib.a bazel-out/local_linux-opt/bin/external/org_tensorflow/tensorflow/core/_objs/version_lib/external/org_tensorflow/tensorflow/core/util/version_info.o

The command that should be run is something like:

path/to/custom/toolchain/ar $(cat bazel-out/local_linux/opt/bin/external/external/org_tensorflow/tensorflow/core/libversion_lib.a-2.params)

What am I missing? I'm on bazel's latest release 0.5.2

1

There are 1 best solutions below

0
On

My mistake, upon further reading different versions of 'ar' support a file argument. The fix is setting 'supports_param_files' argument to 0 in the cc_toolchain rule. Thanks to Marcel Hlopko from the bazel google group for the answer.