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
pull/17480/head
Protobuf Team Bot 8 months ago committed by Copybara-Service
parent d44c0d577c
commit 9f9cb7a10e
  1. 5
      MODULE.bazel
  2. 9
      bazel/private/BUILD.bazel
  3. 8
      bazel/private/proto_toolchain_rule.bzl
  4. 2
      bazel/private/toolchain_helpers.bzl
  5. 1
      bazel/toolchains/BUILD.bazel
  6. 3
      bazel/toolchains/proto_toolchain.bzl
  7. 11
      protobuf_deps.bzl

@ -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",
@ -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)

@ -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 = [
@ -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(

@ -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(),
@ -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,
),
),
]

@ -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",
)

@ -8,6 +8,7 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
"//bazel/private:proto_toolchain_rule_bzl",
"//bazel/private:toolchain_helpers_bzl",
],
)

@ -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.
@ -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,

@ -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")

Loading…
Cancel
Save