tree: 7fe9366be81bd33790ef99954861d73a83f56e9e [path history] [tgz]
  1. add.cpp
  2. add.h
  3. BUILD.bazel
  4. lib.h
  5. main.cpp
  6. README.md
  7. sub.cpp
  8. sub.h
examples/dependencies/README.md

Dependencies example

In this example, instead of specifying the files to be included in the Doxygen documentation using the srcs attribute with a glob, we use the deps attribute. This allows us to select a target and immediately include all of the files in its srcs, hdrs, and data attributes, along with all of its transitive dependencies.

bazel build //dependencies:doxygen

Showcase

In a very common scenario, imagine working on a C++ project with the following build file:

# BUILD.bazel
load("@rules_cc//cc:defs.bzl", "cc_library")

cc_library(
    name = "add",
    srcs = ["add.cpp"],
    hdrs = ["add.h"],
)

cc_library(
    name = "sub",
    srcs = ["sub.cpp"],
    hdrs = ["sub.h"],
)

cc_library(
    name = "lib",
    hdrs = ["lib.h"],
    deps = [
        ":add",
        ":sub",
    ],
)

cc_library(
    name = "main",
    srcs = ["main.cpp"],
    deps = [":lib"],
)

The graph of dependencies looks like this:

graph TD;
    A[main.cpp] --> B[lib.h];
    B --> C[add.h<br>add.cpp];
    B --> D[sub.h<br>sub.cpp];

If we want to include all of the files in the documentation, we can use the deps attribute to collect the main target's files and those of its transitive dependencies, like this:

# BUILD.bazel
load("@doxygen//:doxygen.bzl", "doxygen")

doxygen(
    name = "doxygen",
    deps = [":main"],
    doxygen_config = ":Doxyfile",
)