Skip to content

Commit aa2d2ad

Browse files
committed
Add C FFI Bindings
1 parent cfedd98 commit aa2d2ad

File tree

26 files changed

+2257
-8
lines changed

26 files changed

+2257
-8
lines changed

.github/workflows/ci.yml

Lines changed: 135 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ jobs:
3737
- name: WASM Rust unit tests
3838
run: cargo test -p polyglot-sql-wasm --lib -- --nocapture
3939

40+
- name: FFI Rust tests
41+
run: cargo test -p polyglot-sql-ffi -- --nocapture
42+
43+
- name: FFI release build
44+
run: cargo build -p polyglot-sql-ffi --profile ffi_release
45+
4046
- name: Generic identity tests
4147
run: cargo test --test sqlglot_identity test_sqlglot_identity_all -p polyglot-sql -- --nocapture
4248

@@ -232,9 +238,136 @@ jobs:
232238
env:
233239
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
234240

241+
ffi-build-artifacts:
242+
if: startsWith(github.ref, 'refs/tags/v')
243+
needs: rust-test
244+
name: Build FFI (${{ matrix.archive_name }})
245+
runs-on: ${{ matrix.os }}
246+
strategy:
247+
fail-fast: false
248+
matrix:
249+
include:
250+
- os: ubuntu-latest
251+
target: x86_64-unknown-linux-gnu
252+
archive_name: linux-x86_64
253+
archive_ext: tar.gz
254+
shared_lib: libpolyglot_sql_ffi.so
255+
static_lib: libpolyglot_sql_ffi.a
256+
use_cross: false
257+
- os: ubuntu-latest
258+
target: aarch64-unknown-linux-gnu
259+
archive_name: linux-aarch64
260+
archive_ext: tar.gz
261+
shared_lib: libpolyglot_sql_ffi.so
262+
static_lib: libpolyglot_sql_ffi.a
263+
use_cross: true
264+
- os: macos-13
265+
target: x86_64-apple-darwin
266+
archive_name: macos-x86_64
267+
archive_ext: tar.gz
268+
shared_lib: libpolyglot_sql_ffi.dylib
269+
static_lib: libpolyglot_sql_ffi.a
270+
use_cross: false
271+
- os: macos-14
272+
target: aarch64-apple-darwin
273+
archive_name: macos-aarch64
274+
archive_ext: tar.gz
275+
shared_lib: libpolyglot_sql_ffi.dylib
276+
static_lib: libpolyglot_sql_ffi.a
277+
use_cross: false
278+
- os: windows-latest
279+
target: x86_64-pc-windows-msvc
280+
archive_name: windows-x86_64
281+
archive_ext: zip
282+
shared_lib: polyglot_sql_ffi.dll
283+
static_lib: polyglot_sql_ffi.lib
284+
use_cross: false
285+
steps:
286+
- uses: actions/checkout@v4
287+
288+
- uses: dtolnay/rust-toolchain@stable
289+
with:
290+
targets: ${{ matrix.target }}
291+
292+
- uses: Swatinem/rust-cache@v2
293+
294+
- name: Install cross (linux aarch64)
295+
if: matrix.use_cross
296+
run: cargo install cross --git https://github.com/cross-rs/cross
297+
298+
- name: Build FFI artifacts with cross
299+
if: matrix.use_cross
300+
run: cross build -p polyglot-sql-ffi --profile ffi_release --target ${{ matrix.target }}
301+
302+
- name: Build FFI artifacts with cargo
303+
if: ${{ !matrix.use_cross }}
304+
run: cargo build -p polyglot-sql-ffi --profile ffi_release --target ${{ matrix.target }}
305+
306+
- name: Package archive (unix)
307+
if: runner.os != 'Windows'
308+
run: |
309+
dir="polyglot-sql-ffi-${{ matrix.archive_name }}"
310+
mkdir -p "$dir"
311+
cp crates/polyglot-sql-ffi/polyglot_sql.h "$dir/"
312+
cp "target/${{ matrix.target }}/ffi_release/${{ matrix.shared_lib }}" "$dir/"
313+
cp "target/${{ matrix.target }}/ffi_release/${{ matrix.static_lib }}" "$dir/"
314+
cp LICENSE "$dir/"
315+
tar -czf "${dir}.tar.gz" "$dir"
316+
317+
- name: Package archive (windows)
318+
if: runner.os == 'Windows'
319+
shell: pwsh
320+
run: |
321+
$dir = "polyglot-sql-ffi-${{ matrix.archive_name }}"
322+
New-Item -ItemType Directory -Path $dir -Force | Out-Null
323+
Copy-Item "crates/polyglot-sql-ffi/polyglot_sql.h" "$dir/"
324+
Copy-Item "target/${{ matrix.target }}/ffi_release/${{ matrix.shared_lib }}" "$dir/"
325+
Copy-Item "target/${{ matrix.target }}/ffi_release/${{ matrix.static_lib }}" "$dir/"
326+
Copy-Item "LICENSE" "$dir/"
327+
Compress-Archive -Path $dir -DestinationPath "$dir.zip" -Force
328+
329+
- name: Upload archive artifact
330+
uses: actions/upload-artifact@v4
331+
with:
332+
name: ffi-${{ matrix.archive_name }}
333+
path: polyglot-sql-ffi-${{ matrix.archive_name }}.${{ matrix.archive_ext }}
334+
335+
publish-ffi-assets:
336+
if: startsWith(github.ref, 'refs/tags/v')
337+
needs: [ffi-build-artifacts, publish-crate, publish-npm]
338+
runs-on: ubuntu-latest
339+
permissions:
340+
contents: write
341+
steps:
342+
- name: Download all FFI archives
343+
uses: actions/download-artifact@v4
344+
with:
345+
pattern: ffi-*
346+
path: dist
347+
merge-multiple: true
348+
349+
- name: Generate checksums
350+
run: |
351+
cd dist
352+
shopt -s nullglob
353+
files=(*.tar.gz *.zip)
354+
if [ ${#files[@]} -eq 0 ]; then
355+
echo "No FFI archives found"
356+
exit 1
357+
fi
358+
sha256sum "${files[@]}" > checksums.sha256
359+
360+
- name: Attach assets to GitHub release
361+
uses: softprops/action-gh-release@v2
362+
with:
363+
files: |
364+
dist/*.tar.gz
365+
dist/*.zip
366+
dist/checksums.sha256
367+
235368
deploy-docs:
236369
if: startsWith(github.ref, 'refs/tags/v')
237-
needs: [publish-crate, publish-npm]
370+
needs: [publish-crate, publish-npm, publish-ffi-assets]
238371
runs-on: ubuntu-latest
239372
steps:
240373
- uses: actions/checkout@v4
@@ -286,7 +419,7 @@ jobs:
286419

287420
deploy-playground:
288421
if: startsWith(github.ref, 'refs/tags/v')
289-
needs: [publish-crate, publish-npm]
422+
needs: [publish-crate, publish-npm, publish-ffi-assets]
290423
runs-on: ubuntu-latest
291424
steps:
292425
- uses: actions/checkout@v4

0 commit comments

Comments
 (0)