Skip to content

Commit d853058

Browse files
committed
Revert "Remove rules_proto (bazel-contrib#4339)"
This reverts commit cd29704.
1 parent 7c5c55d commit d853058

File tree

20 files changed

+86
-50
lines changed

20 files changed

+86
-50
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 `com_google_protobuf` repository.
251+
The `proto_library` rule is provided by the `rules_proto` 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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
270+
load("@rules_proto//proto:defs.bzl", "proto_library")
271271
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
272272

273273
proto_library(

proto/compiler.bzl

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

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-
7651
GoProtoCompiler = provider(
7752
doc = "Information and dependencies needed to generate Go code from protos",
7853
fields = {
@@ -219,7 +194,7 @@ def proto_path(src, proto):
219194
def _go_proto_compiler_impl(ctx):
220195
go = go_context(ctx, include_deprecated_properties = False)
221196
go_info = new_go_info(go, ctx.attr)
222-
proto_toolchain = _find_toolchain(
197+
proto_toolchain = proto_toolchains.find_toolchain(
223198
ctx,
224199
legacy_attr = "_legacy_proto_toolchain",
225200
toolchain_type = _PROTO_TOOLCHAIN_TYPE,
@@ -269,7 +244,7 @@ _go_proto_compiler = rule(
269244
"_go_context_data": attr.label(
270245
default = "//:go_context_data",
271246
),
272-
}, **_if_legacy_toolchain({
247+
}, **proto_toolchains.if_legacy_toolchain({
273248
"_legacy_proto_toolchain": attr.label(
274249
# Setting cfg = "exec" here as the legacy_proto_toolchain target
275250
# already needs to apply the non_go_tool_transition. Flipping the
@@ -279,7 +254,7 @@ _go_proto_compiler = rule(
279254
default = "//proto/private:legacy_proto_toolchain",
280255
),
281256
})),
282-
toolchains = [GO_TOOLCHAIN] + _use_toolchain(_PROTO_TOOLCHAIN_TYPE),
257+
toolchains = [GO_TOOLCHAIN] + proto_toolchains.use_toolchain(_PROTO_TOOLCHAIN_TYPE),
283258
)
284259

285260
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-
"@com_google_protobuf//bazel/common:proto_info.bzl",
20+
"@rules_proto//proto:defs.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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
23+
load("@rules_proto//proto:defs.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-
"@com_google_protobuf//bazel/common:proto_lang_toolchain_info.bzl",
19+
"@rules_proto//proto:proto_common.bzl",
2020
"ProtoLangToolchainInfo",
2121
)
2222
load(

tests/core/cross/proto_test.go

Lines changed: 23 additions & 6 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 = "protobuf", version = "29.0-rc2", repo_name = "com_google_protobuf")
25+
bazel_dep(name = "rules_proto", version = "6.0.0")
2626
bazel_dep(name = "toolchains_protoc", version = "0.3.4")
2727
`,
2828
WorkspacePrefix: `
@@ -45,18 +45,35 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4545
4646
http_archive(
4747
name = "com_google_protobuf",
48-
integrity = "sha256-zl0At4RQoMpAC/NgrADA1ZnMIl8EnZhqJ+mk45bFqEo=",
49-
strip_prefix = "protobuf-29.0-rc2",
48+
sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae",
49+
strip_prefix = "protobuf-21.7",
50+
# latest available in BCR, as of 2022-09-30
5051
urls = [
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",
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",
5354
],
5455
)
5556
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()
5673
`,
5774
Main: `
5875
-- BUILD.bazel --
59-
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
76+
load("@rules_proto//proto:defs.bzl", "proto_library")
6077
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
6178
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
6279

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 @@
1-
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
21
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
2+
load("@rules_proto//proto:defs.bzl", "proto_library")
33
load(":codegen.bzl", "go_generated_library")
44

55
go_generated_library(

tests/core/go_proto_library/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
22
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
33
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
4+
<<<<<<< HEAD
5+
=======
6+
load("@rules_proto//proto:defs.bzl", "proto_library")
7+
>>>>>>> parent of cd29704e (Remove rules_proto (#4339))
48

59
# Common rules
610
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 @@
1-
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
21
load("@io_bazel_rules_go//go:def.bzl", "go_test")
32
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3+
load("@rules_proto//proto:defs.bzl", "proto_library")
44

55
proto_library(
66
name = "foo_proto",

tests/core/go_proto_library_importpath/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
22
load("@io_bazel_rules_go//go:def.bzl", "go_test")
33
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
4+
<<<<<<< HEAD
5+
=======
6+
load("@rules_proto//proto:defs.bzl", "proto_library")
7+
>>>>>>> parent of cd29704e (Remove rules_proto (#4339))
48

59
# Common rules
610
proto_library(

0 commit comments

Comments
 (0)