Skip to content

Commit a950f88

Browse files
authored
fix: zig cc for portable standalone binaries with PKCS11 support (#779)
* fix: use zig cc for portable standalone binaries with PKCS11 support Replace static builds (which break dlopen/PKCS11) with zig cc portable builds targeting glibc 2.17+. Binaries are dynamically linked but run on virtually any Linux distro, including Amazon Linux 2023 (glibc 2.34), while preserving PKCS11/CloudHSM dlopen support. - Add zig cc wrapper scripts targeting glibc 2.17 for amd64/arm64/arm - Install zig toolchain in goreleaser before hooks - Replace static build targets with portable zig-cc builds - Fix buildx driver: remove docker driver for dockers_v2 attestation support, use imagetools create for snapshot retag * fix: use double quotes for sh -c in goreleaser before hooks * fix: goreleaser before hooks are plain strings, not maps * fix: bake zig cc into custom goreleaser-cross image Move zig toolchain and wrapper scripts into a custom Docker image (ghcr.io/ecadlabs/goreleaser-cross-zig) instead of downloading at release time. Eliminates runtime curl downloads and supply chain risk. - Add .goreleaser/Dockerfile extending goreleaser-cross with zig 0.14.0 - Remove wrapper scripts from repo (baked into image) - Remove before hooks (nothing to install at build time) - Use absolute CC paths via PATH (zig-cc-x86_64, etc.) - Update Makefile to use custom image * fix: revert to docker driver, disable attestations for dockers_v2 goreleaser snapshot mode doesn't push images, so imagetools create can't retag them. Revert to the docker driver with local image loading and manual tag/push for snapshots. Disable attestations (--provenance=false, --sbom=false) in dockers_v2 build_flags since the docker driver doesn't support them. * fix: use correct dockers_v2 fields (sbom, flags) to disable attestations
1 parent 81bd2de commit a950f88

File tree

3 files changed

+46
-54
lines changed

3 files changed

+46
-54
lines changed

.goreleaser.yml

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -108,113 +108,87 @@ builds:
108108
flags:
109109
- '{{ if .IsSnapshot }}-cover{{ else }}-v{{ end }}'
110110

111-
# Static builds (for standalone archives, no glibc dependency)
111+
# Portable builds (for standalone archives, targets glibc 2.17+ via zig cc)
112112
# Skipped during snapshot/PR builds to save CI time.
113-
# Uses the same glibc cross-compilers as dynamic builds but with static
114-
# linking flags. dlopen won't work (PKCS11 users should use Docker).
115-
- id: signatory-linux-amd-static
113+
# Dynamically linked against old glibc so dlopen/PKCS11 works everywhere.
114+
- id: signatory-linux-amd-portable
116115
skip: '{{ .IsSnapshot }}'
117116
binary: signatory
118117
env:
119118
- CGO_ENABLED=1
120-
- CC=gcc
119+
- CC=zig-cc-x86_64
121120
main: ./cmd/signatory/main.go
122-
tags:
123-
- netgo
124-
- osusergo
125121
ldflags:
126122
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
127123
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
128-
- '-linkmode external'
129-
- '-extldflags "-static"'
130124
goos:
131125
- linux
132126
goarch:
133127
- amd64
134128
flags:
135129
- -v
136130

137-
- id: signatory-cli-linux-amd-static
131+
- id: signatory-cli-linux-amd-portable
138132
skip: '{{ .IsSnapshot }}'
139133
binary: signatory-cli
140134
env:
141135
- CGO_ENABLED=1
142-
- CC=gcc
136+
- CC=zig-cc-x86_64
143137
main: ./cmd/signatory-cli/main.go
144-
tags:
145-
- netgo
146-
- osusergo
147138
ldflags:
148139
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
149140
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
150-
- '-linkmode external'
151-
- '-extldflags "-static"'
152141
goos:
153142
- linux
154143
goarch:
155144
- amd64
156145
flags:
157146
- -v
158147

159-
- id: signatory-linux-arm64-static
148+
- id: signatory-linux-arm64-portable
160149
skip: '{{ .IsSnapshot }}'
161150
binary: signatory
162151
env:
163152
- CGO_ENABLED=1
164-
- CC=aarch64-linux-gnu-gcc
153+
- CC=zig-cc-aarch64
165154
main: ./cmd/signatory/main.go
166-
tags:
167-
- netgo
168-
- osusergo
169155
ldflags:
170156
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
171157
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
172-
- '-linkmode external'
173-
- '-extldflags "-static"'
174158
goos:
175159
- linux
176160
goarch:
177161
- arm64
178162
flags:
179163
- -v
180164

181-
- id: signatory-cli-linux-arm64-static
165+
- id: signatory-cli-linux-arm64-portable
182166
skip: '{{ .IsSnapshot }}'
183167
binary: signatory-cli
184168
env:
185169
- CGO_ENABLED=1
186-
- CC=aarch64-linux-gnu-gcc
170+
- CC=zig-cc-aarch64
187171
main: ./cmd/signatory-cli/main.go
188-
tags:
189-
- netgo
190-
- osusergo
191172
ldflags:
192173
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
193174
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
194-
- '-linkmode external'
195-
- '-extldflags "-static"'
196175
goos:
197176
- linux
198177
goarch:
199178
- arm64
200179
flags:
201180
- -v
202181

203-
- id: signatory-linux-arm-static
182+
- id: signatory-linux-arm-portable
204183
skip: '{{ .IsSnapshot }}'
205184
binary: signatory
206185
env:
207186
- CGO_ENABLED=1
208-
- CC=arm-linux-gnueabihf-gcc
187+
- CC=zig-cc-arm
209188
main: ./cmd/signatory/main.go
210-
tags:
211-
- netgo
212-
- osusergo
213189
ldflags:
214190
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
215191
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
216-
- '-linkmode external'
217-
- '-extldflags "-static"'
218192
goos:
219193
- linux
220194
goarch:
@@ -224,21 +198,16 @@ builds:
224198
flags:
225199
- -v
226200

227-
- id: signatory-cli-linux-arm-static
201+
- id: signatory-cli-linux-arm-portable
228202
skip: '{{ .IsSnapshot }}'
229203
binary: signatory-cli
230204
env:
231205
- CGO_ENABLED=1
232-
- CC=arm-linux-gnueabihf-gcc
206+
- CC=zig-cc-arm
233207
main: ./cmd/signatory-cli/main.go
234-
tags:
235-
- netgo
236-
- osusergo
237208
ldflags:
238209
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitRevision={{.Version}}'
239210
- '-X github.com/ecadlabs/signatory/pkg/metrics.GitBranch={{.Version}}'
240-
- '-linkmode external'
241-
- '-extldflags "-static"'
242211
goos:
243212
- linux
244213
goarch:
@@ -250,12 +219,12 @@ builds:
250219

251220
archives:
252221
- ids:
253-
- signatory-linux-amd-static
254-
- signatory-cli-linux-amd-static
255-
- signatory-linux-arm64-static
256-
- signatory-cli-linux-arm64-static
257-
- signatory-linux-arm-static
258-
- signatory-cli-linux-arm-static
222+
- signatory-linux-amd-portable
223+
- signatory-cli-linux-amd-portable
224+
- signatory-linux-arm64-portable
225+
- signatory-cli-linux-arm64-portable
226+
- signatory-linux-arm-portable
227+
- signatory-cli-linux-arm-portable
259228

260229
dockers_v2:
261230
- id: release
@@ -282,6 +251,9 @@ dockers_v2:
282251
org.opencontainers.image.revision: '{{.FullCommit}}'
283252
org.opencontainers.image.version: '{{.Version}}'
284253
org.opencontainers.image.source: '{{.GitURL}}'
254+
sbom: false
255+
flags:
256+
- --provenance=false
285257
disable: '{{ .IsSnapshot }}'
286258
- id: snapshot
287259
ids:
@@ -306,6 +278,9 @@ dockers_v2:
306278
org.opencontainers.image.revision: '{{.FullCommit}}'
307279
org.opencontainers.image.version: '{{.Version}}'
308280
org.opencontainers.image.source: '{{.GitURL}}'
281+
sbom: false
282+
flags:
283+
- --provenance=false
309284
disable: '{{ not .IsSnapshot }}'
310285

311286
checksum:

.goreleaser/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ghcr.io/goreleaser/goreleaser-cross:v1.25.5
2+
3+
# Install zig toolchain at build time (not at release time).
4+
# This image is built once, pushed to our GHCR, and pinned by tag.
5+
ARG ZIG_VERSION=0.14.0
6+
RUN curl -sSL "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar.xz" \
7+
-o /tmp/zig.tar.xz && \
8+
tar xJf /tmp/zig.tar.xz -C /usr/local && \
9+
ln -sf "/usr/local/zig-linux-x86_64-${ZIG_VERSION}/zig" /usr/local/bin/zig && \
10+
rm /tmp/zig.tar.xz && \
11+
zig version
12+
13+
# Install zig cc wrapper scripts targeting glibc 2.17
14+
RUN printf '#!/bin/sh\nexec zig cc -target x86_64-linux-gnu.2.17 "$@"\n' > /usr/local/bin/zig-cc-x86_64 && \
15+
printf '#!/bin/sh\nexec zig cc -target aarch64-linux-gnu.2.17 "$@"\n' > /usr/local/bin/zig-cc-aarch64 && \
16+
printf '#!/bin/sh\nexec zig cc -target arm-linux-gnueabihf.2.17 "$@"\n' > /usr/local/bin/zig-cc-arm && \
17+
chmod +x /usr/local/bin/zig-cc-*

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ release-dry-run:
3434
-v /var/run/docker.sock:/var/run/docker.sock \
3535
-v `pwd`:/go/src/$(PACKAGE_NAME) \
3636
-w /go/src/$(PACKAGE_NAME) \
37-
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
37+
ghcr.io/ecadlabs/goreleaser-cross-zig:${GOLANG_CROSS_VERSION} \
3838
release \
3939
--clean \
4040
--snapshot
@@ -50,7 +50,7 @@ release-preview:
5050
-v $(HOME)/.docker:/root/.docker \
5151
-v `pwd`:/go/src/$(PACKAGE_NAME) \
5252
-w /go/src/$(PACKAGE_NAME) \
53-
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
53+
ghcr.io/ecadlabs/goreleaser-cross-zig:${GOLANG_CROSS_VERSION} \
5454
release \
5555
--clean \
5656
--snapshot
@@ -71,7 +71,7 @@ release:
7171
-v $(HOME)/.docker:/root/.docker \
7272
-v `pwd`:/go/src/$(PACKAGE_NAME) \
7373
-w /go/src/$(PACKAGE_NAME) \
74-
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
74+
ghcr.io/ecadlabs/goreleaser-cross-zig:${GOLANG_CROSS_VERSION} \
7575
release \
7676
--clean \
7777
--skip=validate

0 commit comments

Comments
 (0)