From 418b589ed23a3789b2fc3bb17b717a4889f00442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 18 Apr 2022 12:17:03 +0300 Subject: [PATCH] example transitions only change platforms, leave toolchains for WORKSPACE --- WORKSPACE | 12 +++++++----- rules/platform.bzl | 11 ++--------- test/c/BUILD | 10 ---------- test/go/BUILD | 32 +++++++++++++++----------------- 4 files changed, 24 insertions(+), 41 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 3ac9b8b..afa9b8a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -50,17 +50,19 @@ load( zig_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_arm64_gnu.2.28", "@zig_sdk//toolchain:darwin_amd64", "@zig_sdk//toolchain:darwin_arm64", - # when a libc-aware platform is selected, these will be used. arm64: - "@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28", - "@zig_sdk//libc_aware/toolchain:linux_arm64_musl", - # ditto, amd64: + # amd64 toolchains for libc-aware platforms: "@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.31", "@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", ) diff --git a/rules/platform.bzl b/rules/platform.bzl index 268dfd6..aabb328 100644 --- a/rules/platform.bzl +++ b/rules/platform.bzl @@ -2,7 +2,6 @@ def _platform_transition_impl(settings, attr): _ignore = settings return { "//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( @@ -10,7 +9,6 @@ _platform_transition = transition( inputs = [], outputs = [ "//command_line_option:platforms", - "//command_line_option:extra_toolchains", ], ) @@ -40,16 +38,12 @@ _attrs = { "platform": attr.string( 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( default = "@bazel_tools//tools/allowlists/function_transition_allowlist", ), } -# wrap a single exectable and build it for the specified platform passing in -# the extra_toolchains. +# wrap a single exectable and build it for the specified platform. platform_binary = rule( implementation = _platform_binary_impl, cfg = _platform_transition, @@ -57,8 +51,7 @@ platform_binary = rule( executable = True, ) -# wrap a single test target and build it for the specified platform passing in -# the extra_toolchains. +# wrap a single test target and build it for the specified platform. platform_test = rule( implementation = _platform_binary_impl, cfg = _platform_transition, diff --git a/test/c/BUILD b/test/c/BUILD index 69d259e..99e36c4 100644 --- a/test/c/BUILD +++ b/test/c/BUILD @@ -13,16 +13,6 @@ cc_binary( platform_binary( name = "which_libc_{}".format(name), 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, ), sh_test( diff --git a/test/go/BUILD b/test/go/BUILD index e5206fd..6c40c2e 100644 --- a/test/go/BUILD +++ b/test/go/BUILD @@ -24,31 +24,29 @@ go_test( [ platform_binary( - name = "go_{}".format(toolchain), + name = "go_{}".format(name), src = "go", - extra_toolchains = ["//toolchain:{}".format(toolchain)], - platform = "//platform:{}".format(platform), + platform = platform, ) - for platform, toolchain in [ - ("linux_amd64", "linux_amd64_musl"), - ("linux_amd64", "linux_amd64_gnu.2.19"), - ("linux_arm64", "linux_arm64_musl"), - ("linux_arm64", "linux_arm64_gnu.2.28"), - ("darwin_amd64", "darwin_amd64"), + for name, platform in [ + ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"), + ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"), + ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"), + ("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"), + ("darwin_amd64", "//platform:darwin_amd64"), ] ] [ platform_test( - name = "go_test_{}".format(toolchain), + name = "go_test_{}".format(name), src = "go_test", - extra_toolchains = ["//toolchain:{}".format(toolchain)], - platform = "//platform:{}".format(platform), + platform = platform, ) - for platform, toolchain in [ - ("linux_amd64", "linux_amd64_musl"), - ("linux_amd64", "linux_amd64_gnu.2.19"), - ("linux_arm64", "linux_arm64_musl"), - ("linux_arm64", "linux_arm64_gnu.2.28"), + for name, platform in [ + ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl"), + ("linux_amd64_gnu.2.19", "//libc_aware/platform:linux_amd64_gnu.2.19"), + ("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"), + ("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"), ] ]