bazelbuild/bazel

bazel cross-compiling bazel

Open

#11,054 建立於 2020年4月1日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Java (4,465 fork)batch import
P3help wantedteam-Documentationteam-OSStype: documentation (cleanup)

倉庫指標

Star
 (25,384 star)
PR 合併指標
 (平均合併 22天 20小時) (30 天內合併 77 個 PR)

描述

Description of the problem / feature request:

I'm trying to cross-compile bazel (with bazel). I'm using the 2.2.0 dist zip. However, I can't make it work. The problems I'm running into are illustrative of problems I've had cross-compiling other bazel projects.

Feature requests: what underlying problem are you trying to solve with this feature?

I want to be able to cross-compile Bazel for various architectures on an x86_64 host.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

First, with the --cpu flag:

$ bazel build --config=aarch64 //src:bazel-dev
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=161
ERROR: Config value aarch64 is not defined in any .rc file

Its unclear what the right --cpu value is. I've tried variants like arm64, arm, etc, and none of them work.

Trying with CC/CXX env vars:

$ CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ bazel build //src:bazel-dev
INFO: Analyzed target //src:bazel-dev (227 packages loaded, 9905 targets configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base /home/paleozogt/.cache/bazel/_bazel_paleozogt/c342016f43074582e446517e0df80fa6/sandbox
ERROR: /home/paleozogt/.cache/bazel/_bazel_paleozogt/c342016f43074582e446517e0df80fa6/external/com_google_protobuf/BUILD.bazel:431:1: Linking of rule '@com_google_protobuf//:protoc' failed (Exit 1) aarch64-linux-gnu-gcc failed: error executing command /usr/bin/aarch64-linux-gnu-gcc @bazel-out/host/bin/external/com_google_protobuf/protoc-2.params

Use --sandbox_debug to see verbose messages from the sandbox
/usr/bin/ld.gold: fatal error: /usr/lib/gcc-cross/aarch64-linux-gnu/7/../../../../aarch64-linux-gnu/lib/../lib/Scrt1.o: unsupported ELF machine number 183
collect2: error: ld returned 1 exit status
Target //src:bazel-dev failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 732.262s, Critical Path: 13.61s
INFO: 416 processes: 416 linux-sandbox.
FAILED: Build did NOT complete successfully

While it seems to be compiling things correctly, the linking is falling down. (I suspect its using the host x86_64 linker.) I've tried using LD env var but that doesn't work. How can the linker get passed to the build?

I also tried building by using an arm64 Docker image (emulated with qemu-user-static). Aside from being a ridiculous way to build software, it doesn't work.

What operating system are you running Bazel on?

Ubuntu 18.04 for amd64.

What's the output of bazel info release?

release 2.2.0

貢獻者指南