Skip to content

Commit 30d2332

Browse files
jagub2copybara-github
authored andcommitted
Add target_compatible_with parameter to proto_toolchain in Bazel rules (#22429)
In some cases, few targets can require different proto_toolchains. In my case, my project defines different toolchains and each of them can define its own Protobuf compiler from its SDK, independent of the others. Restricting it with exec_compatible_with is not an option, since each target is built on the same x86_64 system. I patched this Bazel file in my build system and thus was able to define the Protobuf compiler independently for each target. Closes #22429 COPYBARA_INTEGRATE_REVIEW=#22429 from jagub2:proto_toolchain_target_compatibility 6539aad PiperOrigin-RevId: 785828194
1 parent 00c3c30 commit 30d2332

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

bazel/toolchains/proto_toolchain.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The macro additionally creates toolchain target when toolchain_type is given.
1313
load("//bazel/private:proto_toolchain_rule.bzl", _proto_toolchain_rule = "proto_toolchain")
1414
load("//bazel/private:toolchain_helpers.bzl", "toolchains")
1515

16-
def proto_toolchain(*, name, proto_compiler, exec_compatible_with = []):
16+
def proto_toolchain(*, name, proto_compiler, exec_compatible_with = [], target_compatible_with = []):
1717
"""Creates a proto_toolchain and toolchain target for proto_library.
1818
1919
Toolchain target is suffixed with "_toolchain".
@@ -22,13 +22,14 @@ def proto_toolchain(*, name, proto_compiler, exec_compatible_with = []):
2222
name: name of the toolchain
2323
proto_compiler: (Label) of either proto compiler sources or prebuild binaries
2424
exec_compatible_with: ([constraints]) List of constraints the prebuild binary is compatible with.
25+
target_compatible_with: ([constraints]) List of constraints the target it is compatible with.
2526
"""
2627
_proto_toolchain_rule(name = name, proto_compiler = proto_compiler)
2728

2829
native.toolchain(
2930
name = name + "_toolchain",
3031
toolchain_type = toolchains.PROTO_TOOLCHAIN,
3132
exec_compatible_with = exec_compatible_with,
32-
target_compatible_with = [],
33+
target_compatible_with = target_compatible_with,
3334
toolchain = name,
3435
)

0 commit comments

Comments
 (0)