Skip to content

Commit

Permalink
Reverse the dependency from rules_proto to protobuf
Browse files Browse the repository at this point in the history
This way rules_proto are using rules defined in protobuf. The redirect to native rules is removed.

PiperOrigin-RevId: 650525711
  • Loading branch information
A Googler authored and Blaze Rules Copybara committed Jul 9, 2024
1 parent b38f0e6 commit 7083178
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 299 deletions.
3 changes: 1 addition & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.4.1")
bazel_dep(name = "protobuf", version = "27.1", repo_name = "com_google_protobuf")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "rules_license", version = "0.0.7")

# Dependencies needed in tests
bazel_dep(name = "stardoc", version = "0.5.6", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "googletest", version = "1.11.0", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "protobuf", version = "23.1", dev_dependency = True, repo_name = "com_google_protobuf")
bazel_dep(name = "platforms", version = "0.0.8", dev_dependency = True)
53 changes: 5 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,15 @@

* Postsubmit [![Build status](https://badge.buildkite.com/26d40f574d6f6026928bc271780782e5f168fe7e3595ea6d79.svg)](https://buildkite.com/bazel/rules-proto)

This repository contains a Starlark implementation of `proto_library` and related "base layer" rules in Bazel.
It does **not** provide rules for any specific languages. These are typically expected to be provided in the ruleset for the language.
This repository is deprecated.

For a high-level overview of using Protocol Buffers and gRPC with Bazel, see
<https://bazel-contrib.github.io/SIG-rules-authors/proto-grpc.html>.

For the list of Proto rules, see the Bazel
[documentation](https://docs.bazel.build/versions/master/be/overview.html).
The proto library implementation `proto_library` and rules for other languages like Java, Python, C++ are
in [protobuf repository](http://github.com/google/protobuf).

## Roadmap

As of September 2023, this repo is mostly empty and contains stubs for `proto_library`, `ProtoInfo` and other proto toolchain support rules.

This will change soon, around the time Bazel 7 is released (in Oct/Nov 2023), because the stubs will be replaced with actual implementations.
We plan to remove the native implementations in Bazel 8, at which point rules_proto will be the only way to build Protobuf rules.

As such it's recommended to use this repository now, so that the removal of implementations from Bazel 8 does not cause you problems.

## Getting Started

To get started with `rules_proto`, add the `WORKSPACE` file snippet from the
[latest release](https://github.com/bazelbuild/rules_proto/releases).

Then, in your `BUILD` files, import and use the rules:

```starlark
load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(
...
)
```

If you're migrating from the native proto rules to `rules_proto`, you can use
the following [buildifier](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
command to automate the changes to your `BUILD` and `.bzl` files:

```bash
buildifier --lint=fix --warnings=native-proto <path/to/BUILD>
```

## Contributing

Bazel and `rules_proto` are the work of many contributors.
We appreciate your help!

To contribute, please read the contribution guidelines:
[CONTRIBUTING.md](https://github.com/bazelbuild/rules_proto/blob/master/CONTRIBUTING.md).

Note that the `rules_proto` use the GitHub issue tracker for bug reports and
feature requests only.
As of May 2024, we decided to move the implementation of the rules together with proto compiler into protobuf repository.

For asking questions see:
As such this repository is deprecated and serves only as a helper in the migration.

* [rules_proto mailing list](https://groups.google.com/forum/#!forum/proto-bazel-discuss)
* Slack channel `#proto` on [slack.bazel.build](https://slack.bazel.build)
3 changes: 0 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")

Expand Down
14 changes: 0 additions & 14 deletions dev_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,3 @@ def rules_proto_dev_deps():
"https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
],
)

http_archive(
name = "com_google_protobuf",
sha256 = "dc167b7d23ec0d6e4a3d4eae1798de6c8d162e69fa136d39753aaeb7a6e1289d",
strip_prefix = "protobuf-23.1",
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v23.1.tar.gz",
"https://github.com/protocolbuffers/protobuf/archive/v23.1.tar.gz",
],
remote_patch_strip = 1,
remote_patches = {
"https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/modules/protobuf/23.1/patches/0007-bazel-Get-rid-of-exec_tools.-13401.patch": "sha256-Thj5ZYqMpgaUrjZv8XyWqyD+I6XQNcZjo4jI14a7QxE=",
},
)
10 changes: 7 additions & 3 deletions proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ bzl_library(
deps = [
":proto_lang_toolchain",
":proto_toolchain",
"//proto/private:native",
"//proto/private/rules:proto_descriptor_set",
"@com_google_protobuf//bazel:proto_library_bzl",
],
)

Expand All @@ -31,7 +31,8 @@ bzl_library(
"proto_lang_toolchain.bzl",
],
deps = [
":proto_common",
"@com_google_protobuf//bazel/common:proto_lang_toolchain_info_bzl",
"@com_google_protobuf//bazel/toolchains:proto_lang_toolchain_bzl",
],
)

Expand All @@ -40,6 +41,9 @@ bzl_library(
srcs = [
"proto_common.bzl",
],
deps = [
"@com_google_protobuf//bazel/common:proto_common_bzl",
],
)

bzl_library(
Expand All @@ -49,7 +53,7 @@ bzl_library(
],
visibility = ["//visibility:public"],
deps = [
"//proto/private/rules:proto_toolchain_bzl",
"@com_google_protobuf//bazel/toolchains:proto_toolchain_bzl",
],
)

Expand Down
30 changes: 8 additions & 22 deletions proto/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@

"""Starlark rules for building protocol buffers."""

load("//proto:proto_lang_toolchain.bzl", _proto_lang_toolchain = "proto_lang_toolchain")
load("//proto:proto_toolchain.bzl", _proto_toolchain = "proto_toolchain")
load("//proto/private:native.bzl", "NativeProtoInfo", "native_proto_common")
load("@com_google_protobuf//bazel:proto_library.bzl", _proto_library = "proto_library")
load("@com_google_protobuf//bazel/common:proto_common.bzl", _proto_common = "proto_common")
load("@com_google_protobuf//bazel/common:proto_info.bzl", _ProtoInfo = "ProtoInfo")
load("@com_google_protobuf//bazel/toolchains:proto_lang_toolchain.bzl", _proto_lang_toolchain = "proto_lang_toolchain")
load("@com_google_protobuf//bazel/toolchains:proto_toolchain.bzl", _proto_toolchain = "proto_toolchain")
load("//proto/private/rules:proto_descriptor_set.bzl", _proto_descriptor_set = "proto_descriptor_set")

_MIGRATION_TAG = "__PROTO_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"

def _add_migration_tag(attrs):
if "tags" in attrs and attrs["tags"] != None:
attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG]
else:
attrs["tags"] = [_MIGRATION_TAG]
return attrs

def proto_library(**attrs):
"""Bazel proto_library rule.
Expand All @@ -37,21 +30,14 @@ def proto_library(**attrs):
**attrs: Rule attributes
"""

# buildifier: disable=native-proto
native.proto_library(**_add_migration_tag(attrs))
_proto_library(**attrs)

proto_descriptor_set = _proto_descriptor_set

proto_lang_toolchain = _proto_lang_toolchain

proto_toolchain = _proto_toolchain

# Encapsulates information provided by `proto_library`.
#
# https://docs.bazel.build/versions/master/skylark/lib/ProtoInfo.html
ProtoInfo = NativeProtoInfo
ProtoInfo = _ProtoInfo

# Utilities for protocol buffers.
#
# https://docs.bazel.build/versions/master/skylark/lib/proto_common.html
proto_common = native_proto_common
proto_common = _proto_common
7 changes: 0 additions & 7 deletions proto/private/BUILD

This file was deleted.

28 changes: 0 additions & 28 deletions proto/private/native.bzl

This file was deleted.

14 changes: 1 addition & 13 deletions proto/private/rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ bzl_library(
"//proto:__subpackages__",
],
deps = [
"//proto/private:native",
],
)

bzl_library(
name = "proto_toolchain_bzl",
srcs = [
"proto_toolchain.bzl",
"proto_toolchain_rule.bzl",
"@bazel_features//:features",
],
visibility = [
"//proto:__subpackages__",
"@com_google_protobuf//bazel/common:proto_info_bzl",
],
)
3 changes: 1 addition & 2 deletions proto/private/rules/proto_descriptor_set.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""A rule for generating a `FileDescriptorSet` with all transitive dependencies.
This module contains the definition of `proto_descriptor_set`, a rule that
collects all `FileDescriptorSet`s from its transitive dependencies and generates
a single `FileDescriptorSet` containing all the `FileDescriptorProto` from them.
"""

load("//proto/private:native.bzl", ProtoInfo = "NativeProtoInfo")
load("@com_google_protobuf//bazel/common:proto_info.bzl", "ProtoInfo")

def _proto_descriptor_set_impl(ctx):
args = ctx.actions.args()
Expand Down
40 changes: 0 additions & 40 deletions proto/private/rules/proto_toolchain.bzl

This file was deleted.

70 changes: 0 additions & 70 deletions proto/private/rules/proto_toolchain_rule.bzl

This file was deleted.

7 changes: 3 additions & 4 deletions proto/proto_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
# https://docs.bazel.build/versions/master/skylark/lib/proto_common.html
"""proto_common module"""

load("//proto/private:native.bzl", "native_proto_common")
load("@com_google_protobuf//bazel/common:proto_common.bzl", _proto_common = "proto_common")
load("@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")

proto_common = native_proto_common

ProtoLangToolchainInfo = proto_common.ProtoLangToolchainInfo
proto_common = _proto_common # reexport proto_common for current users

def _incompatible_toolchains_enabled():
return getattr(proto_common, "INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION", False)
Expand Down
Loading

0 comments on commit 7083178

Please sign in to comment.