How to cross-compile py_proto_library in bazel?

121 views
Skip to first unread message

Jasper Swallen

unread,
Jul 19, 2022, 6:28:41 PM7/19/22
to Protocol Buffers
I have cross compilation set up in my bazel project to allow building with multiple separate toolchains (currently x86-64 and cross compilation for aarch64). As I understand it, protobuf officially supports aarch64. However, compilation of @com_google_protobuf//:protobuf_python fails when my cross-compiled toolchain is selected. Is there a proper way to handle this? I would like to build either the correct protoc for this cross compilation, or if that's not possible, disable the toolchain for just this target (so that the protoc for this platform can be used).

I currently select the toolchain with something like this in my .bazelrc:
build:cross --crosstool_top=//toolchains:cross
build:cross --cpu=arm
build:cross --force_pic=true

The errors I get come from the linker thinking that all the symbols are undefined (even std library symbols).

Jasper Swallen

unread,
Jul 20, 2022, 2:30:26 PM7/20/22
to Protocol Buffers

The errors begin with:

1658341606.638177021: src/main/tools/linux-sandbox-pid1.cc:481: child started with PID 2
bazel-out/host/bin/external/com_github_protocolbuffers_protobuf/_objs/protoc/main.o: In function `google::protobuf::compiler::ProtobufMain(int, char**)':
main.cc:(.text+0x24): undefined reference to `std::allocator<char>::allocator()'
main.cc:(.text+0x38): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
main.cc:(.text+0x4c): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
main.cc:(.text+0x54): undefined reference to `std::allocator<char>::~allocator()'
main.cc:(.text+0x64): undefined reference to `std::allocator<char>::allocator()'

I've tried setting --proto_toolchain_for_cc=//toolchains:cross, but it seems to make no difference - it doesn't even seem to try to rebuild the library when I change the proto_toolchain_for_cc variable, and using invalid values "works" fine.

Deanna Garcia

unread,
Jul 20, 2022, 6:33:21 PM7/20/22
to Protocol Buffers
A few questions to help me debug/reproduce:
  • Did you write your own cross compilation toolchains? Or what are you using for that?
  • Can you provide the bazel command that you run (including a .bazelrc if necessary)?
  • Is your setup working to cross-compile other targets, specifically :protoc?

Reply all
Reply to author
Forward
0 new messages