1# Nanopb: Bazel build
2The Bazel build system, is designed to be fast and correct. Nanopb provides a
3set of plugins for the Bazel build system allowing Nanopb to be integrated
4into the build.
5
6## Getting started
7Add the following to your MODULE.bazel file.
8``` py
9# MODULE.bazel
10bazel_dep(name = "nanopb", version = "0.4.9")
11git_override(
12    module_name = "nanopb",
13    remote = "https://github.com/nanopb/nanopb.git",
14    commit = "<commit>",
15)
16```
17
18To use the Nanopb rules with in your build you can use the
19`cc_nanopb_proto_library` which works in a similar way to the native
20`cc_proto_library` rule.
21```  py
22# BUILD.bazel
23load("@nanopb//extra/bazel:nanopb_cc_proto_library.bzl", "cc_nanopb_proto_library")
24
25# Your native proto_library.
26proto_library(
27    name = "descriptor",
28    srcs = [
29        "generator/proto/google/protobuf/descriptor.proto",
30    ],
31)
32
33# Generated library.
34cc_nanopb_proto_library(
35    name = "descriptor_nanopb",
36    protos = [":descriptor"],
37    visibility = ["//visibility:private"],
38)
39
40# Depend directly on the generated code using a cc_library.
41cc_library(
42    name = "uses_generated_descriptors",
43    deps = [":descriptor_nanopb"],
44    hdrs = ["my_header.h"],
45)
46```
47
48If you have a custom nanopb options file, use the `nanopb_options_files` argument shown below.
49```  py
50# Generated library with options.
51cc_nanopb_proto_library(
52    name = "descriptor_nanopb",
53    protos = [":descriptor"],
54    nanopb_options_files = ["descriptor.options"],
55    visibility = ["//visibility:private"],
56)
57```
58