1 # Protocol Buffers - Google's data interchange format
2 # Copyright 2024 Google Inc. All rights reserved.
4 # Use of this source code is governed by a BSD-style
5 # license that can be found in the LICENSE file or at
6 # https://developers.google.com/open-source/licenses/bsd
8 """proto_lang_toolchain rule"""
10 load("@proto_bazel_features//:features.bzl", "bazel_features")
11 load("//bazel/common:proto_common.bzl", "proto_common")
12 load("//bazel/private:proto_lang_toolchain_rule.bzl", _proto_lang_toolchain_rule = "proto_lang_toolchain")
14 def proto_lang_toolchain(*, name, toolchain_type = None, exec_compatible_with = [], target_compatible_with = [], **attrs):
15 """Creates a proto_lang_toolchain and corresponding toolchain target.
17 Toolchain target is only created when toolchain_type is set.
19 https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_lang_toolchain
23 name: name of the toolchain
24 toolchain_type: The toolchain type
25 exec_compatible_with: ([constraints]) List of constraints the prebuild binaries is compatible with.
26 target_compatible_with: ([constraints]) List of constraints the target libraries are compatible with.
27 **attrs: Rule attributes
30 if getattr(proto_common, "INCOMPATIBLE_PASS_TOOLCHAIN_TYPE", False):
31 attrs["toolchain_type"] = toolchain_type
33 # This condition causes Starlark rules to be used only on Bazel >=7.0.0
34 if bazel_features.proto.starlark_proto_info:
35 _proto_lang_toolchain_rule(name = name, **attrs)
37 # On older Bazel versions keep using native rules, so that mismatch in ProtoInfo doesn't happen
38 native.proto_lang_toolchain(name = name, **attrs)
42 name = name + "_toolchain",
43 toolchain_type = toolchain_type,
44 exec_compatible_with = exec_compatible_with,
45 target_compatible_with = target_compatible_with,