Skip to content

Commit cd29704

Browse files
authored
Remove rules_proto (#4339)
**What type of PR is this?** > Cleanup **What does this PR do? Why is it needed?** Replaces rules_proto uses with com_google_protobuf. The former is deprecated.
1 parent 5fe82a7 commit cd29704

File tree

20 files changed

+56
-66
lines changed

20 files changed

+56
-66
lines changed

docs/go/core/workspace.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protobuf_deps()
248248
You'll need a C/C++ toolchain registered for the execution platform (the
249249
platform where Bazel runs actions) to build protoc.
250250

251-
The `proto_library` rule is provided by the `rules_proto` repository.
251+
The `proto_library` rule is provided by the `com_google_protobuf` repository.
252252
`protoc-gen-go`, the Go proto compiler plugin, is provided by the
253253
`com_github_golang_protobuf` repository. Both are declared by
254254
`go_rules_dependencies`. You won't need to declare an explicit dependency
@@ -267,7 +267,7 @@ and `go_proto_library` rules to generate and compile Go code from .proto
267267
files.
268268

269269
```starlark
270-
load("@rules_proto//proto:defs.bzl", "proto_library")
270+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
271271
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
272272

273273
proto_library(

proto/compiler.bzl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ load(
1616
"@bazel_skylib//lib:paths.bzl",
1717
"paths",
1818
)
19+
load("@com_google_protobuf//bazel/common:proto_common.bzl", "proto_common")
1920
load(
20-
"@rules_proto//proto:proto_common.bzl",
21-
proto_toolchains = "toolchains",
21+
"@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl",
22+
"ProtoLangToolchainInfo",
2223
)
2324
load(
2425
"//go:def.bzl",
@@ -48,6 +49,30 @@ load(
4849
# default.
4950
_PROTO_TOOLCHAIN_TYPE = "@rules_proto//proto:toolchain_type"
5051

52+
def _incompatible_toolchains_enabled():
53+
return getattr(proto_common, "INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION", False)
54+
55+
def _find_toolchain(ctx, legacy_attr, toolchain_type):
56+
if _incompatible_toolchains_enabled():
57+
toolchain = ctx.toolchains[toolchain_type]
58+
if not toolchain:
59+
fail("No toolchains registered for '%s'." % toolchain_type)
60+
return toolchain.proto
61+
else:
62+
return getattr(ctx.attr, legacy_attr)[ProtoLangToolchainInfo]
63+
64+
def _use_toolchain(toolchain_type):
65+
if _incompatible_toolchains_enabled():
66+
return [config_common.toolchain_type(toolchain_type, mandatory = False)]
67+
else:
68+
return []
69+
70+
def _if_legacy_toolchain(legacy_attr_dict):
71+
if _incompatible_toolchains_enabled():
72+
return {}
73+
else:
74+
return legacy_attr_dict
75+
5176
GoProtoCompiler = provider(
5277
doc = "Information and dependencies needed to generate Go code from protos",
5378
fields = {
@@ -188,7 +213,7 @@ def proto_path(src, proto):
188213
def _go_proto_compiler_impl(ctx):
189214
go = go_context(ctx, include_deprecated_properties = False)
190215
go_info = new_go_info(go, ctx.attr)
191-
proto_toolchain = proto_toolchains.find_toolchain(
216+
proto_toolchain = _find_toolchain(
192217
ctx,
193218
legacy_attr = "_legacy_proto_toolchain",
194219
toolchain_type = _PROTO_TOOLCHAIN_TYPE,
@@ -233,7 +258,7 @@ _go_proto_compiler = rule(
233258
"_go_context_data": attr.label(
234259
default = "//:go_context_data",
235260
),
236-
}, **proto_toolchains.if_legacy_toolchain({
261+
}, **_if_legacy_toolchain({
237262
"_legacy_proto_toolchain": attr.label(
238263
# Setting cfg = "exec" here as the legacy_proto_toolchain target
239264
# already needs to apply the non_go_tool_transition. Flipping the
@@ -243,7 +268,7 @@ _go_proto_compiler = rule(
243268
default = "//proto/private:legacy_proto_toolchain",
244269
),
245270
})),
246-
toolchains = [GO_TOOLCHAIN] + proto_toolchains.use_toolchain(_PROTO_TOOLCHAIN_TYPE),
271+
toolchains = [GO_TOOLCHAIN] + _use_toolchain(_PROTO_TOOLCHAIN_TYPE),
247272
)
248273

249274
def go_proto_compiler(name, **kwargs):

proto/def.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ load(
1717
"types",
1818
)
1919
load(
20-
"@rules_proto//proto:defs.bzl",
20+
"@com_google_protobuf//bazel/common:proto_info.bzl",
2121
"ProtoInfo",
2222
)
2323
load(

proto/gogo.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _gogo_special_proto_impl(ctx):
2020
"github.com/gogo/protobuf/gogoproto/gogo.proto",
2121
)
2222
ctx.file("github.com/gogo/protobuf/gogoproto/BUILD.bazel", """
23-
load("@rules_proto//proto:defs.bzl", "proto_library")
23+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2424
2525
proto_library(
2626
name = "gogoproto",

proto/private/toolchain.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# compatibility with --noincompatible_enable_proto_toolchain_resolution.
1717

1818
load(
19-
"@rules_proto//proto:proto_common.bzl",
19+
"@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl",
2020
"ProtoLangToolchainInfo",
2121
)
2222
load(

tests/core/cross/proto_test.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
var testArgs = bazel_testing.Args{
2424
ModuleFileSuffix: `
25-
bazel_dep(name = "rules_proto", version = "6.0.0")
25+
bazel_dep(name = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
2626
bazel_dep(name = "toolchains_protoc", version = "0.3.4")
2727
`,
2828
WorkspacePrefix: `
@@ -45,35 +45,18 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4545
4646
http_archive(
4747
name = "com_google_protobuf",
48-
sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae",
49-
strip_prefix = "protobuf-21.7",
50-
# latest available in BCR, as of 2022-09-30
48+
integrity = "sha256-zl0At4RQoMpAC/NgrADA1ZnMIl8EnZhqJ+mk45bFqEo=",
49+
strip_prefix = "protobuf-29.0-rc2",
5150
urls = [
52-
"https://github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz",
53-
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz",
51+
"https://github.com/protocolbuffers/protobuf/archive/v29.0-rc2.tar.gz",
52+
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v29.0-rc2.tar.gz",
5453
],
5554
)
5655
57-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
58-
59-
protobuf_deps()
60-
61-
http_archive(
62-
name = "rules_proto",
63-
sha256 = "303e86e722a520f6f326a50b41cfc16b98fe6d1955ce46642a5b7a67c11c0f5d",
64-
strip_prefix = "rules_proto-6.0.0",
65-
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0/rules_proto-6.0.0.tar.gz",
66-
)
67-
68-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
69-
rules_proto_dependencies()
70-
71-
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
72-
rules_proto_toolchains()
7356
`,
7457
Main: `
7558
-- BUILD.bazel --
76-
load("@rules_proto//proto:defs.bzl", "proto_library")
59+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
7760
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
7861
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
7962

tests/core/go_proto_aspect/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
33
load(":codegen.bzl", "go_generated_library")
44

55
go_generated_library(

tests/core/go_proto_library/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
# Common rules
66
proto_library(

tests/core/go_proto_library_importmap/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "foo_proto",

tests/core/go_proto_library_importpath/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
# Common rules
66
proto_library(

tests/core/transition/hermeticity_test.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestMain(m *testing.M) {
3030
-- BUILD.bazel --
3131
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
3232
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
33-
load("@rules_proto//proto:defs.bzl", "proto_library")
33+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
3434
3535
go_binary(
3636
name = "main",
@@ -122,8 +122,7 @@ message Foo {
122122
}
123123
`,
124124
ModuleFileSuffix: `
125-
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
126-
bazel_dep(name = "rules_proto", version = "6.0.0")
125+
bazel_dep(name = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
127126
bazel_dep(name = "toolchains_protoc", version = "0.3.4")
128127
`,
129128
WorkspacePrefix: `
@@ -160,23 +159,6 @@ http_archive(
160159
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v29.0-rc2.tar.gz",
161160
],
162161
)
163-
164-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
165-
166-
protobuf_deps()
167-
168-
http_archive(
169-
name = "rules_proto",
170-
sha256 = "0e5c64a2599a6e26c6a03d6162242d231ecc0de219534c38cb4402171def21e8",
171-
strip_prefix = "rules_proto-7.0.2",
172-
url = "https://github.com/bazelbuild/rules_proto/releases/download/7.0.2/rules_proto-7.0.2.tar.gz",
173-
)
174-
175-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
176-
rules_proto_dependencies()
177-
178-
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
179-
rules_proto_toolchains()
180162
`,
181163
})
182164
}

tests/integration/googleapis/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "color_service_proto",

tests/integration/grpc_plugin/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "hello_proto",

tests/legacy/examples/proto/dep/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
33

44
proto_library(
55
name = "useful_proto",

tests/legacy/examples/proto/embed/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "embed_proto",

tests/legacy/examples/proto/gogo/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_test")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "values_proto",

tests/legacy/examples/proto/gostyle/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
33

44
genrule(
55
name = "copy",

tests/legacy/examples/proto/grpc/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
22
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
3-
load("@rules_proto//proto:defs.bzl", "proto_library")
3+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
44

55
proto_library(
66
name = "my_svc_proto",

tests/legacy/examples/proto/lib/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
33

44
proto_library(
55
name = "lib_proto",

tests/legacy/proto_ignore_go_package_option/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
33

44
proto_library(
55
name = "a_proto",

0 commit comments

Comments
 (0)