Skip to content

Commit d07f5f7

Browse files
itaismithphilipkiely-baseten
authored andcommitted
[ENH] Bundle CLI in JS client (chroma-core#4200)
## Description of changes The `rust/js_bindings` crate is a `napi` project exposing the CLI entry point in [`src/lib.rs`](https://github.com/chroma-core/chroma/blob/main/rust/js_bindings/src/lib.rs). Inside this crate there is also an `npm` directory defining platform specific packages for these JS bindings. Note that every package specifies the platform it supports. These packages are published by the `build-js-bindings.yml` workflow. Our main JS client, `clients/js/packages/chromadb`, specifies all platforms as optional dependencies. When `npm install chromadb`ing, the correct optional dependency will be installed. There, `bindings.ts` exposes that package to `cli.ts`, where we wrap the entry point. Follow up work: - Script for better local dev experience. - Update JS release runbook for updating bindings versions. ## Test plan *How are these changes tested?* - [ ] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?*
1 parent 8b5cc1a commit d07f5f7

File tree

20 files changed

+1658
-1551
lines changed

20 files changed

+1658
-1551
lines changed
+252
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
name: JS Bindings CI
2+
env:
3+
DEBUG: napi:*
4+
APP_NAME: "chromadb-js-bindings"
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
6+
permissions:
7+
contents: write
8+
id-token: write
9+
'on':
10+
workflow_dispatch: {}
11+
workflow_call: {}
12+
jobs:
13+
build-macos:
14+
name: Build macOS bindings
15+
runs-on: macos-latest
16+
defaults:
17+
run:
18+
working-directory: rust/js_bindings
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
with:
24+
version: 9
25+
run_install: false
26+
- name: Setup node
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: pnpm
31+
cache-dependency-path: rust/js_bindings/pnpm-lock.yaml
32+
- name: Set up Rust toolchain
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
override: true
37+
- name: Install Protoc
38+
uses: arduino/setup-protoc@v3
39+
with:
40+
repo-token: ${{ secrets.GITHUB_TOKEN }}
41+
- name: Add targets
42+
run: |
43+
rustup target add x86_64-apple-darwin
44+
rustup target add aarch64-apple-darwin
45+
- name: Cache cargo
46+
uses: actions/cache@v4
47+
with:
48+
path: |
49+
~/.cargo/registry/index/
50+
~/.cargo/registry/cache/
51+
~/.cargo/git/db/
52+
rust/js_bindings/.cargo-cache
53+
rust/js_bindings/target/
54+
key: macos-cargo
55+
- name: Install dependencies
56+
run: pnpm install
57+
- name: Build ARM64
58+
run: pnpm build --target aarch64-apple-darwin
59+
shell: bash
60+
- name: Build x86_64
61+
run: pnpm build --target x86_64-apple-darwin
62+
shell: bash
63+
- name: Upload ARM64 artifact
64+
uses: actions/upload-artifact@v4
65+
with:
66+
name: bindings-aarch64-apple-darwin
67+
path: rust/js_bindings/chromadb-js-bindings.darwin-arm64.node
68+
if-no-files-found: error
69+
- name: Upload x86_64 artifact
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: bindings-x86_64-apple-darwin
73+
path: rust/js_bindings/chromadb-js-bindings.darwin-x64.node
74+
if-no-files-found: error
75+
76+
build-windows:
77+
name: Build Windows bindings
78+
runs-on: windows-latest
79+
defaults:
80+
run:
81+
working-directory: rust/js_bindings
82+
steps:
83+
- uses: actions/checkout@v4
84+
- name: Install pnpm
85+
uses: pnpm/action-setup@v4
86+
with:
87+
version: 9
88+
run_install: false
89+
- name: Setup node
90+
uses: actions/setup-node@v4
91+
with:
92+
node-version: 20
93+
cache: pnpm
94+
cache-dependency-path: rust/js_bindings/pnpm-lock.yaml
95+
- name: Set up Rust toolchain
96+
uses: actions-rs/toolchain@v1
97+
with:
98+
toolchain: stable
99+
override: true
100+
- name: Install Protoc
101+
uses: arduino/setup-protoc@v2
102+
with:
103+
repo-token: ${{ secrets.GITHUB_TOKEN }}
104+
- name: Add target
105+
run: rustup target add x86_64-pc-windows-msvc
106+
shell: bash
107+
- name: Cache cargo
108+
uses: actions/cache@v4
109+
with:
110+
path: |
111+
~/.cargo/registry/index/
112+
~/.cargo/registry/cache/
113+
~/.cargo/git/db/
114+
rust/js_bindings/.cargo-cache
115+
rust/js_bindings/target/
116+
key: windows-cargo
117+
- name: Install dependencies
118+
run: pnpm install
119+
- name: Build x86_64
120+
run: pnpm build --target x86_64-pc-windows-msvc
121+
shell: bash
122+
- name: Upload x86_64 artifact
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: bindings-x86_64-pc-windows-msvc
126+
path: rust/js_bindings/chromadb-js-bindings.win32-x64-msvc.node
127+
if-no-files-found: error
128+
129+
build-linux:
130+
name: Build Linux bindings
131+
runs-on: depot-ubuntu-22.04-16
132+
defaults:
133+
run:
134+
working-directory: rust/js_bindings
135+
steps:
136+
- uses: actions/checkout@v4
137+
- name: Install pnpm
138+
uses: pnpm/action-setup@v4
139+
with:
140+
version: 9
141+
run_install: false
142+
- name: Setup node
143+
uses: actions/setup-node@v4
144+
with:
145+
node-version: 20
146+
cache: pnpm
147+
cache-dependency-path: rust/js_bindings/pnpm-lock.yaml
148+
- name: Set up Rust toolchain
149+
uses: actions-rs/toolchain@v1
150+
with:
151+
toolchain: stable
152+
override: true
153+
- name: Install Protoc
154+
uses: arduino/setup-protoc@v2
155+
with:
156+
repo-token: ${{ secrets.GITHUB_TOKEN }}
157+
- name: Add targets
158+
run: |
159+
rustup target add x86_64-unknown-linux-gnu
160+
rustup target add aarch64-unknown-linux-gnu
161+
- name: Install ARM64 cross-compilation tools
162+
run: |
163+
sudo apt-get update
164+
sudo apt-get install -y \
165+
gcc-aarch64-linux-gnu \
166+
g++-aarch64-linux-gnu \
167+
libc6-dev-arm64-cross
168+
- name: Cache cargo
169+
uses: actions/cache@v4
170+
with:
171+
path: |
172+
~/.cargo/registry/index/
173+
~/.cargo/registry/cache/
174+
~/.cargo/git/db/
175+
rust/js_bindings/.cargo-cache
176+
rust/js_bindings/target/
177+
key: linux-cargo
178+
- name: Install dependencies
179+
run: pnpm install
180+
- name: Build ARM64
181+
run: |
182+
# Set linker and compiler environment variables
183+
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
184+
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
185+
export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
186+
# Add no_asm flag to avoid assembly issues
187+
export RUSTFLAGS="--cfg no_asm"
188+
# Build with the correct environment
189+
pnpm build --target aarch64-unknown-linux-gnu
190+
shell: bash
191+
- name: Build x86_64
192+
run: pnpm build --target x86_64-unknown-linux-gnu
193+
shell: bash
194+
- name: Upload ARM64 artifact
195+
uses: actions/upload-artifact@v4
196+
with:
197+
name: bindings-aarch64-unknown-linux-gnu
198+
path: rust/js_bindings/chromadb-js-bindings.linux-arm64-gnu.node
199+
if-no-files-found: error
200+
- name: Upload x86_64 artifact
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: bindings-x86_64-unknown-linux-gnu
204+
path: rust/js_bindings/chromadb-js-bindings.linux-x64-gnu.node
205+
if-no-files-found: error
206+
publish:
207+
name: Publish
208+
runs-on: ubuntu-latest
209+
defaults:
210+
run:
211+
working-directory: rust/js_bindings
212+
needs:
213+
- build-macos
214+
- build-windows
215+
- build-linux
216+
steps:
217+
- uses: actions/checkout@v4
218+
- name: Install pnpm
219+
uses: pnpm/action-setup@v4
220+
with:
221+
version: 9
222+
run_install: false
223+
- name: Setup node
224+
uses: actions/setup-node@v4
225+
with:
226+
node-version: 20
227+
cache: pnpm
228+
cache-dependency-path: rust/js_bindings/pnpm-lock.yaml
229+
- name: Install dependencies
230+
run: pnpm install
231+
- name: Download all artifacts
232+
uses: actions/download-artifact@v4
233+
with:
234+
path: artifacts
235+
- name: Move artifacts
236+
run: pnpm artifacts
237+
- name: List packages
238+
run: ls -R ./npm
239+
shell: bash
240+
- name: Publish
241+
run: |
242+
set -e
243+
npm config set provenance true
244+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
245+
for dir in npm/*; do
246+
if [ -d "$dir" ]; then
247+
cd "$dir" && npm publish --access public && cd -
248+
fi
249+
done
250+
env:
251+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
252+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/_javascript-client-tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ jobs:
1212
- uses: pnpm/action-setup@v3
1313
with:
1414
version: "9"
15+
- name: Install dependencies
16+
run: cd clients/js && pnpm install --no-frozen-lockfile
1517
- name: Test
1618
run: bin/ts-integration-test.sh

0 commit comments

Comments
 (0)