5

I'm trying to cross-compile hello-world C++ project with bezel for ARM64 device. I work with Linux/Ubuntu x86_64 as a built-host-PC. I'm following the Building a C++ Project.

I can build the project for host-PC.

bazel build //main:hello-world 

Now I'm trying to cross-compile this project for ARM64 device as

bazel build --cpu=aarch64 //main:hello-world 

I used different configuration for --cpu=arm64, --cpu=aarch64, --cpu=arm64-v8a and it does not wrok.

I'd model the environment as a platform to automatically select the appropriate toolchain installed via "crossbuild-essential-arm64" package for build action.

The cross-compilation build is done on PC-host - host platform - and executed there - execution platform - so the platforms are the same, but the - target platform - is different where the hello-world C++ project will run.

How to cross-compile the C++ project for arm64 target with bazel using --platforms properly?

5
  • I've been looking for the same, except I'm trying to cross-compile an existing project. I've found that Tensorflow has some bits that are meant to work, but I have no idea how to paste these into another project and it doesn't help that there is so much config, I rather unimpressed... Commented Jun 4, 2020 at 12:11
  • 1
    I found github.com/mjbots/rpi_bazel for cross-compiling C++ to a Raspberry Pi using clang - looks quite complicated ... :( Commented Jun 4, 2020 at 15:36
  • github.com/gregestren/snippets/tree/master/… Commented Jun 4, 2020 at 16:55
  • Have you seen docs.bazel.build/versions/master/tutorial/…? I have managed to work from there, but faced other issues with one of the dependencies, will report back on success. I think it should be easier in a greenfield project. Commented Jun 4, 2020 at 21:09
  • As you pointed that info it uses --crosstool_top and other Building with platforms C++ says it's the legacy approach.I guess both should solve the same one. Commented Jun 4, 2020 at 21:24

1 Answer 1

0

As @errordeveloper answered in a comment, I found very helpful the tutorial documentation here Configure C++ Toolchains. The point is that cross compilation in Bazel works at several levels, iiuc to let developers maximum flexibility.

  1. Platforms describe the execution architecture of "something". That could intentionally mean different things, like the host, execution, and target machine. It is mainly a collection of constraints.

  2. Toolchains describe the set of programs to use to perform the build actions, and they are coupled with the platforms, meaning that some toolchains can be used for certain platforms. For instance, you can tell Bazel to use the toolchain X for all ARM targets, independently from the specific ARM version.

In Bazel's cc_* rules, the toolchains are generally not downloaded automatically for every target, except some few cases, like iiuc the host machine one. While specifying new platforms is generally easy, specifying new toolchains requires touching multiple files, but it's not terrible. Usually you have to specify the toolchain in a BUILD file, coupled with a .bzl one to provide the implementation, and register the toolchain in the MODULE file. Follow the linked documentation, and if you want this blog post covers basically the same.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.