1

example transitions only change platforms, leave toolchains for WORKSPACE

This commit is contained in:
Motiejus Jakštys 2022-04-18 12:17:03 +03:00
parent a53170cf82
commit 418b589ed2
4 changed files with 24 additions and 41 deletions

View File

@ -50,17 +50,19 @@ load(
zig_toolchains() zig_toolchains()
register_toolchains( register_toolchains(
# if no `--platform` is selected, these toolchains will be used. # if no `--platform` is specified, these toolchains will be used for
# (linux,darwin)x(amd64,arm64)
"@zig_sdk//toolchain:linux_amd64_gnu.2.19", "@zig_sdk//toolchain:linux_amd64_gnu.2.19",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28", "@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64", "@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64", "@zig_sdk//toolchain:darwin_arm64",
# when a libc-aware platform is selected, these will be used. arm64: # amd64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
# ditto, amd64:
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.19", "@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.19",
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.28", "@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.31",
"@zig_sdk//libc_aware/toolchain:linux_amd64_musl", "@zig_sdk//libc_aware/toolchain:linux_amd64_musl",
# arm64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
) )

View File

@ -2,7 +2,6 @@ def _platform_transition_impl(settings, attr):
_ignore = settings _ignore = settings
return { return {
"//command_line_option:platforms": "@zig_sdk{}".format(attr.platform), "//command_line_option:platforms": "@zig_sdk{}".format(attr.platform),
"//command_line_option:extra_toolchains": ["@zig_sdk{}".format(tc) for tc in attr.extra_toolchains],
} }
_platform_transition = transition( _platform_transition = transition(
@ -10,7 +9,6 @@ _platform_transition = transition(
inputs = [], inputs = [],
outputs = [ outputs = [
"//command_line_option:platforms", "//command_line_option:platforms",
"//command_line_option:extra_toolchains",
], ],
) )
@ -40,16 +38,12 @@ _attrs = {
"platform": attr.string( "platform": attr.string(
doc = "The platform to build the target for.", doc = "The platform to build the target for.",
), ),
"extra_toolchains": attr.string_list(
doc = "The toolchains to provide as extra_toolchains.",
),
"_allowlist_function_transition": attr.label( "_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist", default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
), ),
} }
# wrap a single exectable and build it for the specified platform passing in # wrap a single exectable and build it for the specified platform.
# the extra_toolchains.
platform_binary = rule( platform_binary = rule(
implementation = _platform_binary_impl, implementation = _platform_binary_impl,
cfg = _platform_transition, cfg = _platform_transition,
@ -57,8 +51,7 @@ platform_binary = rule(
executable = True, executable = True,
) )
# wrap a single test target and build it for the specified platform passing in # wrap a single test target and build it for the specified platform.
# the extra_toolchains.
platform_test = rule( platform_test = rule(
implementation = _platform_binary_impl, implementation = _platform_binary_impl,
cfg = _platform_transition, cfg = _platform_transition,

View File

@ -13,16 +13,6 @@ cc_binary(
platform_binary( platform_binary(
name = "which_libc_{}".format(name), name = "which_libc_{}".format(name),
src = "which_libc", src = "which_libc",
extra_toolchains = [
# toolchains for specific libc versions
"//libc_aware/toolchain:linux_amd64_gnu.2.19",
"//libc_aware/toolchain:linux_amd64_gnu.2.28",
"//libc_aware/toolchain:linux_amd64_gnu.2.31",
"//libc_aware/toolchain:linux_amd64_musl",
# fallback toolchains
"//toolchain:linux_amd64_gnu.2.19",
"//toolchain:linux_arm64_gnu.2.28",
],
platform = platform, platform = platform,
), ),
sh_test( sh_test(

View File

@ -24,31 +24,29 @@ go_test(
[ [
platform_binary( platform_binary(
name = "go_{}".format(toolchain), name = "go_{}".format(name),
src = "go", src = "go",
extra_toolchains = ["//toolchain:{}".format(toolchain)], platform = platform,
platform = "//platform:{}".format(platform),
) )
for platform, toolchain in [ for name, platform in [
("linux_amd64", "linux_amd64_musl"), ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"),
("linux_amd64", "linux_amd64_gnu.2.19"), ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"),
("linux_arm64", "linux_arm64_musl"), ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"),
("linux_arm64", "linux_arm64_gnu.2.28"), ("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"),
("darwin_amd64", "darwin_amd64"), ("darwin_amd64", "//platform:darwin_amd64"),
] ]
] ]
[ [
platform_test( platform_test(
name = "go_test_{}".format(toolchain), name = "go_test_{}".format(name),
src = "go_test", src = "go_test",
extra_toolchains = ["//toolchain:{}".format(toolchain)], platform = platform,
platform = "//platform:{}".format(platform),
) )
for platform, toolchain in [ for name, platform in [
("linux_amd64", "linux_amd64_musl"), ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"),
("linux_amd64", "linux_amd64_gnu.2.19"), ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"),
("linux_arm64", "linux_arm64_musl"), ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"),
("linux_arm64", "linux_arm64_gnu.2.28"), ("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"),
] ]
] ]