From aac2ffa4b374e368a06ad82aa7fcedacfbf627ed Mon Sep 17 00:00:00 2001 From: Will Jones Date: Mon, 22 May 2023 14:26:06 -0700 Subject: [PATCH] Lint and test vectordb node in CI (#92) Closes #90. --- .github/workflows/node.yml | 101 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + node/native.js | 26 +++++++--- node/package.json | 2 +- 4 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/node.yml diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml new file mode 100644 index 00000000..b1a85421 --- /dev/null +++ b/.github/workflows/node.yml @@ -0,0 +1,101 @@ +name: Node + +on: + push: + branches: + - main + pull_request: + paths: + - node/** + - rust/ffi/node/** + - .github/workflows/node.yml + +env: + # Disable full debug symbol generation to speed up CI build and keep memory down + # "1" means line tables only, which is useful for panic tracebacks. + RUSTFLAGS: "-C debuginfo=1" + RUST_BACKTRACE: "1" + +jobs: + lint: + name: Lint + runs-on: ubuntu-22.04 + defaults: + run: + shell: bash + working-directory: node + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: node/package-lock.json + - name: Lint + run: | + npm ci + npm run lint + linux: + name: Linux (Node ${{ matrix.node-version }}) + timeout-minutes: 30 + strategy: + matrix: + node-version: [ "16", "18" ] + runs-on: "ubuntu-22.04" + defaults: + run: + shell: bash + working-directory: node + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + cache-dependency-path: node/package-lock.json + - uses: Swatinem/rust-cache@v2 + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y protobuf-compiler libssl-dev + - name: Build + run: | + npm ci + npm run build + npm run tsc + - name: Test + run: npm run test + macos: + timeout-minutes: 30 + runs-on: "macos-13" + defaults: + run: + shell: bash + working-directory: node + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + lfs: true + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + cache-dependency-path: node/package-lock.json + - uses: Swatinem/rust-cache@v2 + - name: Install dependencies + run: brew install protobuf + - name: Build + run: | + npm ci + npm run build + npm run tsc + - name: Test + run: | + npm run test diff --git a/Cargo.toml b/Cargo.toml index a9ca9918..b95029fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,3 +3,4 @@ members = [ "rust/vectordb", "rust/ffi/node" ] +resolver = "2" diff --git a/node/native.js b/node/native.js index 275f8873..0d4172a0 100644 --- a/node/native.js +++ b/node/native.js @@ -14,12 +14,26 @@ let nativeLib; -if (process.platform === "darwin" && process.arch === "arm64") { - nativeLib = require('./darwin_arm64.node') -} else if (process.platform === "linux" && process.arch === "x64") { - nativeLib = require('./linux-x64.node') -} else { - throw new Error(`vectordb: unsupported platform ${process.platform}_${process.arch}. Please file a bug report at https://github.com/lancedb/lancedb/issues`) +function getPlatformLibrary() { + if (process.platform === "darwin" && process.arch == "arm64") { + return require('./aarch64-apple-darwin.node'); + } else if (process.platform === "darwin" && process.arch == "x64") { + return require('./x86_64-apple-darwin.node'); + } else if (process.platform === "linux" && process.arch == "x64") { + return require('./x86_64-unknown-linux-gnu.node'); + } else { + throw new Error(`vectordb: unsupported platform ${process.platform}_${process.arch}. Please file a bug report at https://github.com/lancedb/lancedb/issues`) + } +} + +try { + nativeLib = require('./index.node') +} catch (e) { + if (e.code === "MODULE_NOT_FOUND") { + nativeLib = getPlatformLibrary(); + } else { + throw new Error('vectordb: failed to load native library. Please file a bug report at https://github.com/lancedb/lancedb/issues'); + } } module.exports = nativeLib diff --git a/node/package.json b/node/package.json index fc746055..2b41f498 100644 --- a/node/package.json +++ b/node/package.json @@ -6,7 +6,7 @@ "types": "dist/index.d.ts", "scripts": { "tsc": "tsc -b", - "build": "cargo-cp-artifact --artifact cdylib vectordb-node darwin_arm64.node -- cargo build --message-format=json-render-diagnostics", + "build": "cargo-cp-artifact --artifact cdylib vectordb-node index.node -- cargo build --message-format=json-render-diagnostics", "build-release": "npm run build -- --release", "test": "mocha -recursive dist/test", "lint": "eslint src --ext .js,.ts"