From 100c1e372726446ed97dbbe43cbe0c934f280b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 10 Jun 2021 13:02:35 +0300 Subject: [PATCH] remove `.2.19` from toolchain params Only the default toolchain can be exposed. --- .build.yml | 6 +++--- README.md | 6 +++--- toolchain/BUILD.sdk.bazel | 36 +++++------------------------------- toolchain/defs.bzl | 16 ++++++++++++++-- toolchain/zig_toolchain.bzl | 3 ++- 5 files changed, 27 insertions(+), 40 deletions(-) diff --git a/.build.yml b/.build.yml index 2fc69ae..c8942c4 100644 --- a/.build.yml +++ b/.build.yml @@ -15,13 +15,13 @@ tasks: //test:gognu - test_linux-gnu: | cd bazel-zig-cc; ../bazel run \ - --platforms @zig_sdk//:platform_x86_64-linux-gnu \ + --platforms @zig_sdk//:x86_64-linux-gnu \ //test:gognu - test_linux-musl: | cd bazel-zig-cc; ../bazel run \ - --platforms @zig_sdk//:platform_x86_64-linux-musl \ + --platforms @zig_sdk//:x86_64-linux-musl \ //test:gomusl #- test_macos-gnu: | # cd bazel-zig-cc; ../bazel build --toolchain_resolution_debug=true \ - # --platforms @zig_sdk//:platform_x86_64-macos-gnu \ + # --platforms @zig_sdk//:x86_64-macos-gnu \ # //test:gognu diff --git a/README.md b/README.md index 2ee174d..872a382 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ $ file ../bazel-bin/test/gognu_/gognu Explicitly the toolchain explicitly `-gnu`: ``` -$ bazel run --platforms @zig_sdk//:platform_x86_64-linux-gnu //test:gognu +$ bazel run --platforms @zig_sdk//:x86_64-linux-gnu //test:gognu ``` ## linux cgo + musl ``` -$ bazel build --platforms @zig_sdk//:platform_x86_64-linux-musl //test:gomusl +$ bazel build --platforms @zig_sdk//:x86_64-linux-musl //test:gomusl ... $ file ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl ../bazel-out/k8-fastbuild-ST-d17813c235ce/bin/test/gomusl_/gomusl: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=redacted, with debug_info, not stripped @@ -54,7 +54,7 @@ hello, world Does not work? ``` -$ bazel build --platforms @zig_sdk//:platform_x86_64-macos-musl //test:gognu +$ bazel build --platforms @zig_sdk//:x86_64-macos-musl //test:gognu ... ``` diff --git a/toolchain/BUILD.sdk.bazel b/toolchain/BUILD.sdk.bazel index 6c385b1..2647601 100644 --- a/toolchain/BUILD.sdk.bazel +++ b/toolchain/BUILD.sdk.bazel @@ -1,36 +1,10 @@ load("@zig-cc-bazel//toolchain:defs.bzl", "zig_build_macro") -package(default_visibility = ["//visibility:public"]) -zig_build_macro(absolute_path={absolute_path}, zig_include_root={zig_include_root}) -constraint_setting(name = "libc") - -constraint_value( - name = "musl", - constraint_setting = ":libc", +package( + default_visibility = ["//visibility:public"] ) - -platform( - name = "platform_x86_64-macos-gnu", - constraint_values = [ - "@platforms//os:macos", - "@platforms//cpu:x86_64", - ], -) - -platform( - name = "platform_x86_64-linux-gnu", - constraint_values = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], -) - -platform( - name = "platform_x86_64-linux-musl", - constraint_values = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ":musl", - ], +zig_build_macro( + absolute_path={absolute_path}, + zig_include_root={zig_include_root}, ) diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index e600d89..318f3ce 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -39,7 +39,8 @@ TARGET_CONFIGS = [ tool_paths={"ld": "ld64.lld"}, ), struct( - target="x86_64-linux-gnu.2.19", + target="x86_64-linux-gnu", + target_suffix = ".2.19", includes=[ "libunwind/include", "libc/include/generic-glibc", @@ -182,11 +183,21 @@ def zig_build_macro(absolute_path, zig_include_root): filegroup(name="zig_compiler", srcs=["zig"]) filegroup(name="lib/std", srcs=native.glob(["lib/std/**"])) + native.constraint_setting(name = "libc") + + native.constraint_value( + name = "musl", + constraint_setting = ":libc", + ) + lazy_filegroups = {} for target_config in TARGET_CONFIGS: target = target_config.target - native.platform(name = target, constraint_values = target_config.constraint_values) + native.platform( + name = target, + constraint_values = target_config.constraint_values, + ) all_srcs = [] ar_srcs = [":zig_compiler"] @@ -219,6 +230,7 @@ def zig_build_macro(absolute_path, zig_include_root): zig_cc_toolchain_config( name = target + "_cc_toolchain_config", target = target, + target_suffix = getattr(target_config, 'target_suffix', ''), tool_paths = absolute_tool_paths, cxx_builtin_include_directories = cxx_builtin_include_directories, copts = target_config.copts, diff --git a/toolchain/zig_toolchain.bzl b/toolchain/zig_toolchain.bzl index 66f38e1..bd6fcdd 100644 --- a/toolchain/zig_toolchain.bzl +++ b/toolchain/zig_toolchain.bzl @@ -40,7 +40,7 @@ def _zig_cc_toolchain_config_impl(ctx): "-I" + d for d in ctx.attr.cxx_builtin_include_directories ] + [ - "-target", ctx.attr.target, + "-target", ctx.attr.target + ctx.attr.target_suffix, "-no-canonical-prefixes", "-Wno-builtin-macro-redefined", "-D__DATE__=\"redacted\"", @@ -104,6 +104,7 @@ zig_cc_toolchain_config = rule( "target_system_name": attr.string(), "target_cpu": attr.string(), "target_libc": attr.string(), + "target_suffix": attr.string(), "compiler": attr.string(), "abi_version": attr.string(), "abi_libc_version": attr.string(),