Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic langsmith-nodejs Rust bindings #1293

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 250 additions & 2 deletions .github/workflows/test_langsmith_nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,258 @@ permissions:

env:
RUST_VERSION: '1.82'
NODEJS_VERSION: 22
RUST_WORKSPACE_PATH: 'rust' # The location of the Rust workspace relative to the repo root.
BINDINGS_RELATIVE_PATH: 'crates/langsmith-nodejs' # Bindings path relative to the Rust workspace.
MACOSX_DEPLOYMENT_TARGET: '13' # This governs what SDK we use & the oldest supported macOS.

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
settings:
- host: macos-15
target: aarch64-apple-darwin
build: |
cd "$RUST_WORKSPACE_PATH/$BINDINGS_RELATIVE_PATH"
rustup default "$RUST_VERSION"
yarn build
strip -x *.node
- host: windows-latest
target: x86_64-pc-windows-msvc
build: |
cd "$RUST_WORKSPACE_PATH/$BINDINGS_RELATIVE_PATH"
rustup default "$RUST_VERSION"
yarn build
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: |
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" "$DOCKER_REGISTRY_URL"
docker pull "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian"
docker tag "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian" builder
build: |
docker run \
--rm \
-v ~/.cargo/git:/root/.cargo/git \
-v ~/.cargo/registry:/root/.cargo/registry \
-v "$(pwd):/build" \
-w /build \
builder \
/bin/bash -c \
"set -euo pipefail && \
cd "$RUST_WORKSPACE_PATH/$BINDINGS_RELATIVE_PATH" && \
rustup default "$RUST_VERSION" && \
yarn build && \
strip langsmith-nodejs.linux-x64-gnu.node"
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: |
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" "$DOCKER_REGISTRY_URL"
docker pull "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine"
docker tag "$DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine" builder
build: |
docker run \
--rm \
-v ~/.cargo/git:/root/.cargo/git \
-v ~/.cargo/registry:/root/.cargo/registry \
-v "$(pwd):/build" \
-w /build \
builder \
/bin/bash -c \
"set -euo pipefail && \
cd "$RUST_WORKSPACE_PATH/$BINDINGS_RELATIVE_PATH" && \
rustup default "$RUST_VERSION" && \
yarn build && \
strip langsmith-nodejs.linux-x64-musl.node"
name: build ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- run: echo 'hello world'
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODEJS_VERSION }}
check-latest: true

- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "${{ env.RUST_VERSION }}"
cache-workspaces: "${{ env.RUST_WORKSPACE_PATH }} -> target"
rustflags: ""
target: "${{ matrix.settings.target }}"

- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules"
key: langsmith-nodejs-build-npm-cache-${{ matrix.settings.target }}-node@${{ env.NODEJS_VERSION }}-${{ hashFiles('yarn.lock') }}

- name: Pull latest image
env:
DOCKER_REGISTRY_URL: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: ${{ matrix.settings.docker }}

- name: Install dependencies
working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"
shell: bash
run: |
yarn install \
--ignore-scripts \
--frozen-lockfile \
--registry https://registry.npmjs.org \
--network-timeout 300000

- name: Build
shell: bash
run: |
set -euxo pipefail
${{ matrix.settings.build }}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: "bindings-${{ matrix.settings.target }}"
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/langsmith-nodejs.*.node"

test-macos-windows-bindings:
name: "test node@${{ matrix.node }} on ${{ matrix.settings.target }}"
needs:
- build
strategy:
fail-fast: false
matrix:
settings:
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: macos-15
target: aarch64-apple-darwin
node:
- '18'
- '20'
- '22'
runs-on: ${{ matrix.settings.host }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODEJS_VERSION }}
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules"
key: langsmith-nodejs-test-npm-cache-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"
shell: bash
run: |
set -euo pipefail
yarn install \
--ignore-scripts \
--frozen-lockfile \
--registry https://registry.npmjs.org \
--network-timeout 300000

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"

- name: Test bindings
working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"
shell: bash
run: |
set -euo pipefail

# List downloaded bindings
ls .

# Run tests.
yarn test

test-linux-bindings:
name: test node@${{ matrix.node }} on ${{ matrix.settings.target }}
needs:
- build
strategy:
fail-fast: false
matrix:
settings:
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker-suffix: slim
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker-suffix: alpine
node:
- '18'
- '20'
- '22'
runs-on: "${{ matrix.settings.host }}"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODEJS_VERSION }}
check-latest: true

- name: Cache NPM dependencies
uses: actions/cache@v4
with:
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}/node_modules"
key: langsmith-nodejs-test-npm-cache-${{ matrix.settings.target }}-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
working-directory: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"
shell: bash
run: |
set -euo pipefail
yarn install \
--ignore-scripts \
--frozen-lockfile \
--registry https://registry.npmjs.org \
--network-timeout 300000

- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: "${{ env.RUST_WORKSPACE_PATH }}/${{ env.BINDINGS_RELATIVE_PATH }}"

- name: Test bindings
working-directory: "${{ env.RUST_WORKSPACE_PATH }}"
shell: bash
run: |
set -euo pipefail

# List downloaded bindings
ls "$BINDINGS_RELATIVE_PATH/"

# Run tests.
docker run \
--rm \
-v "$(pwd):/rust" \
-w "/rust/$BINDINGS_RELATIVE_PATH" \
node:${{ matrix.node }}-${{ matrix.settings.docker-suffix }} \
yarn test
1 change: 1 addition & 0 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"dependencies": {
"@types/uuid": "^10.0.0",
"commander": "^10.0.1",
"langsmith-nodejs": "file:../rust/crates/langsmith-nodejs",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, we'll need to replace this path dependency with a dependency on a real, published JS library.

"p-queue": "^6.6.2",
"p-retry": "4",
"semver": "^7.6.3",
Expand Down
Loading
Loading