Skip to content

Commit eed230f

Browse files
sweenzorclaude
andcommitted
ci(release): statically embed libstdc++ and pin the linux build image
Hardening on top of kenn-io#393 (which fixed the Linux release break by moving to ubuntu:22.04, where the GCC 12 libstdc++ is available). Build with gcc-12 and embed libstdc++/libgcc statically so the released binary has no runtime libstdc++ (GLIBCXX) dependency; kenn-io#393 leaves it dynamically linked, requiring GLIBCXX_3.4.30. Also pin the build image by digest, and add a guard that fails the build if libstdc++ ever links dynamically. Verified in a matching ubuntu:22.04 arm64 container: links cleanly, runs, no dynamic libstdc++. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 345738c commit eed230f

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ jobs:
2222
go_arch_name: arm64
2323
runs-on: ${{ matrix.runner }}
2424
container:
25-
image: ubuntu:22.04
25+
# Digest-pinned. ubuntu:22.04 ships GCC 12, needed to link DuckDB 1.5.4's
26+
# static lib.
27+
image: ubuntu:22.04@sha256:4f838adc7181d9039ac795a7d0aba05a9bd9ecd480d294483169c5def983b64d
2628

2729
steps:
2830
- name: Install build tools
2931
env:
3032
DEBIAN_FRONTEND: noninteractive
3133
run: |
3234
apt-get update
33-
# libsqlite3-dev provides sqlite3.h, which sqlite-vec's CGo
34-
# binding includes unconditionally with -DSQLITE_CORE. mattn's
35-
# sqlite3 driver still links its own bundled amalgamation at
36-
# runtime; the header is only needed at compile time.
37-
apt-get install -y gcc g++ make git curl tar gzip file binutils libsqlite3-dev
35+
# gcc-12: lets us statically embed GCC 12's libstdc++ (see Build).
36+
# libsqlite3-dev: sqlite3.h for sqlite-vec's CGo binding.
37+
apt-get install -y gcc-12 g++-12 make git curl tar gzip file binutils libsqlite3-dev
3838
3939
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
4040

@@ -52,18 +52,33 @@ jobs:
5252
GOOS: linux
5353
GOARCH: ${{ matrix.goarch }}
5454
CGO_ENABLED: '1'
55+
CC: gcc-12
56+
CXX: g++-12
5557
run: |
5658
export PATH="/usr/local/go/bin:$HOME/go/bin:$PATH"
5759
VERSION=${GITHUB_REF#refs/tags/v}
5860
61+
# Embed libstdc++/libgcc statically (no runtime GLIBCXX dep). Only
62+
# libstdc++.a on the search path forces -lstdc++ to the static archive.
63+
STATICLIBS="$(mktemp -d)"
64+
cp "$(gcc-12 -print-file-name=libstdc++.a)" "$STATICLIBS/"
65+
export CGO_LDFLAGS="-L$STATICLIBS"
66+
5967
mkdir -p dist
60-
LDFLAGS="-s -w -X go.kenn.io/msgvault/cmd/msgvault/cmd.Version=v${VERSION} -X go.kenn.io/msgvault/cmd/msgvault/cmd.Commit=$(printf '%s' "$GITHUB_SHA" | cut -c1-8) -X go.kenn.io/msgvault/cmd/msgvault/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) -extldflags '-lstdc++ -lm'"
68+
LDFLAGS="-s -w -X go.kenn.io/msgvault/cmd/msgvault/cmd.Version=v${VERSION} -X go.kenn.io/msgvault/cmd/msgvault/cmd.Commit=$(printf '%s' "$GITHUB_SHA" | cut -c1-8) -X go.kenn.io/msgvault/cmd/msgvault/cmd.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) -extldflags '-static-libgcc -lm'"
6169
go build -tags "fts5 sqlite_vec" -trimpath -buildvcs=false -ldflags="$LDFLAGS" -o dist/msgvault ./cmd/msgvault
6270
6371
echo "--- Binary info ---"
6472
file dist/msgvault
6573
ldd dist/msgvault || true
6674
75+
# Fail if libstdc++ linked dynamically — it would reintroduce a
76+
# GLIBCXX runtime dependency.
77+
if ldd dist/msgvault | grep -q 'libstdc++'; then
78+
echo "FATAL: binary dynamically links libstdc++ — static link failed"
79+
exit 1
80+
fi
81+
6782
# Verify runtime version requirements are reasonable. DuckDB's
6883
# prebuilt static library still links against libstdc++ symbols.
6984
echo "--- Runtime requirements ---"

0 commit comments

Comments
 (0)