@@ -42,6 +42,27 @@ func hostArch() string {
42
42
return canonArchFromGoArch (runtime .GOARCH )
43
43
}
44
44
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
+
45
66
// BuilderContainer builds a CLI binary.
46
67
func (m * ApoxyCli ) BuilderContainer (ctx context.Context , src * dagger.Directory ) * dagger.Container {
47
68
return dag .Container ().
@@ -65,6 +86,9 @@ func (m *ApoxyCli) BuilderContainer(ctx context.Context, src *dagger.Directory)
65
86
WithExec ([]string {
66
87
"ln" , "-s" , fmt .Sprintf ("/zig-linux-%s-0.13.0/zig" , hostArch ()), "/bin/zig" ,
67
88
}).
89
+ WithNewFile ("/bin/zig-wrapper" , zigWrapperScript , dagger.ContainerWithNewFileOpts {
90
+ Permissions : 0755 ,
91
+ }).
68
92
WithDirectory ("/src" , src ,
69
93
dagger.ContainerWithDirectoryOpts {
70
94
Exclude : []string {"secrets/**" }, // exclude secrets from build context
@@ -162,7 +186,7 @@ func (m *ApoxyCli) BuildAPIServer(
162
186
WithEnvVariable ("GOARCH" , goarch ).
163
187
WithEnvVariable ("GOOS" , "linux" ).
164
188
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 )).
166
190
WithExec ([]string {"go" , "build" , "-o" , "apiserver" , "./cmd/apiserver" })
167
191
168
192
runtimeCtr := m .PullEdgeRuntime (ctx , string (platform ))
@@ -198,11 +222,9 @@ func (m *ApoxyCli) BuildBackplane(
198
222
WithMountedCache ("/go/build-cache" , dag .CacheVolume ("go-build-" + goarch )).
199
223
WithEnvVariable ("GOCACHE" , "/go/build-cache" )
200
224
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 )))
206
228
207
229
builder = builder .
208
230
WithExec ([]string {"go" , "build" , "-ldflags" , "-v -linkmode=external" , "-o" , bpOut , "./cmd/backplane" }).
@@ -241,10 +263,7 @@ func (m *ApoxyCli) PublishImages(
241
263
fmt .Println ("API server image published to" , addr )
242
264
243
265
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" } {
248
267
bCtr := m .BuildBackplane (ctx , src , platform )
249
268
bCtrs = append (bCtrs , bCtr )
250
269
}
0 commit comments