2023-03-02 23:42:35 +02:00
|
|
|
# Copyright 2023 Uber Technologies, Inc.
|
2023-04-20 03:23:25 +03:00
|
|
|
# Licensed under the MIT License
|
2023-03-02 23:42:35 +02:00
|
|
|
|
2021-11-05 19:29:07 +02:00
|
|
|
load("@io_bazel_rules_go//go:def.bzl", go_binary_rule = "go_binary")
|
|
|
|
|
|
|
|
"""
|
|
|
|
go_binary overrides go_binary from rules_go and provides default
|
|
|
|
gc_linkopts values that are needed to compile for macos target.
|
|
|
|
To use it, add this map_kind gazelle directive to your BUILD.bazel files
|
|
|
|
where target binary needs to be compiled with zig toolchain.
|
|
|
|
|
2023-04-21 17:00:03 +03:00
|
|
|
Example: if this toolchain is registered as hermetic_cc_toolchain in your WORKSPACE, add this to
|
2021-11-05 19:29:07 +02:00
|
|
|
your root BUILD file
|
2023-04-21 17:00:03 +03:00
|
|
|
# gazelle:map_kind go_binary go_binary @hermetic_cc_toolchain//rules:rules_go.bzl
|
2021-11-05 19:29:07 +02:00
|
|
|
"""
|
|
|
|
|
2021-11-07 12:31:24 +02:00
|
|
|
_MACOS_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie"]
|
|
|
|
|
|
|
|
def go_binary(**kwargs):
|
|
|
|
kwargs["gc_linkopts"] = select({
|
|
|
|
"@platforms//os:macos": _MACOS_GC_LINKOPTS,
|
2021-11-05 19:47:52 +02:00
|
|
|
"//conditions:default": [],
|
2021-11-07 12:31:24 +02:00
|
|
|
}) + kwargs.pop("gc_linkopts", [])
|
|
|
|
go_binary_rule(**kwargs)
|