diff --git a/MODULE.bazel b/MODULE.bazel index fcf2eeaa958a7..05128b355cc18 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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) \ No newline at end of file diff --git a/bazel/private/BUILD.bazel b/bazel/private/BUILD.bazel index 407c325916129..c90632d7b0ed0 100644 --- a/bazel/private/BUILD.bazel +++ b/bazel/private/BUILD.bazel @@ -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( diff --git a/bazel/private/proto_toolchain_rule.bzl b/bazel/private/proto_toolchain_rule.bzl index 9487a06026dec..8a11fac9db02c 100644 --- a/bazel/private/proto_toolchain_rule.bzl +++ b/bazel/private/proto_toolchain_rule.bzl @@ -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, ), ), ] diff --git a/bazel/private/toolchain_helpers.bzl b/bazel/private/toolchain_helpers.bzl index e58c9d6a0ece8..aa49eb8cf4c88 100644 --- a/bazel/private/toolchain_helpers.bzl +++ b/bazel/private/toolchain_helpers.bzl @@ -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", ) diff --git a/bazel/toolchains/BUILD.bazel b/bazel/toolchains/BUILD.bazel index 34a45d5bbd833..2c21426b15345 100644 --- a/bazel/toolchains/BUILD.bazel +++ b/bazel/toolchains/BUILD.bazel @@ -8,6 +8,7 @@ bzl_library( visibility = ["//visibility:public"], deps = [ "//bazel/private:proto_toolchain_rule_bzl", + "//bazel/private:toolchain_helpers_bzl", ], ) diff --git a/bazel/toolchains/proto_toolchain.bzl b/bazel/toolchains/proto_toolchain.bzl index 171e08cad5aca..1bad37b3a65ce 100644 --- a/bazel/toolchains/proto_toolchain.bzl +++ b/bazel/toolchains/proto_toolchain.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, diff --git a/protobuf_deps.bzl b/protobuf_deps.bzl index 97f95e3ac4a1c..0c90a525d4a35 100644 --- a/protobuf_deps.bzl +++ b/protobuf_deps.bzl @@ -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")