Skip to content

Commit

Permalink
Move proto_toolchain from rules_proto to protobuf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Jul 22, 2024
1 parent d44c0d5 commit 9f9cb7a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
5 changes: 2 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "zlib", version = "1.3.1")
bazel_dep(name = "bazel_features", version = "1.13.0", repo_name = "proto_bazel_features")

# TODO: remove after toolchain types are moved to protobuf
bazel_dep(name = "rules_proto", version = "4.0.0")

SUPPORTED_PYTHON_VERSIONS = [
"3.8",
"3.9",
Expand Down Expand Up @@ -99,3 +96,5 @@ use_repo(maven, "maven")
# Development dependencies
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
# rules_proto are needed for @com_google_protobuf_v25.0 used in //compatibility/... tests
bazel_dep(name = "rules_proto", version = "4.0.0", dev_dependency = True)
9 changes: 9 additions & 0 deletions bazel/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ load("//bazel/private:native_bool_flag.bzl", "native_bool_flag")

licenses(["notice"])

toolchain_type(
name = "proto_toolchain_type",
)

bzl_library(
name = "upb_proto_library_internal_bzl",
srcs = [
Expand Down Expand Up @@ -40,6 +44,11 @@ bzl_library(
"proto_toolchain_rule.bzl",
],
visibility = ["//bazel:__subpackages__"],
deps = [
":toolchain_helpers_bzl",
"//bazel/common:proto_common_bzl",
"//bazel/common:proto_lang_toolchain_info_bzl",
],
)

bzl_library(
Expand Down
8 changes: 2 additions & 6 deletions bazel/private/proto_toolchain_rule.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
"""A Starlark implementation of the proto_toolchain rule."""

load("//bazel/common:proto_common.bzl", "proto_common")
load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo")
load("//bazel/private:toolchain_helpers.bzl", "toolchains")

def _impl(ctx):
kwargs = {}
if getattr(proto_common, "INCOMPATIBLE_PASS_TOOLCHAIN_TYPE", False):
kwargs["toolchain_type"] = "@rules_proto//proto:toolchain_type"

return [
DefaultInfo(
files = depset(),
Expand All @@ -23,7 +19,7 @@ def _impl(ctx):
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
progress_message = ctx.attr.progress_message,
mnemonic = ctx.attr.mnemonic,
**kwargs
toolchain_type = toolchains.PROTO_TOOLCHAIN,
),
),
]
Expand Down
2 changes: 1 addition & 1 deletion bazel/private/toolchain_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ toolchains = struct(
find_toolchain = _find_toolchain,
if_legacy_toolchain = _if_legacy_toolchain,
INCOMPATIBLE_ENABLE_PROTO_TOOLCHAIN_RESOLUTION = _incompatible_toolchain_resolution,
PROTO_TOOLCHAIN = "@rules_proto//proto:toolchain_type",
PROTO_TOOLCHAIN = "//bazel/private:proto_toolchain_type",
)
1 change: 1 addition & 0 deletions bazel/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
"//bazel/private:proto_toolchain_rule_bzl",
"//bazel/private:toolchain_helpers_bzl",
],
)

Expand Down
3 changes: 2 additions & 1 deletion bazel/toolchains/proto_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The macro additionally creates toolchain target when toolchain_type is given.
"""

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

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

native.toolchain(
name = name + "_toolchain",
toolchain_type = "@rules_proto//proto:toolchain_type",
toolchain_type = toolchains.PROTO_TOOLCHAIN,
exec_compatible_with = exec_compatible_with,
target_compatible_with = [],
toolchain = name,
Expand Down
11 changes: 0 additions & 11 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,6 @@ def protobuf_deps():
sha256 = "160d1ebf33763124766fb35316329d907ca67f733238aa47624a8e3ff3cf2ef4",
)

# TODO: remove after toolchain types are moved to protobuf
if not native.existing_rule("rules_proto"):
http_archive(
name = "rules_proto",
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
strip_prefix = "rules_proto-5.3.0-21.7",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
],
)

if not native.existing_rule("proto_bazel_features"):
proto_bazel_features(name = "proto_bazel_features")

Expand Down

0 comments on commit 9f9cb7a

Please sign in to comment.