Bazel: When objc_binary depends on cc_library, the latter is built for the wrong architecture

Created on 20 Jun 2015  路  6Comments  路  Source: bazelbuild/bazel

bazel build of the binary target yields:

ld: warning: ignoring file bazel-out/local_darwin-fastbuild/bin/.../libgrpc_unsecure.a, file was built for archive which is not the architecture being linked (i386): bazel-out/local_darwin-fastbuild/bin/.../libgrpc_unsecure.a

and lipo -info bazel-out/local_darwin-fastbuild/bin/.../libgrpc_unsecure.a:

input file bazel-out/local_darwin-fastbuild/bin/.../libgrpc_unsecure.a is not a fat file
Non-fat file: bazel-out/local_darwin-fastbuild/bin/.../libgrpc_unsecure.a is architecture: x86_64

So it seems it's compiling the cc_library for OS X.

P2 rules > ObjC / iOS / J2ObjC bug

Most helpful comment

You should be able to use apple_binary now, with appropriate flags and crosstool, provided you want to build targeting ios.

This is related to https://github.com/bazelbuild/bazel/issues/1279, as getting a crosstool targeting iOS is a bit of a pain without a working example.

You should be able to specify

bazel build //package:my_target \
--experimental_enable_objc_cc_deps --ios_multi_cpus=i386,x86_64 \
--crosstool_top=tools/osx/crosstool:crosstool

to build apple_binary "my_target" as a fat binary for both i386 and x86_64 architectures, even with cc deps.

All 6 comments

objc -> cc dependencies are a super experimental feature at this point in time, so expect them to be broken for a bit longer.

That said, if you have a crosstool that supports the architecture you're trying to build (I'll try to get one into bazel for the iOS architectures eventually) you can use the following flags to make things work:

blaze build --cpu= --crosstool_top= --host_crosstool_top=//tools/objc/crosstool:crosstool

This was unsassigned when we moved to github. After re-reading actually it is not P1.

Any progress on this? I can have objc_library's depend on cc_libraries, but when putting that obj_library as a dependency of an obc_binary I get "ld: symbol(s) not found for architecture i386".

Any ETA on this?

We're currently reworking how objc compilation works to use a CcToolchainProvider / CROSSTOOL file similarly to how C++ compilation works; either this will be fixed as part of the refactor or the refactor will make it much easier to fix.

Does the workaround posted by aragos above work?

You should be able to use apple_binary now, with appropriate flags and crosstool, provided you want to build targeting ios.

This is related to https://github.com/bazelbuild/bazel/issues/1279, as getting a crosstool targeting iOS is a bit of a pain without a working example.

You should be able to specify

bazel build //package:my_target \
--experimental_enable_objc_cc_deps --ios_multi_cpus=i386,x86_64 \
--crosstool_top=tools/osx/crosstool:crosstool

to build apple_binary "my_target" as a fat binary for both i386 and x86_64 architectures, even with cc deps.

Was this page helpful?
0 / 5 - 0 ratings