1

move go_binary_override to rules_go

also, do not ignore the user's gc_linkopts.
This commit is contained in:
Motiejus Jakštys 2021-11-07 12:31:24 +02:00
parent c549c095ab
commit f50493ca72
3 changed files with 10 additions and 15 deletions

2
BUILD
View File

@ -1,7 +1,7 @@
load("@bazel_gazelle//:def.bzl", "gazelle") load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") 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:build_file_name BUILD
# gazelle:prefix github.com/motiejus/bazel-zig-cc # gazelle:prefix github.com/motiejus/bazel-zig-cc

View File

@ -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 Example: if this toolchain is registered as bazel-zig-cc in your WORKSPACE, add this to
your root BUILD file 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): _MACOS_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie"]
new_args = {}
new_args["gc_linkopts"] = select({ def go_binary(**kwargs):
"@platforms//os:macos": [ kwargs["gc_linkopts"] = select({
"-s", "@platforms//os:macos": _MACOS_GC_LINKOPTS,
"-w",
"-buildmode=pie",
],
"//conditions:default": [], "//conditions:default": [],
}) }) + kwargs.pop("gc_linkopts", [])
for k, v in args.items(): go_binary_rule(**kwargs)
new_args[k] = v
go_binary_rule(**new_args)

View File

@ -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") load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library( go_library(