从这里的例子开始:https://github.com/PiotrSikora/bazel-zig-cc/blob/main/rules_go.bzl。
我正试图将它扩大到以下几个方面:
- Same flags for linux targets
- "-l" and "-w" for BSD target
- Add "-trimpath" for all targets
然而,我甚至难以做到(1)。 我的守则是:
_MACOS_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie","-trimpath"]
_LINUX_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie","-trimpath"]
def go_binary(**kwargs):
kwargs["gc_linkopts"] = select({
"@platforms//os:macos": _MACOS_GC_LINKOPTS,
"@platforms//os:linux": _LINUX_GC_LINKOPTS,
"//conditions:default": [],
}) + kwargs.pop("gc_linkopts", [])
go_binary_rule(**kwargs)
我发现的错误是:
flag provided but not defined: -trimpath