Selecting a build system is an essential decision when creating a project. Changing is always painful, especially in a mature repository. Therefore the choice should be made carefully. With this article, I will try to describe a few advantages of what Bazel can provide in the context of an embedded repository and show how to set up a build environment with a cross compiler from scratch.
This is a companion discussion topic for the original entry at https://interrupt.memfault.com/blog/bazel-build-system-for-embedded-projects
I may agree with the ‘powerful’ part of the conclusion. Bazel does support a wide array of paradigms and seems to offer a solution to build just about anything while guaranteeing build correctness, which is no small feat.
However, I cannot agree with the ‘effective’ part of it.
Following this post, I set out to bootstrapping a new build for an upcoming firmware for a new platform. After about a day of troubleshooting various issues, I was able to produce a dummy ELF file for my target. This would have taken me minutes (meh, seconds) had I written a makefile for it instead.
The next step after the .elf file is to call objcopy on it to generate a binary blob for my firmware. And there went another few hours, unsuccessfully so far. That would have been another minute with a makefile.
Although I do want a modern tool able to handle non-trivial builds (cross-toolchain + host unit tests, etc.), I cannot recommend bazel so far. Cmake, for its lack of support for multiple toolchains, is also out of the picture. I have worked on an embedded project using GN in the past, with some success, it unfortunately isn’t one of the cool kids and I’d rather stick with something that is widely understood.
All in all, it looks like the team will be stuck with good ol’ make for this project.
Hey Blaise, or anyone, can you share a working example of the Dockerize step?
The documentation kinda “hand-waves” through the toolchain setup – briefly describing the general idea of what toolchain changes are needed – but there are nuanced issues with the things I’ve tried that may fit the description. A working example of execution platforms running docker containers would be awesome if anyone can share one.