@@ -22,30 +22,76 @@ jobs:
2222 - name : linux-x64
2323 runs-on : ubuntu-24.04
2424 platform : linux
25+ asset-platform : linux
2526 asset-arch : x86_64
2627 build-arch : " "
2728 static-swift-stdlib : true
29+ swift-sdk : " "
30+ swift-sdk-triple : " "
31+ swift-sdk-arch : " "
32+ file-arch-pattern : x86-64
2833 - name : linux-arm64
2934 runs-on : ubuntu-24.04-arm
3035 platform : linux
36+ asset-platform : linux
3137 asset-arch : aarch64
3238 build-arch : " "
3339 static-swift-stdlib : true
40+ swift-sdk : " "
41+ swift-sdk-triple : " "
42+ swift-sdk-arch : " "
43+ file-arch-pattern : aarch64
44+ - name : linux-musl-x64
45+ runs-on : ubuntu-24.04
46+ platform : linux
47+ asset-platform : linux-musl
48+ asset-arch : x86_64
49+ build-arch : " "
50+ static-swift-stdlib : false
51+ swift-sdk : swift-6.2.1-RELEASE_static-linux-0.0.1
52+ swift-sdk-triple : x86_64-swift-linux-musl
53+ swift-sdk-arch : x86_64
54+ file-arch-pattern : x86-64
55+ - name : linux-musl-arm64
56+ runs-on : ubuntu-24.04-arm
57+ platform : linux
58+ asset-platform : linux-musl
59+ asset-arch : aarch64
60+ build-arch : " "
61+ static-swift-stdlib : false
62+ swift-sdk : swift-6.2.1-RELEASE_static-linux-0.0.1
63+ swift-sdk-triple : aarch64-swift-linux-musl
64+ swift-sdk-arch : aarch64
65+ file-arch-pattern : aarch64
3466 - name : macos-arm64
3567 runs-on : macos-15
3668 platform : macos
69+ asset-platform : macos
3770 asset-arch : arm64
3871 build-arch : arm64
3972 static-swift-stdlib : false
73+ swift-sdk : " "
74+ swift-sdk-triple : " "
75+ swift-sdk-arch : " "
76+ file-arch-pattern : " "
4077 - name : macos-x86_64
4178 runs-on : macos-15-intel
4279 platform : macos
80+ asset-platform : macos
4381 asset-arch : x86_64
4482 build-arch : x86_64
4583 static-swift-stdlib : false
84+ swift-sdk : " "
85+ swift-sdk-triple : " "
86+ swift-sdk-arch : " "
87+ file-arch-pattern : " "
4688 runs-on : ${{ matrix.runs-on }}
4789 env :
4890 RELEASE_TAG : ${{ inputs.tag || github.ref_name }}
91+ SWIFT_STATIC_LINUX_SDK_URL : https://download.swift.org/swift-6.2.1-release/static-sdk/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz
92+ SWIFT_STATIC_LINUX_SDK_CHECKSUM : 08e1939a504e499ec871b36826569173103e4562769e12b9b8c2a50f098374ad
93+ SQLITE_AMALGAMATION_VERSION : " 3530200"
94+ SQLITE_AMALGAMATION_SHA3_256 : 81142986038e18f96c4a54e1a72562ae17e502a916f2a7701eff43388cbf1a40
4995 steps :
5096 - uses : actions/checkout@v6
5197
@@ -118,14 +164,112 @@ jobs:
118164 hash -r
119165 swift --version
120166
167+ - name : Install Swift Static Linux SDK
168+ if : matrix.swift-sdk != ''
169+ shell : bash
170+ run : |
171+ set -euo pipefail
172+ swift sdk install "$SWIFT_STATIC_LINUX_SDK_URL" --checksum "$SWIFT_STATIC_LINUX_SDK_CHECKSUM"
173+ swift sdk list | grep -Fx "${{ matrix.swift-sdk }}"
174+
175+ sdk_root="$(
176+ find "$HOME" -type d -path "*/${{ matrix.swift-sdk }}.artifactbundle/${{ matrix.swift-sdk }}/swift-linux-musl" | head -n1
177+ )"
178+ if [[ -z "$sdk_root" ]]; then
179+ echo "Swift SDK root not found." >&2
180+ exit 1
181+ fi
182+
183+ python3 - "$sdk_root/swift-sdk.json" "${{ matrix.swift-sdk-triple }}" <<'PY'
184+ import json
185+ import sys
186+
187+ sdk_json_path, target_triple = sys.argv[1], sys.argv[2]
188+ with open(sdk_json_path, encoding="utf-8") as handle:
189+ sdk_json = json.load(handle)
190+
191+ target_triples = sdk_json.get("targetTriples", {})
192+ if target_triple not in target_triples:
193+ raise SystemExit(f"Swift SDK target triple not found: {target_triple}")
194+
195+ sdk_json["targetTriples"] = {target_triple: target_triples[target_triple]}
196+ with open(sdk_json_path, "w", encoding="utf-8") as handle:
197+ json.dump(sdk_json, handle, indent=2)
198+ handle.write("\n")
199+ PY
200+
201+ for sdk_arch in "$sdk_root"/musl-1.2.5.sdk/*; do
202+ if [[ "$(basename "$sdk_arch")" != "${{ matrix.swift-sdk-arch }}" ]]; then
203+ rm -rf "$sdk_arch"
204+ fi
205+ done
206+
207+ - name : Build static SQLite for musl SDK
208+ if : matrix.swift-sdk != ''
209+ shell : bash
210+ run : |
211+ set -euo pipefail
212+
213+ missing_packages=()
214+ for tool in clang openssl unzip; do
215+ if ! command -v "$tool" >/dev/null 2>&1; then
216+ missing_packages+=("$tool")
217+ fi
218+ done
219+ if [[ "${#missing_packages[@]}" -gt 0 ]]; then
220+ sudo apt-get update
221+ sudo apt-get install -y "${missing_packages[@]}"
222+ fi
223+
224+ sqlite_zip="$RUNNER_TEMP/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}.zip"
225+ sqlite_src="$RUNNER_TEMP/sqlite-src"
226+ sqlite_out="$RUNNER_TEMP/sqlite-${{ matrix.swift-sdk-triple }}"
227+
228+ curl -fsSL "https://www.sqlite.org/2026/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}.zip" -o "$sqlite_zip"
229+ actual_sha3="$(openssl dgst -sha3-256 "$sqlite_zip" | awk '{print $NF}')"
230+ if [[ "$actual_sha3" != "$SQLITE_AMALGAMATION_SHA3_256" ]]; then
231+ echo "SQLite amalgamation checksum mismatch: $actual_sha3" >&2
232+ exit 1
233+ fi
234+
235+ rm -rf "$sqlite_src" "$sqlite_out"
236+ mkdir -p "$sqlite_src" "$sqlite_out/build" "$sqlite_out/lib"
237+ unzip -q "$sqlite_zip" -d "$sqlite_src"
238+
239+ sdk_bundle="$(
240+ find "$HOME" -type d -name "${{ matrix.swift-sdk }}.artifactbundle" | head -n1
241+ )"
242+ if [[ -z "$sdk_bundle" ]]; then
243+ echo "Swift SDK artifact bundle not found." >&2
244+ exit 1
245+ fi
246+ sysroot="$sdk_bundle/${{ matrix.swift-sdk }}/swift-linux-musl/musl-1.2.5.sdk/${{ matrix.swift-sdk-arch }}"
247+ if [[ ! -d "$sysroot" ]]; then
248+ echo "Swift SDK sysroot not found: $sysroot" >&2
249+ exit 1
250+ fi
251+
252+ clang \
253+ -target "${{ matrix.swift-sdk-triple }}" \
254+ --sysroot="$sysroot" \
255+ -O2 \
256+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
257+ -c "$sqlite_src/sqlite-amalgamation-${SQLITE_AMALGAMATION_VERSION}/sqlite3.c" \
258+ -o "$sqlite_out/build/sqlite3.o"
259+ llvm-ar crs "$sqlite_out/lib/libsqlite3.a" "$sqlite_out/build/sqlite3.o"
260+
261+ echo "CODEXBAR_SQLITE3_LIB_DIR=$sqlite_out/lib" >> "$GITHUB_ENV"
262+
121263 - name : Build CodexBarCLI (release)
122264 id : build
123265 shell : bash
124266 run : |
125267 set -euo pipefail
126268
127269 BUILD_ARGS=(swift build -c release --product CodexBarCLI)
128- if [[ -n "${{ matrix.build-arch }}" ]]; then
270+ if [[ -n "${{ matrix.swift-sdk }}" ]]; then
271+ BUILD_ARGS+=(--swift-sdk "${{ matrix.swift-sdk }}" --triple "${{ matrix.swift-sdk-triple }}")
272+ elif [[ -n "${{ matrix.build-arch }}" ]]; then
129273 BUILD_ARGS+=(--arch "${{ matrix.build-arch }}")
130274 fi
131275 if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
@@ -134,7 +278,9 @@ jobs:
134278 "${BUILD_ARGS[@]}"
135279
136280 SHOW_BIN_ARGS=(swift build -c release --product CodexBarCLI --show-bin-path)
137- if [[ -n "${{ matrix.build-arch }}" ]]; then
281+ if [[ -n "${{ matrix.swift-sdk }}" ]]; then
282+ SHOW_BIN_ARGS+=(--swift-sdk "${{ matrix.swift-sdk }}" --triple "${{ matrix.swift-sdk-triple }}")
283+ elif [[ -n "${{ matrix.build-arch }}" ]]; then
138284 SHOW_BIN_ARGS+=(--arch "${{ matrix.build-arch }}")
139285 fi
140286 if [[ "${{ matrix.static-swift-stdlib }}" == "true" ]]; then
@@ -184,9 +330,14 @@ jobs:
184330 if [[ "${{ matrix.platform }}" == "macos" ]]; then
185331 lipo -archs "$BIN" | tr ' ' '\n' | grep -Fx "${{ matrix.asset-arch }}"
186332 run_with_timeout "$RUNNER_TEMP/codexbar-cli-smoke-${{ matrix.name }}.txt" "$BIN" config validate --format json
333+ elif [[ -n "${{ matrix.swift-sdk }}" ]]; then
334+ run_with_timeout "$RUNNER_TEMP/codexbar-cli-help-${{ matrix.name }}.txt" "$BIN" --help
335+ run_with_timeout "$RUNNER_TEMP/codexbar-cli-config-${{ matrix.name }}.json" "$BIN" config validate --format json
336+ file "$BIN" | grep -q "${{ matrix.file-arch-pattern }}"
337+ file "$BIN" | grep -q "statically linked"
187338 else
188339 run_with_timeout "$RUNNER_TEMP/codexbar-cli-help-${{ matrix.name }}.txt" "$BIN" --help
189- file "$BIN" | grep -q "${{ matrix.asset -arch }}"
340+ file "$BIN" | grep -q "${{ matrix.file -arch-pattern }}"
190341 fi
191342 printf '%s\n' "${RELEASE_TAG#v}" > "$BIN_DIR/VERSION"
192343 VERSION_OUTPUT="$RUNNER_TEMP/codexbar-cli-version-${{ matrix.name }}.txt"
@@ -213,7 +364,7 @@ jobs:
213364 ln -s "CodexBarCLI" "$OUT_DIR/codexbar"
214365 printf '%s\n' "${SAFE_REF_NAME#v}" > "$OUT_DIR/VERSION"
215366
216- ASSET="CodexBarCLI-${SAFE_REF_NAME}-${{ matrix.platform }}-${{ matrix.asset-arch }}.tar.gz"
367+ ASSET="CodexBarCLI-${SAFE_REF_NAME}-${{ matrix.asset- platform }}-${{ matrix.asset-arch }}.tar.gz"
217368 (cd "$OUT_DIR" && tar czf "$ASSET" CodexBarCLI codexbar VERSION)
218369 if command -v sha256sum >/dev/null 2>&1; then
219370 sha256sum "$OUT_DIR/$ASSET" > "$OUT_DIR/$ASSET.sha256"
0 commit comments