Skip to content

Commit c7d328c

Browse files
committed
[ci] Found a hacky way to cross-compile to aarch64
1 parent c1c3f0e commit c7d328c

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

ci/main.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ func hostArch() string {
4242
return canonArchFromGoArch(runtime.GOARCH)
4343
}
4444

45+
// This wrapper script pretends to be Gold linker (see issue link bellow).
46+
// TODO(dilyevsky): When Go team finally gets around fixing their
47+
// https://github.com/golang/go/issues/22040 hack, we can undo this hack.
48+
var zigWrapperScript = `#!/bin/sh
49+
50+
# Find the real zig executable
51+
REAL_ZIG=$(which -a zig | grep -v "$0" | head -1)
52+
53+
# Check if the command contains both required arguments
54+
case "$*" in
55+
*-fuse-ld=gold*-Wl,--version* | *-Wl,--version*-fuse-ld=gold*)
56+
echo "GNU gold"
57+
exit 0
58+
;;
59+
*)
60+
# Forward all other commands to the real zig
61+
exec "$REAL_ZIG" "$@"
62+
;;
63+
esac
64+
`
65+
4566
// BuilderContainer builds a CLI binary.
4667
func (m *ApoxyCli) BuilderContainer(ctx context.Context, src *dagger.Directory) *dagger.Container {
4768
return dag.Container().
@@ -65,6 +86,9 @@ func (m *ApoxyCli) BuilderContainer(ctx context.Context, src *dagger.Directory)
6586
WithExec([]string{
6687
"ln", "-s", fmt.Sprintf("/zig-linux-%s-0.13.0/zig", hostArch()), "/bin/zig",
6788
}).
89+
WithNewFile("/bin/zig-wrapper", zigWrapperScript, dagger.ContainerWithNewFileOpts{
90+
Permissions: 0755,
91+
}).
6892
WithDirectory("/src", src,
6993
dagger.ContainerWithDirectoryOpts{
7094
Exclude: []string{"secrets/**"}, // exclude secrets from build context
@@ -162,7 +186,7 @@ func (m *ApoxyCli) BuildAPIServer(
162186
WithEnvVariable("GOARCH", goarch).
163187
WithEnvVariable("GOOS", "linux").
164188
WithEnvVariable("CGO_ENABLED", "1").
165-
WithEnvVariable("CC", fmt.Sprintf("zig cc --target=%s-linux-musl", targetArch)).
189+
WithEnvVariable("CC", fmt.Sprintf("zig-wrapper cc --target=%s-linux-musl", targetArch)).
166190
WithExec([]string{"go", "build", "-o", "apiserver", "./cmd/apiserver"})
167191

168192
runtimeCtr := m.PullEdgeRuntime(ctx, string(platform))
@@ -198,11 +222,9 @@ func (m *ApoxyCli) BuildBackplane(
198222
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build-"+goarch)).
199223
WithEnvVariable("GOCACHE", "/go/build-cache")
200224

201-
if goarch == "amd64" {
202-
builder = builder.
203-
WithEnvVariable("CGO_ENABLED", "1").
204-
WithEnvVariable("CC", fmt.Sprintf("zig cc --target=%s-linux-musl", canonArchFromGoArch(goarch)))
205-
}
225+
builder = builder.
226+
WithEnvVariable("CGO_ENABLED", "1").
227+
WithEnvVariable("CC", fmt.Sprintf("zig-wrapper cc --target=%s-linux-musl", canonArchFromGoArch(goarch)))
206228

207229
builder = builder.
208230
WithExec([]string{"go", "build", "-ldflags", "-v -linkmode=external", "-o", bpOut, "./cmd/backplane"}).
@@ -241,10 +263,7 @@ func (m *ApoxyCli) PublishImages(
241263
fmt.Println("API server image published to", addr)
242264

243265
var bCtrs []*dagger.Container
244-
// TODO(dilyevsky): When Go team finally gets around fixing their
245-
// https://github.com/golang/go/issues/22040 hack, we can enable arm64
246-
// builds in CI.
247-
for _, platform := range []string{"linux/amd64" /* "linux/arm64", */} {
266+
for _, platform := range []string{"linux/amd64", "linux/arm64"} {
248267
bCtr := m.BuildBackplane(ctx, src, platform)
249268
bCtrs = append(bCtrs, bCtr)
250269
}

0 commit comments

Comments
 (0)