bazelbuild / bazelbuild/bazel

bazel cross-compiling bazel

Open
#11,054 0 comments 0 reactions 0 assignees View on GitHub
help wanted P3 team-Documentation team-OSS type: documentation (cleanup)
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

I'm trying to cross-compile bazel (with bazel). I'm using the 2.2.0 [dist zip](https://github.com/bazelbuild/bazel/releases/download/2.2.0/bazel-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](https://github.com/bazelbuild/bazel/issues/11038).

### 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`

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported commands for //src:bazel-dev on Ubuntu 18.04, starting with the --config=aarch64 failure and the protobuf linker error in external/com_google_protobuf/BUILD.bazel. Read the relevant .rc configuration and inspect how CC, CXX, and LD are passed to the build. Done means Bazel can cross-compile for a non-x86_64 architecture with the correct linker selection.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, docker, java, linux
Domain
build-system, devops, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.