feat: statically link sqlite-vec into SQLite dylib #45
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| env: | |
| SQLITE_VEC_VERSION: "0.1.7-alpha.8" | |
| jobs: | |
| build-sqlite: | |
| runs-on: ${{ matrix.runs-on }} | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: arm64 | |
| runs-on: macos-15 | |
| - arch: x64 | |
| runs-on: macos-15-intel | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Get latest SQLite version | |
| id: sqlite-version | |
| run: | | |
| DOWNLOAD_PATH=$(curl -sL https://sqlite.org/download.html | grep -o '[0-9]*/sqlite-amalgamation-[0-9]*\.zip' | head -1) | |
| VERSION=$(echo "$DOWNLOAD_PATH" | grep -o 'sqlite-amalgamation-[0-9]*' | sed 's/sqlite-amalgamation-//') | |
| YEAR=$(echo "$DOWNLOAD_PATH" | cut -d'/' -f1) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "year=$YEAR" >> $GITHUB_OUTPUT | |
| - name: Check existing dylib | |
| id: check | |
| run: | | |
| DYLIB_PATH="native/darwin-${{ matrix.arch }}/libsqlite3.dylib" | |
| if [ ! -f "$DYLIB_PATH" ]; then | |
| echo "needs-update=true" >> $GITHUB_OUTPUT | |
| echo "Dylib not found, will build" | |
| else | |
| EXISTING_SIZE=$(stat -f%z "$DYLIB_PATH" 2>/dev/null || stat -c%s "$DYLIB_PATH" 2>/dev/null || echo "0") | |
| if [ "$EXISTING_SIZE" -lt 1400000 ]; then | |
| echo "needs-update=true" >> $GITHUB_OUTPUT | |
| echo "Dylib too small (likely missing sqlite-vec), will rebuild" | |
| else | |
| if strings "$DYLIB_PATH" | grep -q "vec_version"; then | |
| echo "needs-update=false" >> $GITHUB_OUTPUT | |
| echo "Dylib exists with sqlite-vec" | |
| else | |
| echo "needs-update=true" >> $GITHUB_OUTPUT | |
| echo "Dylib missing sqlite-vec, will rebuild" | |
| fi | |
| fi | |
| fi | |
| - name: Download SQLite and sqlite-vec | |
| if: steps.check.outputs.needs-update == 'true' | |
| run: | | |
| curl -LO "https://sqlite.org/${{ steps.sqlite-version.outputs.year }}/sqlite-amalgamation-${{ steps.sqlite-version.outputs.version }}.zip" | |
| unzip "sqlite-amalgamation-${{ steps.sqlite-version.outputs.version }}.zip" | |
| curl -LO "https://github.com/asg017/sqlite-vec/releases/download/v${{ env.SQLITE_VEC_VERSION }}/sqlite-vec-${{ env.SQLITE_VEC_VERSION }}-amalgamation.zip" | |
| unzip "sqlite-vec-${{ env.SQLITE_VEC_VERSION }}-amalgamation.zip" | |
| - name: Build combined dylib | |
| if: steps.check.outputs.needs-update == 'true' | |
| run: | | |
| SQLITE_DIR="sqlite-amalgamation-${{ steps.sqlite-version.outputs.version }}" | |
| gcc -c "$SQLITE_DIR/sqlite3.c" -o sqlite3.o \ | |
| -DSQLITE_ENABLE_FTS5 \ | |
| -DSQLITE_ENABLE_RTREE \ | |
| -DSQLITE_ENABLE_GEOPOLY | |
| gcc -c sqlite-vec.c -o sqlite-vec.o \ | |
| -I"$SQLITE_DIR" \ | |
| -DSQLITE_CORE \ | |
| -DSQLITE_VEC_STATIC | |
| cat > vec_init.c << 'INIT_EOF' | |
| #include "sqlite3.h" | |
| extern int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi); | |
| __attribute__((constructor)) | |
| static void vec_auto_register(void) { | |
| sqlite3_auto_extension((void(*)(void))sqlite3_vec_init); | |
| } | |
| INIT_EOF | |
| gcc -c vec_init.c -o vec_init.o -I"$SQLITE_DIR" | |
| gcc -dynamiclib \ | |
| -o libsqlite3.dylib \ | |
| sqlite3.o sqlite-vec.o vec_init.o \ | |
| -install_name @rpath/libsqlite3.dylib \ | |
| -lpthread -ldl -lm | |
| - name: Verify dylib | |
| if: steps.check.outputs.needs-update == 'true' | |
| run: | | |
| otool -D libsqlite3.dylib | |
| file libsqlite3.dylib | |
| ls -la libsqlite3.dylib | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: libsqlite3-darwin-${{ matrix.arch }} | |
| path: libsqlite3.dylib | |
| retention-days: 1 | |
| if-no-files-found: ignore | |
| commit-dylib: | |
| needs: build-sqlite | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| changed: ${{ steps.update.outputs.changed }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Update dylib files | |
| id: update | |
| run: | | |
| CHANGED="false" | |
| if [ -f "artifacts/libsqlite3-darwin-arm64/libsqlite3.dylib" ]; then | |
| mkdir -p native/darwin-arm64 | |
| cp artifacts/libsqlite3-darwin-arm64/libsqlite3.dylib native/darwin-arm64/ | |
| CHANGED="true" | |
| echo "Updated arm64 dylib" | |
| fi | |
| if [ -f "artifacts/libsqlite3-darwin-x64/libsqlite3.dylib" ]; then | |
| mkdir -p native/darwin-x64 | |
| cp artifacts/libsqlite3-darwin-x64/libsqlite3.dylib native/darwin-x64/ | |
| CHANGED="true" | |
| echo "Updated x64 dylib" | |
| fi | |
| echo "changed=$CHANGED" >> $GITHUB_OUTPUT | |
| - name: Commit and push | |
| if: steps.update.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add native/ | |
| git commit -m "chore: update SQLite+sqlite-vec dylib [skip ci]" | |
| git push origin main | |
| release: | |
| needs: [build-sqlite, commit-dylib] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Pull latest changes | |
| run: git pull origin main | |
| - uses: oven-sh/setup-bun@v2 | |
| - run: bun install | |
| - run: bun run typecheck | |
| - run: bun run build | |
| - name: Setup Node.js for npm publish | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Publish to npm | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Prepare release assets | |
| run: | | |
| mkdir -p release-assets | |
| cp native/darwin-arm64/libsqlite3.dylib release-assets/libsqlite3-darwin-arm64.dylib | |
| cp native/darwin-x64/libsqlite3.dylib release-assets/libsqlite3-darwin-x64.dylib | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| generate_release_notes: true | |
| files: | | |
| release-assets/libsqlite3-darwin-arm64.dylib | |
| release-assets/libsqlite3-darwin-x64.dylib |