From f50493ca72129dfee2ed0ffe24483de95e59e455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 7 Nov 2021 12:31:24 +0200 Subject: [PATCH] move go_binary_override to rules_go also, do not ignore the user's gc_linkopts. --- BUILD | 2 +- .../{go_binary_override.bzl => rules_go.bzl} | 21 +++++++------------ test/BUILD | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) rename rules/{go_binary_override.bzl => rules_go.bzl} (57%) diff --git a/BUILD b/BUILD index a34acae..158480f 100644 --- a/BUILD +++ b/BUILD @@ -1,7 +1,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle") load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") -# gazelle:map_kind go_binary go_binary //rules:go_binary_override.bzl +# gazelle:map_kind go_binary go_binary //rules:rules_go.bzl # gazelle:build_file_name BUILD # gazelle:prefix github.com/motiejus/bazel-zig-cc diff --git a/rules/go_binary_override.bzl b/rules/rules_go.bzl similarity index 57% rename from rules/go_binary_override.bzl rename to rules/rules_go.bzl index 73be848..f4d860a 100644 --- a/rules/go_binary_override.bzl +++ b/rules/rules_go.bzl @@ -8,19 +8,14 @@ where target binary needs to be compiled with zig toolchain. Example: if this toolchain is registered as bazel-zig-cc in your WORKSPACE, add this to your root BUILD file -# gazelle:map_kind go_binary go_binary @bazel-zig-cc//rules:go_binary_override.bzl +# gazelle:map_kind go_binary go_binary @bazel-zig-cc//rules:rules_go.bzl """ -def go_binary(**args): - new_args = {} - new_args["gc_linkopts"] = select({ - "@platforms//os:macos": [ - "-s", - "-w", - "-buildmode=pie", - ], +_MACOS_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie"] + +def go_binary(**kwargs): + kwargs["gc_linkopts"] = select({ + "@platforms//os:macos": _MACOS_GC_LINKOPTS, "//conditions:default": [], - }) - for k, v in args.items(): - new_args[k] = v - go_binary_rule(**new_args) + }) + kwargs.pop("gc_linkopts", []) + go_binary_rule(**kwargs) diff --git a/test/BUILD b/test/BUILD index 415b9c2..6f67d05 100644 --- a/test/BUILD +++ b/test/BUILD @@ -1,4 +1,4 @@ -load("//rules:go_binary_override.bzl", "go_binary") +load("//rules:rules_go.bzl", "go_binary") load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library(