This project attempts to demonstrate the following:
- Building Boost (1.65) shared libraries, Google Test, and a CMake-based library (GENIVI/vsomeip) with Bazel, via bazelbuild/rules_foreign_cc
- Targeting the above for the Raspberry Pi using a different (preferably faster) platform such as Ubuntu, via mjbots/rpi_bazel
A similar project works on x86 Ubuntu. I want to build that project for the Raspberry Pi, but on Ubuntu because it's faster and more convenient. mjbots/rpi_bazel to the rescue!
Unfortunately, mjbots/rpi_bazel doesn't play nice with bazelbuild/rules_foreign_cc. As demonstrated by this project, not even the Ubuntu build works. Let's fix it!
Can we power lift this boulder together?
We need to fix the following two issues:
- Boost shared libraries are successfully created for the host operating system but fails to create shared libraries for the Raspberry Pi
- CMake projects don't work when building for either the host or the Raspberry Pi
Multi-platform C++ projects are common. However, they are difficult to build. Bazel can fix this by making it easy for C++ developers to integrate the Bazel, Boost:b2, CMake, and toolchain ecosystems so that a single machine containing fast hardware and a lot of RAM can target multiple platforms including constrained systems such as the Raspberry Pi, thus avoiding complex orchestration and software installation on target platforms.
My ultimate goal is to support other platforms in addition to the Raspberry Pi with a similar approach to mjbots/rpi_bazel, such as IMX Linux. I admit that I have no idea how to do this. Today, rpi_bazel is black magic to me. I either want to learn or someone else needs to step up and do the same for more platforms, particularly embedded platforms that require C programming.
Here is some additional reading on this topic:
- Some form of Linux such as Ubuntu 18
- Bazel 0.26.1 or later. Version 0.28.1 seems to work.
The goal of this project is to build everything with clang instead of gcc. If gcc is not installed, you need to tell Bazel to use clang.
export CC=/usr/bin/clang
The executable will be located in bazel-bin/test/test
bazel build test
CMake fails to build. See the Raspberry Pi section below.
bazel build --cpu=pi test
boost/BUILD doesn't work even for the host platform unless this file specifies a toolset. Therefore, --with-toolset=clang is used.
Despite Boost appearing to build correctly, x86 shared libraries are built instead of ARM-compatible libraries. This can be verified using the 'file' command. I tried hard-coding toolset=arm-clang instead, but was still unsuccessful.
At any rate, the architecture (--cpu=pi) should affect the Boost build. The specified toolset should not be hard-coded.
ld.lld: error: bazel-out/armeabihf-fastbuild/bin/_solib_armeabihf/_U_S_Sboost_Clog___Uboost_Slog_Slib/libboost_atomic.so.1.65.0 is incompatible with armelf_linux_eabi
CMake (GENIVI/vsomeip) fails with:
/tmp/tmp.X5xqrpaTj2/CMakeFiles/CMakeTmp/external/org_llvm_clang/bin/clang: No such file or directory