/modern-cpp-bazel-starter

A starter template for modern C++ built with Bazel and configured with code analysis, testing and coverage

Primary LanguageC++The UnlicenseUnlicense

Modern C++ with Bazel starter template

Introduction

This is a starter template for a multi lib, multi app project born out of my needs. This template is based on my other starter project modern-cpp-cmake-starter, but uses Bazel as the build system.

Guiding Principles

Repository Structure

  • As far as possible, all directories are self contained
  • Executables are in the “apps” directory, one directory per app
  • Libraries are in “libs” directory, one directory per library
  • Every app or library directory has one or all of directories viz. “include”, “src”, “tests”
  • Each namespace gets own directory inside the above three

Build System

  • Bazel is primary build system(version 6.0)
  • External dependencies are managed via WORKSPACE, bazel module to be added later

How to use this template

  1. Use the “Use this template” button on github to create a new repository with all the content of this starter, modify according to your needs.
  2. Clone this repo locally and remove/change the remote

Building with Bazel

# build everything
 bazel build //...
# build specific target
 bazel build //path/to/pkg:target
# analyse with clang tidy
bazel build --config clang-tidy //...
# analyse IWYU (Include What You Use)
bazel build --config=iwyu //path/to/pkg:target
# run codecoverage for tests (e.g. greeter tests)
 bazel coverage --combined_report=lcov [target].
# open the code coverage report
 genhtml --output genhtml "$(bazel info output_path)/_coverage/_coverage_report.dat"

References