Build Native Libraries #22
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: Build Native Libraries | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| libsql_ref: | |
| description: 'libSQL ref to build (branch, tag, or commit)' | |
| required: true | |
| default: 'main' | |
| jobs: | |
| build-native: | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| output: linux-x64 | |
| ext: so | |
| - os: ubuntu-latest | |
| target: x86_64-pc-windows-gnu | |
| output: win-x64 | |
| ext: dll | |
| is_cross: true | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| output: osx-arm64 | |
| ext: dylib | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Checkout libSQL | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: tursodatabase/libsql | |
| ref: ${{ github.event.inputs.libsql_ref }} | |
| path: libsql | |
| - name: Install MinGW for cross-compilation | |
| if: matrix.is_cross == true | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y mingw-w64 | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Add Rust target and verify installation | |
| run: | | |
| echo "=== Current Rust installation ===" | |
| rustup show | |
| echo "" | |
| echo "=== Available targets ===" | |
| rustup target list | grep -E "(installed|${{ matrix.target }})" | |
| echo "" | |
| echo "=== Adding target ${{ matrix.target }} ===" | |
| rustup target add ${{ matrix.target }} | |
| echo "" | |
| echo "=== Verify target was added ===" | |
| rustup target list --installed | |
| echo "" | |
| echo "=== Rust toolchain info ===" | |
| rustc --version | |
| cargo --version | |
| echo "" | |
| echo "=== Check for MinGW (Windows cross-compilation) ===" | |
| which x86_64-w64-mingw32-gcc || echo "MinGW gcc not found" | |
| x86_64-w64-mingw32-gcc --version || echo "MinGW gcc version check failed" | |
| echo "" | |
| echo "=== Environment variables ===" | |
| env | grep -E "(RUST|CARGO|CC|AR|TARGET)" | sort | |
| - name: Build libSQL | |
| working-directory: libsql/bindings/c | |
| run: | | |
| echo "=== Building for target: ${{ matrix.target }} ===" | |
| echo "=== Current directory: $(pwd) ===" | |
| echo "=== Cargo configuration ===" | |
| cat ~/.cargo/config.toml 2>/dev/null || echo "No global cargo config" | |
| cat .cargo/config.toml 2>/dev/null || echo "No local cargo config" | |
| echo "" | |
| echo "=== Checking for rust-toolchain.toml ===" | |
| if [ -f "rust-toolchain.toml" ]; then | |
| echo "Found rust-toolchain.toml:" | |
| cat rust-toolchain.toml | |
| echo "" | |
| echo "Temporarily renaming to prevent version override..." | |
| mv rust-toolchain.toml rust-toolchain.toml.bak | |
| fi | |
| if [ -f "../../rust-toolchain.toml" ]; then | |
| echo "Found rust-toolchain.toml in parent:" | |
| cat ../../rust-toolchain.toml | |
| echo "" | |
| echo "Temporarily renaming to prevent version override..." | |
| mv ../../rust-toolchain.toml ../../rust-toolchain.toml.bak | |
| fi | |
| echo "" | |
| echo "=== Verifying Rust target is still installed ===" | |
| rustup target list --installed | |
| echo "" | |
| # Build with vendored SQLite to ensure all symbols are included | |
| LIBSQL_BUNDLED=1 cargo build --release --target ${{ matrix.target }} --verbose | |
| - name: Create shared library (Linux) | |
| if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-gnu' | |
| run: | | |
| cd libsql/target/${{ matrix.target }}/release | |
| ar -x libsql_experimental.a | |
| gcc -shared -o libsql.so *.o -lpthread -ldl -lm | |
| mkdir -p ${{ github.workspace }}/artifacts/${{ matrix.output }}/native | |
| cp libsql.so ${{ github.workspace }}/artifacts/${{ matrix.output }}/native/ | |
| - name: Create shared library (Windows) | |
| if: matrix.target == 'x86_64-pc-windows-gnu' | |
| run: | | |
| cd libsql/target/${{ matrix.target }}/release | |
| echo "=== Listing all static libraries ===" | |
| find . -name "*.a" -type f | head -20 | |
| echo "=== Extracting libsql_experimental.a ===" | |
| ar -x libsql_experimental.a | |
| # Extract SQLite-related libraries from deps | |
| echo "=== Looking for SQLite libraries in deps ===" | |
| for lib in deps/*.a; do | |
| echo "Checking $lib..." | |
| # Check if library contains sqlite symbols | |
| if nm "$lib" 2>/dev/null | grep -q "sqlite3_"; then | |
| echo "Found SQLite symbols in $lib, extracting..." | |
| ar -x "$lib" | |
| fi | |
| done | |
| echo "=== Creating DLL ===" | |
| x86_64-w64-mingw32-gcc -shared -o libsql.dll *.o \ | |
| -Wl,--export-all-symbols \ | |
| -lws2_32 -ladvapi32 -luserenv -lbcrypt -lntdll -lcrypt32 \ | |
| -lsecur32 -lkernel32 -lole32 -loleaut32 -luuid -lncrypt \ | |
| -static-libgcc | |
| # Verify DLL was created and check size | |
| echo "=== Verifying DLL ===" | |
| ls -lh libsql.dll | |
| file libsql.dll | |
| # Clean up object files | |
| rm *.o | |
| mkdir -p ${{ github.workspace }}/artifacts/${{ matrix.output }}/native | |
| cp libsql.dll ${{ github.workspace }}/artifacts/${{ matrix.output }}/native/ | |
| - name: Create shared library (macOS) | |
| if: matrix.os == 'macos-latest' | |
| run: | | |
| cd libsql/target/${{ matrix.target }}/release | |
| ar -x libsql_experimental.a | |
| # Build dynamic library | |
| clang -dynamiclib -o libsql.dylib *.o \ | |
| -framework Security -framework CoreFoundation \ | |
| -lSystem -lc -lm | |
| # Verify library was created | |
| echo "Library created:" | |
| ls -lh libsql.dylib | |
| file libsql.dylib | |
| mkdir -p ${{ github.workspace }}/artifacts/${{ matrix.output }}/native | |
| cp libsql.dylib ${{ github.workspace }}/artifacts/${{ matrix.output }}/native/ | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: libsql-${{ matrix.output }} | |
| path: artifacts/${{ matrix.output }}/native/libsql.${{ matrix.ext }} | |
| commit-libraries: | |
| needs: build-native | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Copy libraries to project | |
| run: | | |
| # Create directories | |
| mkdir -p src/Nelknet.LibSQL.Bindings/runtimes/linux-x64/native | |
| mkdir -p src/Nelknet.LibSQL.Bindings/runtimes/win-x64/native | |
| mkdir -p src/Nelknet.LibSQL.Bindings/runtimes/osx-arm64/native | |
| # Copy libraries | |
| cp artifacts/libsql-linux-x64/libsql.so src/Nelknet.LibSQL.Bindings/runtimes/linux-x64/native/ | |
| cp artifacts/libsql-win-x64/libsql.dll src/Nelknet.LibSQL.Bindings/runtimes/win-x64/native/ | |
| cp artifacts/libsql-osx-arm64/libsql.dylib src/Nelknet.LibSQL.Bindings/runtimes/osx-arm64/native/ | |
| # Create version file | |
| echo "Built from libSQL ref: ${{ github.event.inputs.libsql_ref }}" > src/Nelknet.LibSQL.Bindings/runtimes/LIBSQL_VERSION | |
| echo "Built on: $(date)" >> src/Nelknet.LibSQL.Bindings/runtimes/LIBSQL_VERSION | |
| # Show what we built | |
| ls -lh src/Nelknet.LibSQL.Bindings/runtimes/*/native/* | |
| - name: Commit and push | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add src/Nelknet.LibSQL.Bindings/runtimes/ | |
| git commit -m "chore: Update native libSQL libraries from ${{ github.event.inputs.libsql_ref }}" | |
| git push |