bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.07k stars 4.04k forks source link

[bazel.build] Problem with /reference/be/protocol-buffer #23611

Open peytondmurray opened 3 weeks ago

peytondmurray commented 3 weeks ago

Page link:

https://bazel.build/reference/be/protocol-buffer

Problem description (include actual vs expected text, if applicable):

The https://github.com/bazelbuild/rules_proto/ repository is deprecated.

Where do you see this issue? (include link to specific section of the page, if applicable)

See this section: https://bazel.build/reference/be/protocol-buffer#proto_library

Any other information you'd like to share?

For what it's worth it's very hard for developers to come in and actually use bazel to build protocol buffers at the moment if they don't already have a working build. There is a lot of information in various places online which seems valid for old versions of protobuf; for example, many sources say that you can load the functions that generate code from protocol buffers using the following:

load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")

Now it seems that cc_proto_library is not available this way. I tried consulting the Bazel documentation but I don't actually think there's information about how to load cc_proto_library on the docs page. Furthermore if you look on the protocol buffers bazel docs they point you to the deprecated rules_proto repository. However in the readme for that repository, it says that the rules have been migrated to the protobuf repo, but if I search the docs in that repo there is no mention of cc_proto_library at all.

Looking in the protobuf repo examples directory, there is a usage of cc_proto_library which apparently you can load by doing

load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")

after you've done

http_archive(
    name = "com_google_protobuf",
    sha256 = "3b8bf6e96499a744bd014c60b58f797715a758093abf859f1d902194b8e1f8c9",
    strip_prefix = "protobuf-28.1",
    urls = ["https://github.com/protocolbuffers/protobuf/archive/v28.1.tar.gz"],
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

However there is a note about needing

# Needed because protobuf_deps brings rules_python 0.26.0 which is broken:
# https://github.com/bazelbuild/rules_python/issues/1543
http_archive(
    name = "rules_python",
    sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
    strip_prefix = "rules_python-0.25.0",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)

However for the project I'm working on, I'm trying to update the (currently broken) build system so that it actually runs; unfortunately doing this leads to other build errors which look an awful lot like the cc_proto_library and py_proto_library APIs have changed.

Anyway, it's not really in the scope of this issue to fix all of this, but I just wanted to say that it's currently quite hard for new Bazel users to come in and actually find a path forward. This is exacerbated by the fact that in addition to managing project dependencies, developers are required to manually manage Bazel rule dependencies, as well as Bazel versions via Bazelisk. If there's any way to update the docs with a working example of how to generate python and C++ code from protocol buffers, I'd be super grateful.

meteorcloudy commented 2 weeks ago

/cc @comius