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:
- https://registry.bazel.build/ has a bunch of C++ libraries which can be built from source within your build.
- https://registry.bazel.build/modules/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. - https://registry.bazel.build/modules/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.
- https://docs.aspect.build/cli/ includes a
configure
command that can do some auto-generation ofBUILD
files, freeing you from some of the tedium of specifying sources and dependencies.
aspect init
and select the “C/C++” option, as well as Linting, Stamping, and OCI containers if you’d like to learn these.
Watch a live presentation of this course:
Outline
Running a “hello world” application Link against pre-installed system libraries Build external dependencies from source Configuring the IDE or editor Testing and debugging with GoogleTest Cross-compilation to target platforms Linting and Formatting BUILD file generationTopics we may 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