Skip to content

Commit 9f9cb7a

Browse files
Move proto_toolchain from rules_proto to protobuf
The toolchain type is consumed by proto_library and produced by proto_toolchain rule. As such it's a private dependency, because both rules are now part of protobuf repo. There are some early adopters of --incompatible_enable_proto_toolchain_resolution that might be broken from this: grpc, rules_go, rules_ts, rules_rust, rules_lint, because they have implementation that is not using proto_common. Those repositories need to define their own proto_lang_toolchain and consume it with proto_common.compile. PiperOrigin-RevId: 654897871
1 parent d44c0d5 commit 9f9cb7a

File tree

7 files changed

+17
-22
lines changed

7 files changed

+17
-22
lines changed

MODULE.bazel

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ bazel_dep(name = "platforms", version = "0.0.8")
2727
bazel_dep(name = "zlib", version = "1.3.1")
2828
bazel_dep(name = "bazel_features", version = "1.13.0", repo_name = "proto_bazel_features")
2929

30-
# TODO: remove after toolchain types are moved to protobuf
31-
bazel_dep(name = "rules_proto", version = "4.0.0")
32-
3330
SUPPORTED_PYTHON_VERSIONS = [
3431
"3.8",
3532
"3.9",
@@ -99,3 +96,5 @@ use_repo(maven, "maven")
9996
# Development dependencies
10097
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest", dev_dependency = True)
10198
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
99+
# rules_proto are needed for @com_google_protobuf_v25.0 used in //compatibility/... tests
100+
bazel_dep(name = "rules_proto", version = "4.0.0", dev_dependency = True)

bazel/private/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ load("//bazel/private:native_bool_flag.bzl", "native_bool_flag")
1010

1111
licenses(["notice"])
1212

13+
toolchain_type(
14+
name = "proto_toolchain_type",
15+
)
16+
1317
bzl_library(
1418
name = "upb_proto_library_internal_bzl",
1519
srcs = [
@@ -40,6 +44,11 @@ bzl_library(
4044
"proto_toolchain_rule.bzl",
4145
],
4246
visibility = ["//bazel:__subpackages__"],
47+
deps = [
48+
":toolchain_helpers_bzl",
49+
"//bazel/common:proto_common_bzl",
50+
"//bazel/common:proto_lang_toolchain_info_bzl",
51+
],
4352
)
4453

4554
bzl_library(

bazel/private/proto_toolchain_rule.bzl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"""A Starlark implementation of the proto_toolchain rule."""
22

3-
load("//bazel/common:proto_common.bzl", "proto_common")
43
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
4+
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
55

66
def _impl(ctx):
7-
kwargs = {}
8-
if getattr(proto_common, "INCOMPATIBLE_PASS_TOOLCHAIN_TYPE", False):
9-
kwargs["toolchain_type"] = "@rules_proto//proto:toolchain_type"
10-
117
return [
128
DefaultInfo(
139
files = depset(),
@@ -23,7 +19,7 @@ def _impl(ctx):
2319
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
2420
progress_message = ctx.attr.progress_message,
2521
mnemonic = ctx.attr.mnemonic,
26-
**kwargs
22+
toolchain_type = toolchains.PROTO_TOOLCHAIN,
2723
),
2824
),
2925
]

bazel/private/toolchain_helpers.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ toolchains = struct(
4545
find_toolchain = _find_toolchain,
4646
if_legacy_toolchain = _if_legacy_toolchain,
4747
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _incompatible_toolchain_resolution,
48-
PROTO_TOOLCHAIN = "@rules_proto//proto:toolchain_type",
48+
PROTO_TOOLCHAIN = "//bazel/private:proto_toolchain_type",
4949
)

bazel/toolchains/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bzl_library(
88
visibility = ["//visibility:public"],
99
deps = [
1010
"//bazel/private:proto_toolchain_rule_bzl",
11+
"//bazel/private:toolchain_helpers_bzl",
1112
],
1213
)
1314

bazel/toolchains/proto_toolchain.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The macro additionally creates toolchain target when toolchain_type is given.
44
"""
55

66
load("//bazel/private:proto_toolchain_rule.bzl", _proto_toolchain_rule = "proto_toolchain")
7+
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
78

89
def proto_toolchain(*, name, proto_compiler, exec_compatible_with = []):
910
"""Creates a proto_toolchain and toolchain target for proto_library.
@@ -19,7 +20,7 @@ def proto_toolchain(*, name, proto_compiler, exec_compatible_with = []):
1920

2021
native.toolchain(
2122
name = name + "_toolchain",
22-
toolchain_type = "@rules_proto//proto:toolchain_type",
23+
toolchain_type = toolchains.PROTO_TOOLCHAIN,
2324
exec_compatible_with = exec_compatible_with,
2425
target_compatible_with = [],
2526
toolchain = name,

protobuf_deps.bzl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,6 @@ def protobuf_deps():
120120
sha256 = "160d1ebf33763124766fb35316329d907ca67f733238aa47624a8e3ff3cf2ef4",
121121
)
122122

123-
# TODO: remove after toolchain types are moved to protobuf
124-
if not native.existing_rule("rules_proto"):
125-
http_archive(
126-
name = "rules_proto",
127-
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
128-
strip_prefix = "rules_proto-5.3.0-21.7",
129-
urls = [
130-
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
131-
],
132-
)
133-
134123
if not native.existing_rule("proto_bazel_features"):
135124
proto_bazel_features(name = "proto_bazel_features")
136125

0 commit comments

Comments
 (0)