You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add instructions on using the BCR to the README.md
If your project is using Bazel, you can make your builds more reproducible by depending on protobuf through the Bazel Central Registry, instead of building it from source.
The C++ Protocol Buffer runtime is available on the [Bazel Central Registry](https://registry.bazel.build/modules/protobuf). If your project uses Bazel, you can simply add `@protobuf//:protobuf` as a dependency. Here's an example setup:
18
+
19
+
* main.cpp
20
+
*```c
21
+
#include"<messages>.pb.h"
22
+
intmain() {
23
+
GOOGLE_PROTOBUF_VERIFY_VERSION;
24
+
return 0;
25
+
}
26
+
```
27
+
*\<messages\>.pb.cc/.h
28
+
* Generated using `protoc`, downloaded from [Github Releases](https://github.com/protocolbuffers/protobuf/releases).
29
+
* Check the runtime version of the compiler using `protoc --version`. It'll return something like "libprotoc 29.2".
30
+
* MODULE.bazel
31
+
*```
32
+
bazel_dep(name = "protobuf", version = "29.2")
33
+
```
34
+
* Note that the version matches `protoc`'s version
35
+
* BUILD
36
+
* ```
37
+
cc_library(
38
+
name = "<messages>",
39
+
srcs = ["<messages>.pb.cc"],
40
+
hdrs = ["<messages>.pb.h"],
41
+
deps = [
42
+
"@protobuf//:protobuf",
43
+
],
44
+
)
45
+
cc_binary(
46
+
name = "main",
47
+
srcs = ["main.cpp"],
48
+
deps = [
49
+
":<messages>",
50
+
],
51
+
)
52
+
```
53
+
* WORKSPACE
54
+
* ```
55
+
workspace(name = "example")
56
+
```
57
+
58
+
Then build it using `bazel build :main` and run the binary using `./bazel-bin/main`
0 commit comments