Skip to content

Commit 608791f

Browse files
committed
Bazel/Go: use native cross compilation for fat binaries
1 parent 2590d8a commit 608791f

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

go/rules.bzl

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
load("@rules_go//go:def.bzl", "go_binary")
2-
load("//misc/bazel:universal_binary.bzl", "wrap_as_universal_binary")
1+
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary")
32

4-
def codeql_go_binary(**kwargs):
5-
wrap_as_universal_binary(go_binary, **kwargs)
3+
def codeql_go_binary(*, name, visibility = None, **kwargs):
4+
def internal(prefix = "internal"):
5+
return "%s/%s" % (prefix, name)
6+
7+
go_binary(
8+
name = internal(),
9+
visibility = ["//visibility:private"],
10+
**kwargs
11+
)
12+
macos_targets = ("darwin_arm64", "darwin_amd64")
13+
for target in macos_targets:
14+
go_cross_binary(
15+
name = internal(target),
16+
platform = "@rules_go//go/toolchain:%s" % target,
17+
target = internal(),
18+
target_compatible_with = ["@platforms//os:macos"],
19+
visibility = ["//visibility:private"],
20+
)
21+
native.genrule(
22+
name = internal("universal"),
23+
outs = [internal("universal_")],
24+
srcs = [internal(t) for t in macos_targets],
25+
target_compatible_with = ["@platforms//os:macos"],
26+
executable = True,
27+
visibility = ["//visibility:private"],
28+
cmd = "lipo -create $(SRCS) -output $@",
29+
)
30+
native.alias(
31+
name = name,
32+
actual = select({
33+
"@platforms//os:macos": internal("universal"),
34+
"//conditions:default": internal(),
35+
}),
36+
visibility = visibility,
37+
)

misc/bazel/universal_binary.bzl

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)