Skip to content

Commit

Permalink
Add NodeJS support (#118)
Browse files Browse the repository at this point in the history
* init litesvm-node

* napi rough work

* more napi rough work

* more rough work

* get the setup methods compiling

* typescript setup

* add most LiteSVM methods

* add compute budget support

* add missing methods

* move profile to fix warning

* add lint scripts

* add structured transaction error support

* delete accidental file

* add tests, add toString methods, add get/set_clock, add friendly SimulatedTransactionInfo wrapper

* fix withComputeBudget

* fix lint

* use swc-jest

* fix FeatureSet usage

* update some i64 types

* add rent sysvar

* add more tests

* update lock file

* add more toString methods

* move files and add some setters

* add epoch_rewards

* add epoch_schedule

* add last_restart_slot

* add slot_hashes

* add slot_history

* add stake_history

* prefer to_string_js macro

* rough work

* add missing methods

* fix Debug impl

* fix clock test

* split out more files

* add doc comments

* clean up Cargo.toml a bit

* add repository field

* add docs

* add ci

* specify cache-dependency-path

* remove unused file

* missing cd commands

* use openssl-vendored feature

* add perl install step

* move perl install step

* missing =

* add debugging

* change if syntax

* remove debugging

* move perl install to build command

* modify command

* debug linux distro

* missing &&

* remove double &&

* more distro debugging

* use apk to install perl

* debug test step

* fix paths

* try fix command

* try fix command again

* use working directory

* copy compiled programs to make ci tests easier

* fix path

* add some logs for ci

* try fix artifact download path

* ignore breaking test on musl, can't debug

* remove "List packages" step

* add docs check workflow

* remove test logs

* add release-node workflow

* remove i64 footgun

* add bigint conversion functions

* error handling for bigint converions

* simplify calculate_burn

* fix lint

* add getTransaction test

* typo

* fix stupid js bug in test

* fix testPathIgnorePatterns for musl ci
  • Loading branch information
kevinheavey authored Jan 19, 2025
1 parent 1cc04f4 commit 4f00b0d
Show file tree
Hide file tree
Showing 102 changed files with 22,122 additions and 15 deletions.
199 changes: 199 additions & 0 deletions .github/workflows/node-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
name: node-build
env:
DEBUG: napi:*
APP_NAME: litesvm
MACOSX_DEPLOYMENT_TARGET: '10.13'
on:
push:
branches: [master]
paths-ignore:
- '**/*.md'
- LICENSE
- '**/*.gitignore'
- .editorconfig
- crates/node-litesvm/docs/**
pull_request:
branches: [master]
paths-ignore:
- '**/*.md'
- LICENSE
- '**/*.gitignore'
- .editorconfig
- crates/node-litesvm/docs/**
jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-13
target: x86_64-apple-darwin
build: |
cd crates/node-litesvm &&
yarn build &&
strip -x litesvm/*.node
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: |-
set -e &&
cd crates/node-litesvm &&
yarn build --target x86_64-unknown-linux-gnu &&
strip litesvm/*.node
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust@sha256:10573060f07edd964f5de04a92d19f8228b396310a5c9c0df23ef69b1f566ab9
build: set -e && apk add perl && cd crates/node-litesvm && yarn build && strip litesvm/*.node
- host: macos-13
target: aarch64-apple-darwin
build: |
rustup target add aarch64-apple-darwin &&
cd crates/node-litesvm &&
yarn build --target aarch64-apple-darwin
strip -x litesvm/*.node
name: stable - ${{ matrix.settings.target }} - node@18
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: 18
check-latest: true
cache: yarn
cache-dependency-path: crates/node-litesvm/yarn.lock
- name: Install
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
.cargo-cache
target/
key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }}
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash
- name: Install dependencies
run: cd crates/node-litesvm && corepack enable && yarn install
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
if: ${{ !matrix.settings.docker }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: crates/node-litesvm/litesvm/litesvm.*.node
if-no-files-found: error
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node:
- '18'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
cache-dependency-path: crates/node-litesvm/yarn.lock
- name: Install dependencies
run: cd crates/node-litesvm && yarn install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-unknown-linux-gnu
path: crates/node-litesvm/litesvm/
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build/crates/node-litesvm node:${{ matrix.node }}-slim yarn test
test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node:
- '18'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: yarn
cache-dependency-path: crates/node-litesvm/yarn.lock
- name: Install dependencies
run: |
cd crates/node-litesvm
yarn config set supportedArchitectures.libc "musl"
yarn install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-unknown-linux-musl
path: crates/node-litesvm/litesvm/
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build/crates/node-litesvm node:${{ matrix.node }}-alpine yarn test --testPathIgnorePatterns usdc copy
universal-macOS:
name: Build universal macOS binary
needs:
- build
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
cache: yarn
cache-dependency-path: crates/node-litesvm/yarn.lock
- name: Install dependencies
run: cd crates/node-litesvm && yarn install
- name: Download macOS x64 artifact
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-apple-darwin
path: crates/node-litesvm/artifacts
- name: Download macOS arm64 artifact
uses: actions/download-artifact@v3
with:
name: bindings-aarch64-apple-darwin
path: crates/node-litesvm/artifacts
- name: Combine binaries
run: cd crates/node-litesvm && yarn universal
- name: Test universal binary
run: cd crates/node-litesvm && cp litesvm.darwin-universal.node litesvm/ && yarn test
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-universal-apple-darwin
path: crates/node-litesvm/litesvm/litesvm.*.node
if-no-files-found: error
28 changes: 28 additions & 0 deletions .github/workflows/node-docs-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: node-docs-check

on:
push:
branches: [master]
paths-ignore:
- LICENSE
- '**/*.gitignore'
- .editorconfig
pull_request:
branches: [master]
paths-ignore:
- LICENSE
- '**/*.gitignore'
- .editorconfig

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v2
- name: Install dependencies
run: cd crates/node-litesvm && corepack enable && yarn install

- name: Build documentation
run: cd crates/node-litesvm && yarn docs:build
25 changes: 25 additions & 0 deletions .github/workflows/node-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: node-docs

on:
push:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v2
- name: Install dependencies
run: cd crates/node-litesvm && corepack enable && yarn install

- name: Build documentation
run: cd crates/node-litesvm && yarn docs:build

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./crates/node-litesvm/docs/.vuepress/dist/
force_orphan: true
32 changes: 32 additions & 0 deletions .github/workflows/node-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: node-lint
on:
push:
branches: [master]
pull_request:
branches: [master]
paths-ignore:
- '**/*.md'
- LICENSE
- '**/*.gitignore'
- .editorconfig
- node-litesvm/docs/**
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
- uses: hecrj/setup-rust-action@v1
with:
rust-version: 1.68.0
components: clippy
- name: Install dependencies
run: cd crates/node-litesvm && corepack enable && yarn install
- name: Lint rust
run: cd crates/node-litesvm && yarn lint:rust
- name: Lint JS
run: cd crates/node-litesvm && yarn lint:js
37 changes: 37 additions & 0 deletions .github/workflows/release-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: release NodeJS

on:
push:
tags:
- "node-v[0-9]+.[0-9]+.[0-9]+"
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
cache: yarn
cache-dependency-path: crates/node-litesvm/yarn.lock
- name: Install dependencies
run: cd crates/node-litesvm/ && corepack enable && yarn install
- name: Download all artifacts
uses: dawidd6/action-download-artifact@v2
with:
workflow: build.yml
path: crates/node-litesvm/artifacts
- name: Move artifacts
run: cd crates/node-litesvm/ && yarn artifacts
- name: Compile Typescript
run: crates/node-litesvm/ && yarn tsc
- name: Publish
run: |
cd crates/node-litesvm/
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading

0 comments on commit 4f00b0d

Please sign in to comment.