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

154 views
Skip to first unread message

marco

unread,
Jul 18, 2017, 9:40:13 PM7/18/17
to bazel-discuss, mar...@cs.stanford.edu
bazel version 0.5.2

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

Marcel Hlopko

unread,
Jul 19, 2017, 3:30:50 AM7/19/17
to marco, bazel-discuss, mar...@cs.stanford.edu
Hi Marco,

ar usually supports @file argument, from the man page:

@file
           Read command-line options from file.  The options read are inserted in place of the original @file option.  If file does not exist, or cannot be read, then the option will be treated literally, and not removed.

           Options in file are separated by whitespace.  A whitespace character may be included in an option by surrounding the entire option in either single or double quotes.  Any character (including a backslash) may be included by prefixing the character to be included
           with a backslash.  The file may itself contain additional @file options; any such options will be processed recursively.

That's what bazel uses (we have linking actions with so many inputs that we exceed the command line length limit). If your ar doesn't support param files, set 'supports_param_files' argument to 0 in your cc_toolchain rule.

Hope this helps,
Cheers


--
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/0e3f775f-d5d2-45e0-8a42-135a88543416%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: Matthew Scott Sucherman, Paul Terence Manicle | Registergericht und -nummer: Hamburg, HRB 86891
Reply all
Reply to author
Forward
0 new messages