Skip to content

Commit 9531f1a

Browse files
committed
Issue #50: ARM64 static compilation fails with linking errors
1 parent e3e3e90 commit 9531f1a

File tree

8 files changed

+175
-89
lines changed

8 files changed

+175
-89
lines changed

.github/workflows/main.yml

Lines changed: 141 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
- "v*"
77

88
env:
9-
GO_VERSION: "1.23.4"
10-
REGISTRY_IMAGE: "ghcr.io/proofrock/ws4sql"
9+
GO_VERSION: "1.23.5"
10+
REGISTRY_IMAGE: "ghcr.io/proofrock/ws4sql_test"
1111

1212
jobs:
1313
test:
@@ -31,22 +31,24 @@ jobs:
3131
- name: Checkout
3232
uses: actions/checkout@v4
3333

34-
- uses: actions/setup-go@v5
35-
with:
36-
go-version: ${{ env.GO_VERSION }}
37-
3834
- name: Modify version number
3935
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
4036
working-directory: src/
4137

4238
- name: Build dir generation
4339
run: mkdir bin/
4440

41+
- name: Setup Alpine chroot
42+
uses: jirutka/setup-alpine@v1
43+
with:
44+
branch: edge
45+
4546
- name: Compile and Pack Artifact
4647
run: |
47-
make build-static
48+
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd
49+
make build-static-linux-musl-amd64
4850
tar czf bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz -C bin/ ws4sql
49-
rm bin/ws4sql
51+
shell: alpine.sh --root {0}
5052

5153
- name: Upload artifacts
5254
uses: actions/upload-artifact@v4
@@ -55,7 +57,39 @@ jobs:
5557
path: bin/ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz
5658
retention-days: 1
5759

58-
# TODO build_linux_arm64
60+
build_linux_arm64:
61+
runs-on: ubuntu-latest
62+
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
67+
- name: Modify version number
68+
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
69+
working-directory: src/
70+
71+
- name: Build dir generation
72+
run: mkdir bin/
73+
74+
- name: Setup Alpine chroot
75+
uses: jirutka/setup-alpine@v1
76+
with:
77+
arch: aarch64
78+
branch: edge
79+
80+
- name: Compile and Pack Artifact
81+
run: |
82+
apk add --no-cache musl-dev go g++ git make openssl openssl-dev openssl-libs-static zstd
83+
make build-static-linux-musl-arm64
84+
tar czf bin/ws4sql-${{ github.ref_name }}-linux-arm64.tar.gz -C bin/ ws4sql
85+
shell: alpine.sh --root {0}
86+
87+
- name: Upload artifacts
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: binary_linux_arm64
91+
path: bin/ws4sql-${{ github.ref_name }}-linux-arm64.tar.gz
92+
retention-days: 1
5993

6094
build_macos_arm64:
6195
runs-on: macos-latest
@@ -122,28 +156,111 @@ jobs:
122156
path: bin/ws4sql-${{ github.ref_name }}-win-amd64.zip
123157
retention-days: 1
124158

159+
build_docker:
160+
needs:
161+
- build_linux_amd64
162+
- build_linux_arm64
163+
runs-on: ubuntu-latest
164+
strategy:
165+
fail-fast: false
166+
matrix:
167+
platform:
168+
- linux/amd64
169+
- linux/arm64
170+
steps:
171+
- name: Prepare
172+
run: |
173+
platform=${{ matrix.platform }}
174+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
175+
echo "PLATFORM_PAIR_UNDERSCORE=${platform//\//_}" >> $GITHUB_ENV
176+
177+
- name: Checkout
178+
uses: actions/checkout@v4
179+
180+
- name: Download artifact
181+
uses: actions/download-artifact@v4
182+
with:
183+
name: binary_${{ env.PLATFORM_PAIR_UNDERSCORE }}
184+
path: bin/
185+
186+
- name: Unpack artifact
187+
run: |
188+
tar xzf *.tar.gz
189+
chmod +x ws4sql # Probably unnecessary
190+
working-directory: bin/
191+
192+
- name: Docker meta
193+
id: meta
194+
uses: docker/metadata-action@v5
195+
with:
196+
images: ${{ env.REGISTRY_IMAGE }}
197+
198+
# - name: Set up QEMU
199+
# uses: docker/setup-qemu-action@v3
200+
201+
- name: Set up Docker Buildx
202+
uses: docker/setup-buildx-action@v3
203+
204+
- name: Login to Github Container Registry
205+
uses: docker/login-action@v3
206+
with:
207+
registry: ghcr.io
208+
username: ${{ github.actor }}
209+
password: ${{ secrets.TOKEN }}
210+
211+
- name: Build and push by digest
212+
id: build
213+
uses: docker/build-push-action@v5
214+
with:
215+
context: .
216+
platforms: ${{ matrix.platform }}
217+
labels: ${{ steps.meta.outputs.labels }}
218+
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
219+
220+
- name: Export digest
221+
run: |
222+
mkdir -p /tmp/digests
223+
digest="${{ steps.build.outputs.digest }}"
224+
touch "/tmp/digests/${digest#sha256:}"
225+
226+
- name: Upload digest
227+
uses: actions/upload-artifact@v4
228+
with:
229+
name: digests-${{ env.PLATFORM_PAIR }}
230+
path: /tmp/digests/*
231+
if-no-files-found: error
232+
retention-days: 1
233+
125234
release:
126235
needs:
127236
- build_linux_amd64
237+
- build_linux_arm64
128238
- build_macos_arm64
129239
- build_win_amd64
240+
- build_docker
130241
- test
131242
runs-on: ubuntu-latest
132243

133244
steps:
134-
- name: Download artifacts [1/3]
245+
- name: Download artifacts [1/4]
135246
uses: actions/download-artifact@v4
136247
with:
137248
name: binary_linux_amd64
138249
path: bin/
139250

140-
- name: Download artifacts [2/3]
251+
- name: Download artifacts [2/4]
252+
uses: actions/download-artifact@v4
253+
with:
254+
name: binary_linux_arm64
255+
path: bin/
256+
257+
- name: Download artifacts [3/4]
141258
uses: actions/download-artifact@v4
142259
with:
143260
name: binary_macos_arm64
144261
path: bin/
145262

146-
- name: Download artifacts [3/3]
263+
- name: Download artifacts [4/4]
147264
uses: actions/download-artifact@v4
148265
with:
149266
name: binary_win_amd64
@@ -174,6 +291,16 @@ jobs:
174291
asset_name: ws4sql-${{ github.ref_name }}-linux-amd64.tar.gz
175292
asset_content_type: application/gzip
176293

294+
- name: Release Artifact [linux/arm64]
295+
uses: actions/upload-release-asset@v1
296+
env:
297+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
298+
with:
299+
upload_url: ${{ steps.create_release.outputs.upload_url }}
300+
asset_path: bin/ws4sql-${{ github.ref_name }}-linux-arm64.tar.gz
301+
asset_name: ws4sql-${{ github.ref_name }}-linux-arm64.tar.gz
302+
asset_content_type: application/gzip
303+
177304
- name: Release Artifact [darwin/arm64]
178305
uses: actions/upload-release-asset@v1
179306
env:
@@ -194,73 +321,10 @@ jobs:
194321
asset_name: ws4sql-${{ github.ref_name }}-win-amd64.zip
195322
asset_content_type: application/zip
196323

197-
build-docker:
198-
runs-on: ubuntu-latest
199-
strategy:
200-
fail-fast: false
201-
matrix:
202-
platform:
203-
- linux/amd64
204-
- linux/arm64
205-
steps:
206-
- name: Prepare
207-
run: |
208-
platform=${{ matrix.platform }}
209-
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
210-
211-
- name: Checkout
212-
uses: actions/checkout@v4
213-
214-
- name: Modify version number
215-
run: sed -i 's/v0\.0\.0/${{ github.ref_name }}/g' ws4sql.go
216-
working-directory: src/
217-
218-
- name: Docker meta
219-
id: meta
220-
uses: docker/metadata-action@v5
221-
with:
222-
images: ${{ env.REGISTRY_IMAGE }}
223-
224-
# - name: Set up QEMU
225-
# uses: docker/setup-qemu-action@v3
226-
227-
- name: Set up Docker Buildx
228-
uses: docker/setup-buildx-action@v3
229-
230-
- name: Login to Github Container Registry
231-
uses: docker/login-action@v3
232-
with:
233-
registry: ghcr.io
234-
username: ${{ github.actor }}
235-
password: ${{ secrets.TOKEN }}
236-
237-
- name: Build and push by digest
238-
id: build
239-
uses: docker/build-push-action@v5
240-
with:
241-
context: .
242-
platforms: ${{ matrix.platform }}
243-
labels: ${{ steps.meta.outputs.labels }}
244-
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
245-
246-
- name: Export digest
247-
run: |
248-
mkdir -p /tmp/digests
249-
digest="${{ steps.build.outputs.digest }}"
250-
touch "/tmp/digests/${digest#sha256:}"
251-
252-
- name: Upload digest
253-
uses: actions/upload-artifact@v4
254-
with:
255-
name: digests-${{ env.PLATFORM_PAIR }}
256-
path: /tmp/digests/*
257-
if-no-files-found: error
258-
retention-days: 1
259-
260-
merge-docker:
324+
merge_docker:
261325
runs-on: ubuntu-latest
262326
needs:
263-
- build-docker
327+
- build_docker
264328
- release
265329
- test
266330
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ bin/
55
/notes.md
66
test/*.db
77
test/*.db.wal
8+
libduckdb_bundle.a
89

910
# Created by https://www.toptal.com/developers/gitignore/api/go,macos,linux,windows
1011
# Edit at https://www.toptal.com/developers/gitignore?templates=go,macos,linux,windows

Dockerfile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
# See BUILDING.md
1+
FROM gcr.io/distroless/static-debian12
22

3-
FROM golang:latest AS build
4-
5-
WORKDIR /go/src/app
6-
COPY . .
7-
8-
RUN make build
9-
10-
# Now copy it into our base image.
11-
FROM debian:12-slim
12-
COPY --from=build /go/src/app/bin/ws4sql /
3+
COPY bin/ws4sql /
134

145
EXPOSE 12321
156
VOLUME /data

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ build-static:
2828
cd src; go build -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension" -ldflags='-w -extldflags "-static"'
2929
mv src/ws4sql bin/
3030

31+
build-static-linux-musl-amd64:
32+
# In an Alpine Linux context with the following packages
33+
# musl-dev go g++ make openssl openssl-dev openssl-libs-static zstd
34+
make build-prepare
35+
cp precompiled/libduckdb_bundle/linux-musl-amd64/libduckdb_bundle.a.zst src/
36+
cd src && zstd -d libduckdb_bundle.a.zst
37+
cd src && CGO_CFLAGS="-O2 -fPIC" CGO_CXXFLAGS="-O2 -fPIC" CGO_LDFLAGS="-lduckdb_bundle -lssl -lcrypto -L./" go build -buildvcs=false -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension duckdb_use_static_lib" -ldflags='-w -extldflags "-static"'
38+
mv src/ws4sql bin/
39+
40+
build-static-linux-musl-arm64:
41+
# In an Alpine Linux context with the following packages
42+
# musl-dev go g++ make openssl openssl-dev openssl-libs-static zstd
43+
make build-prepare
44+
cp precompiled/libduckdb_bundle/linux-musl-arm64/libduckdb_bundle.a.zst src/
45+
cd src && zstd -d libduckdb_bundle.a.zst
46+
cd src && CGO_CFLAGS="-O2 -fPIC" CGO_CXXFLAGS="-O2 -fPIC" CGO_LDFLAGS="-lduckdb_bundle -lssl -lcrypto -L./" go build -buildvcs=false -trimpath -a -tags="netgo osusergo sqlite_omit_load_extension duckdb_use_static_lib" -ldflags='-w -extldflags "-static"'
47+
mv src/ws4sql bin/
48+
3149
test:
3250
cd src; go test -v -timeout 6m
3351

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Linux
2+
3+
To compile this prerequisite, set up an Alpine Linux (edge), for example in docker - and use this broad "recipe":
4+
5+
```bash
6+
apk add --no-cache findutils musl-dev go g++ git make cmake ninja openssl openssl-dev openssl-libs-static python3 zstd
7+
git clone -b "v1.1.3" https://github.com/duckdb/duckdb
8+
cd duckdb
9+
CFLAGS="-O3 -fPIC" CXXFLAGS="-O3 -fPIC" BUILD_SHELL=0 BUILD_UNITTESTS=0 DUCKDB_PLATFORM=any ENABLE_EXTENSION_AUTOLOADING=1 ENABLE_EXTENSION_AUTOINSTALL=1 BUILD_EXTENSIONS="json;httpfs;parquet" make bundle-library -j4
10+
cp duckdb/build/release/libduckdb_bundle.a .
11+
zstd -T4 -19 duckdb/build/release/libduckdb_bundle.a
12+
```
Binary file not shown.
Binary file not shown.

src/ws4sql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
_ "github.com/mattn/go-sqlite3"
3939
)
4040

41-
const version = "ws4sql-v0.0.0"
41+
const version = "v0.0.0"
4242

4343
// Simply prints a header, parses the cli parameters and calls
4444
// launch(), that is the real entry point. It's separate from the

0 commit comments

Comments
 (0)