Given the shortcomings of alternatives like cmake
, Bazel is a pretty great choice for C++ applications, even if you don’t need a multi-language or multi-application monorepo.
We’ll use the following tools and libraries:
Bazel Central Registry has a bunch of C++ libraries which can be built from source within your build.
Bazel Central Registry | toolchains_llvm adds a hermetic C++ toolchain to Bazel, which can include a sysroot that fully decouples build results from packages installed on the host machine. There are options for other compilers like
gcc
too.Bazel Central Registry | rules_foreign_cc lets you re-use legacy builds under Bazel, for example using cmake.
- https://github.com/bazelbuild/rules_cc is a re-implementation of Bazel’s built-in C++ rules in Starlark, Bazel’s extension language.
Aspect CLI | Aspect Docs includes a
configure
command that can do some auto-generation ofBUILD
files, freeing you from some of the tedium of specifying sources and dependencies.
Before starting the course, we assume you’ve already taken Bazel 101.
You should also run aspect init
and select the “C/C++” option, as well as Linting, Stamping, and OCI containers if you’d like to learn these.
Outline
Running a “hello world” applicationLink against pre-installed system librariesBuild external dependencies from sourceConfiguring the IDE or editorTesting and debugging with GoogleTestCross-compilation to target platformsLinting and FormattingBUILD file generationTopics to cover in the future
- Link against external dependencies from a distro like Debian
- apko or APT
- RPATH in ELF header
- point to some ruleset
- Embedding C++ code in other languages with Foreign Function Interfaces
- Binding to a dylib vs static link into program
- Go (cgo)
- Python (pybind)
- npm (gyp)
- Java (SWIG)
- Alternative toolchains
- musl syscall implementations (doesn’t need runtime linking)
- Sanitizers
- Asan
- Ubsan
- Tsan