Skip to content

Add instructions on using the BCR to the README.md #19967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,53 @@ CMake Installation
To compile or install protobuf from source using CMake, see
[cmake/README.md](../cmake/README.md).

C++ Protobuf using the Bazel Central Registry - Unix
----------------------------------------------------

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:

* main.cpp
* ```c
#include "<messages>.pb.h"
int main() {
GOOGLE_PROTOBUF_VERIFY_VERSION;
return 0;
}
```
* \<messages\>.pb.cc/.h
* Generated using `protoc`, downloaded from [Github Releases](https://github.com/protocolbuffers/protobuf/releases).
* Check the runtime version of the compiler using `protoc --version`. It'll return something like "libprotoc 29.2".
Comment on lines +27 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section is unnecessary, specifically for Bazel workflows (it may be useful for others)

* MODULE.bazel
* ```
bazel_dep(name = "protobuf", version = "29.2")
```
* Note that the version matches `protoc`'s version
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one too, if you're using a fully Bazel approach you don't have to worry about version mismatch

* BUILD
* ```
cc_library(
name = "<messages>",
srcs = ["<messages>.pb.cc"],
hdrs = ["<messages>.pb.h"],
deps = [
"@protobuf//:protobuf",
],
)
cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [
":<messages>",
],
)
```
* WORKSPACE
* ```
workspace(name = "example")
```

Then build it using `bazel build :main` and run the binary using `./bazel-bin/main`


C++ Protobuf - Unix
-----------------------

Expand Down
Loading