Bazel/Go: use native cross compilation for fat binaries

This commit is contained in:
Paolo Tranquilli 2024-05-02 09:13:40 +02:00
Родитель 2590d8a27f
Коммит 608791fd7f
2 изменённых файлов: 36 добавлений и 28 удалений

Просмотреть файл

@ -1,5 +1,37 @@
load("@rules_go//go:def.bzl", "go_binary")
load("//misc/bazel:universal_binary.bzl", "wrap_as_universal_binary")
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary")
def codeql_go_binary(**kwargs):
wrap_as_universal_binary(go_binary, **kwargs)
def codeql_go_binary(*, name, visibility = None, **kwargs):
def internal(prefix = "internal"):
return "%s/%s" % (prefix, name)
go_binary(
name = internal(),
visibility = ["//visibility:private"],
**kwargs
)
macos_targets = ("darwin_arm64", "darwin_amd64")
for target in macos_targets:
go_cross_binary(
name = internal(target),
platform = "@rules_go//go/toolchain:%s" % target,
target = internal(),
target_compatible_with = ["@platforms//os:macos"],
visibility = ["//visibility:private"],
)
native.genrule(
name = internal("universal"),
outs = [internal("universal_")],
srcs = [internal(t) for t in macos_targets],
target_compatible_with = ["@platforms//os:macos"],
executable = True,
visibility = ["//visibility:private"],
cmd = "lipo -create $(SRCS) -output $@",
)
native.alias(
name = name,
actual = select({
"@platforms//os:macos": internal("universal"),
"//conditions:default": internal(),
}),
visibility = visibility,
)

Просмотреть файл

@ -1,24 +0,0 @@
load("@apple_support//rules:universal_binary.bzl", _universal_binary = "universal_binary")
def wrap_as_universal_binary(rule, *, name, visibility = None, **kwargs):
internal_name = "internal/%s" % name
universal_name = "universal/%s" % name
rule(
name = internal_name,
visibility = ["//visibility:private"],
**kwargs
)
_universal_binary(
name = universal_name,
target_compatible_with = ["@platforms//os:macos"],
binary = internal_name,
visibility = ["//visibility:private"],
)
native.alias(
name = name,
actual = select({
"@platforms//os:macos": universal_name,
"//conditions:default": internal_name,
}),
visibility = visibility,
)