name: SONA NAPI Build & Publish on: push: # `paths` is ignored for tag pushes, so without `branches` this workflow # only ran on sona-v* tags and never built on main. Main pushes build and # gate only; publishing still requires a sona-v* tag or workflow_dispatch. branches: [main] tags: - 'sona-v*' paths: - 'crates/sona/**' - 'npm/packages/sona/**' - '.github/workflows/sona-napi.yml' pull_request: paths: - '.github/workflows/sona-napi.yml' - 'crates/sona/**' - 'npm/packages/sona/**' workflow_dispatch: inputs: publish: description: 'Publish to npm' type: boolean default: false env: CARGO_TERM_COLOR: always jobs: build: strategy: fail-fast: false matrix: include: # Linux x64 GNU - os: ubuntu-latest target: x86_64-unknown-linux-gnu node-file: sona.linux-x64-gnu.node # Linux x64 MUSL - os: ubuntu-latest target: x86_64-unknown-linux-musl node-file: sona.linux-x64-musl.node # Linux ARM64 — 22.04 so the gcc cross-link needs glibc 2.35, not 24.04's 2.39 - os: ubuntu-24.04 container: ubuntu:22.04 target: aarch64-unknown-linux-gnu node-file: sona.linux-arm64-gnu.node # macOS x64 — cross-compiled on Apple Silicon (macos-13 Intel runners are retired; # jobs requesting that label queue forever) - os: macos-15 target: x86_64-apple-darwin node-file: sona.darwin-x64.node # macOS ARM64 - os: macos-15 target: aarch64-apple-darwin node-file: sona.darwin-arm64.node # Windows x64 - os: windows-latest target: x86_64-pc-windows-msvc node-file: sona.win32-x64-msvc.node # Windows ARM64 - os: windows-latest target: aarch64-pc-windows-msvc node-file: sona.win32-arm64-msvc.node runs-on: ${{ matrix.os }} container: ${{ matrix.container }} name: Build ${{ matrix.target }} steps: - name: Bootstrap ubuntu:22.04 build container (keeps the glibc floor) if: ${{ matrix.container != '' }} shell: bash run: | apt-get update DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ sudo git curl wget ca-certificates build-essential pkg-config xz-utils unzip zip python3 jq file \ libssl-dev cmake clang libclang-dev git config --global --add safe.directory '*' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: '20' registry-url: 'https://registry.npmjs.org' - name: Setup Rust uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 with: targets: ${{ matrix.target }} - name: Install musl tools (Linux MUSL) if: matrix.target == 'x86_64-unknown-linux-musl' run: | sudo apt-get update sudo apt-get install -y musl-tools - name: Install cross-compilation tools (Linux ARM64) if: matrix.target == 'aarch64-unknown-linux-gnu' run: | sudo apt-get update sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu - name: Install napi-rs CLI run: npm install -g @napi-rs/cli@3.7.3 # Plain gcc cross-linker, same as build-diskann.yml. `--use-napi-cross` # now fails in CI ("Failed to set up the --use-napi-cross toolchain ... # Cannot find native binding") with both @napi-rs/cli 3.10.x and 3.7.3. - name: Build native module (cross-compile) if: matrix.target == 'aarch64-unknown-linux-gnu' working-directory: npm/packages/sona env: CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc run: | npx napi build --platform --release -p ruvector-sona --manifest-path ../../../crates/sona/Cargo.toml --output-dir . -F napi --target ${{ matrix.target }} - name: Build native module (macOS) if: startsWith(matrix.target, 'x86_64-apple-darwin') || startsWith(matrix.target, 'aarch64-apple-darwin') working-directory: npm/packages/sona env: CARGO_BUILD_TARGET: ${{ matrix.target }} RUSTFLAGS: '-C link-arg=-undefined -C link-arg=dynamic_lookup' run: | npx napi build --platform --release -p ruvector-sona --manifest-path ../../../crates/sona/Cargo.toml --output-dir . -F napi --target ${{ matrix.target }} - name: Build native module (other) if: "!startsWith(matrix.target, 'x86_64-apple-darwin') && !startsWith(matrix.target, 'aarch64-apple-darwin') && matrix.target != 'aarch64-unknown-linux-gnu'" working-directory: npm/packages/sona env: CARGO_BUILD_TARGET: ${{ matrix.target }} run: | npx napi build --platform --release -p ruvector-sona --manifest-path ../../../crates/sona/Cargo.toml --output-dir . -F napi --target ${{ matrix.target }} - name: List built files working-directory: npm/packages/sona shell: bash run: ls -la *.node || echo "No .node files" - name: Gate linux-arm64 binary (no LDAPR, GLIBC <= 2.34) if: matrix.target == 'aarch64-unknown-linux-gnu' shell: bash run: bash scripts/ci/check-arm64-node-binary.sh npm/packages/sona/${{ matrix.node-file }} - name: Upload artifact uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with: name: bindings-${{ matrix.target }} path: npm/packages/sona/${{ matrix.node-file }} if-no-files-found: error # Build universal macOS binary universal-macos: runs-on: macos-15 name: Universal macOS needs: build steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Download x64 artifact uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with: name: bindings-x86_64-apple-darwin path: artifacts/x64 - name: Download ARM64 artifact uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with: name: bindings-aarch64-apple-darwin path: artifacts/arm64 - name: Create universal binary run: | mkdir -p artifacts/universal lipo -create \ artifacts/x64/sona.darwin-x64.node \ artifacts/arm64/sona.darwin-arm64.node \ -output artifacts/universal/sona.darwin-universal.node - name: Upload universal artifact uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 with: name: bindings-darwin-universal path: artifacts/universal/sona.darwin-universal.node # Publish to npm publish: runs-on: ubuntu-latest name: Publish npm packages needs: [build, universal-macos] if: startsWith(github.ref, 'refs/tags/sona-v') || github.event.inputs.publish == 'true' steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: '20' registry-url: 'https://registry.npmjs.org' - name: Install napi-rs CLI run: npm install -g @napi-rs/cli@3.7.3 # pinned: 3.10.x breaks --use-napi-cross (aarch64 "Cannot find native binding"); 3.7.3 was the last green run, 2026-07-17 - name: Download all artifacts uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 with: path: artifacts - name: List artifacts run: | echo "=== All downloaded artifacts ===" find artifacts -name "*.node" -ls - name: Copy .node files to npm package working-directory: npm/packages/sona run: | # Copy all .node files from artifacts to the package directory cp ../../../artifacts/bindings-x86_64-unknown-linux-gnu/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-x86_64-unknown-linux-musl/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-aarch64-unknown-linux-gnu/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-x86_64-apple-darwin/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-aarch64-apple-darwin/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-x86_64-pc-windows-msvc/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-aarch64-pc-windows-msvc/*.node . 2>/dev/null || true cp ../../../artifacts/bindings-darwin-universal/*.node . 2>/dev/null || true # index.js / index.d.ts are committed (CI napi CLI version drift # produced no loader at all — see #516). Hard-fail if absent: # npm publish silently skips missing `files` entries, which is # exactly how the broken 0.1.6 tarball shipped. test -f index.js -a -f index.d.ts || { echo "ERROR: index.js/index.d.ts missing"; exit 1; } echo "=== .node files in package ===" ls -la *.node - name: Create and publish platform packages working-directory: npm/packages/sona env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | set -euo pipefail VERSION=$(node -p "require('./package.json').version") echo "Publishing version: $VERSION" mkdir -p npm publish_platform() { local name=$1 local node_file=$2 local os_val=$3 local cpu_val=$4 local libc_val=$5 if [ -f "$node_file" ]; then local dir_name=$(echo "$name" | sed 's/@ruvector\/sona-//') mkdir -p "npm/$dir_name" cp "$node_file" "npm/$dir_name/" if [ -n "$libc_val" ]; then node -e "require('fs').writeFileSync('npm/$dir_name/package.json', JSON.stringify({name:'$name',version:'$VERSION',os:['$os_val'],cpu:['$cpu_val'],libc:['$libc_val'],main:'$node_file',files:['$node_file'],homepage:'https://ruv.io',license:'MIT OR Apache-2.0',repository:{type:'git',url:'git+https://github.com/ruvnet/RuVector.git',directory:'npm/packages/sona/npm/$dir_name'},bugs:{url:'https://github.com/ruvnet/RuVector/issues'}},null,2))" else node -e "require('fs').writeFileSync('npm/$dir_name/package.json', JSON.stringify({name:'$name',version:'$VERSION',os:['$os_val'],cpu:['$cpu_val'],main:'$node_file',files:['$node_file'],homepage:'https://ruv.io',license:'MIT OR Apache-2.0',repository:{type:'git',url:'git+https://github.com/ruvnet/RuVector.git',directory:'npm/packages/sona/npm/$dir_name'},bugs:{url:'https://github.com/ruvnet/RuVector/issues'}},null,2))" fi echo "Publishing $name..." cd "npm/$dir_name" bash "$GITHUB_WORKSPACE/scripts/ci/npm-publish-if-missing.sh" --access public cd ../.. else echo "ERROR: expected platform binary $node_file is missing"; exit 1 fi } publish_platform "@ruvector/sona-linux-x64-gnu" "sona.linux-x64-gnu.node" "linux" "x64" "" publish_platform "@ruvector/sona-linux-x64-musl" "sona.linux-x64-musl.node" "linux" "x64" "musl" publish_platform "@ruvector/sona-linux-arm64-gnu" "sona.linux-arm64-gnu.node" "linux" "arm64" "" publish_platform "@ruvector/sona-darwin-x64" "sona.darwin-x64.node" "darwin" "x64" "" publish_platform "@ruvector/sona-darwin-arm64" "sona.darwin-arm64.node" "darwin" "arm64" "" publish_platform "@ruvector/sona-win32-x64-msvc" "sona.win32-x64-msvc.node" "win32" "x64" "" publish_platform "@ruvector/sona-win32-arm64-msvc" "sona.win32-arm64-msvc.node" "win32" "arm64" "" echo "=== Platform packages published ===" - name: Update main package with optionalDependencies working-directory: npm/packages/sona run: | VERSION=$(node -p "require('./package.json').version") # Add optionalDependencies to package.json node -e " const pkg = require('./package.json'); pkg.optionalDependencies = { '@ruvector/sona-linux-x64-gnu': '$VERSION', '@ruvector/sona-linux-x64-musl': '$VERSION', '@ruvector/sona-linux-arm64-gnu': '$VERSION', '@ruvector/sona-darwin-x64': '$VERSION', '@ruvector/sona-darwin-arm64': '$VERSION', '@ruvector/sona-win32-x64-msvc': '$VERSION', '@ruvector/sona-win32-arm64-msvc': '$VERSION' }; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n'); " echo "=== Updated package.json ===" cat package.json - name: Publish main package working-directory: npm/packages/sona env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} run: | set -euo pipefail # Rename bundled binaries to the index..node names the # committed loader (index.js) checks for. Must happen AFTER the # platform packages are created from the sona..node names. for f in sona.*.node; do if [ -e "$f" ]; then mv "$f" "index.${f#sona.}"; fi done echo "=== Main package contents ===" ls -la # Publish main package bash "$GITHUB_WORKSPACE/scripts/ci/npm-publish-if-missing.sh" --access public # Test installation on all platforms test-install: runs-on: ${{ matrix.os }} name: Test ${{ matrix.os }} needs: publish if: startsWith(github.ref, 'refs/tags/sona-v') strategy: matrix: os: [ubuntu-latest, macos-15, windows-latest] steps: - name: Setup Node.js uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 with: node-version: '20' - name: Wait for npm propagation run: sleep 30 - name: Test npm install run: | npm init -y npm install @ruvector/sona@latest node -e "const sona = require('@ruvector/sona'); console.log('SONA loaded successfully!'); console.log('SonaEngine:', typeof sona.SonaEngine);"