feat: JS<>wasm npm package release script (#404)

This commit is contained in:
Ethan Cemer
2023-08-12 09:35:15 -05:00
committed by GitHub
parent 28e5413a83
commit d6a7841026
6 changed files with 96 additions and 4 deletions

View File

@@ -103,7 +103,7 @@ jobs:
- name: Add rust-src
run: rustup component add rust-src --toolchain nightly-2023-04-17-x86_64-unknown-linux-gnu
- name: Run wasm verifier tests
run: wasm-pack test --chrome --headless -- -Z build-std="panic_abort,std"
run: wasm-pack test --chrome --headless -- -Z build-std="panic_abort,std" --features web
render-circuit:
runs-on: ubuntu-latest-32-cores

87
.github/workflows/wasm.yml vendored Normal file
View File

@@ -0,0 +1,87 @@
name: Build and Publish WASM<>JS Bindings
on:
# Requires someone to trigger this build script via github workflows
# It is required that the codebase is audited by contributors
# before triggering to reduce the likelihood of supply chain attacks
workflow_dispatch:
defaults:
run:
working-directory: .
jobs:
wasm-publish:
name: publish-wasm-bindings
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-04-17
override: true
components: rustfmt, clippy
- uses: jetli/wasm-pack-action@v0.4.0
- name: Add wasm32-unknown-unknown target
run: rustup target add wasm32-unknown-unknown
- name: Install wasm-server-runner
run: cargo install wasm-server-runner
- name: Add rust-src
run: rustup component add rust-src --toolchain nightly-2023-04-17-x86_64-unknown-linux-gnu
- name: Build wasm files for both web and nodejs compilation targets
run: |
wasm-pack build --target nodejs --out-dir ./pkg/nodejs . -- -Z build-std="panic_abort,std"
wasm-pack build --target web --out-dir ./pkg/web . -- -Z build-std="panic_abort,std" --features web
- name: Create package.json in pkg folder
shell: bash
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
echo '{
"name": "ezkl-wasm",
"version": "${{ github.ref_name }}",
"files": [
"nodejs/ezkl_bg.wasm",
"nodejs/ezkl.js",
"nodejs/ezkl.d.ts",
"web/ezkl_bg.wasm",
"web/ezkl.js",
"web/ezkl.d.ts",
"web/snippets/wasm-bindgen-rayon-7afa899f36665473/src/workerHelpers.js",
"ezkl.js",
"ezkl.d.ts"
],
"main": "ezkl.js",
"types": "ezkl.d.ts",
"sideEffects": [
"web/snippets/*"
]
}' > pkg/package.json
- name: Create ezkl.js in pkg folder
run: |
echo "import * as nodejsFunctions from './nodejs/ezkl.js';" >> pkg/ezkl.js
echo "import * as webFunctions from './web/ezkl.js';" >> pkg/ezkl.js
echo "export const nodejs = nodejsFunctions;" >> pkg/ezkl.js
echo "export const web = webFunctions;" >> pkg/ezkl.js
- name: Create ezkl.d.ts in pkg folder
run: |
echo "export const nodejs: typeof import('./nodejs/ezkl');" >> pkg/ezkl.d.ts
echo "export const web: typeof import('./web/ezkl');" >> pkg/ezkl.d.ts
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18.12.1'
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
run: |
cd pkg
npm install
npm ci
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
target
pkg
data
*.csv
*.ipynb_checkpoints

View File

@@ -66,7 +66,7 @@ getrandom = { version = "0.2.8", features = ["js"] }
instant = { version = "0.1", features = [ "wasm-bindgen", "inaccurate" ] }
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
wasm-bindgen-rayon = "1.0"
wasm-bindgen-rayon = { version = "1.0", optional=true }
wasm-bindgen-test = "0.3.34"
serde-wasm-bindgen = "0.4"
wasm-bindgen = { version = "0.2.81", features = ["serde-serialize"]}
@@ -145,6 +145,7 @@ bench = false
required-features = ["ezkl"]
[features]
web = ["wasm-bindgen-rayon"]
default = ["ezkl"]
render = ["halo2_proofs/dev-graph", "plotters"]
onnx = ["dep:tract-onnx"]

View File

@@ -19,6 +19,7 @@ use wasm_bindgen::prelude::*;
use console_error_panic_hook;
#[cfg(feature = "web")]
pub use wasm_bindgen_rayon::init_thread_pool;
#[wasm_bindgen]

View File

@@ -14,10 +14,12 @@ mod wasm32 {
use halo2curves::bn256::{Fr, G1Affine, Fq};
use rand::rngs::StdRng;
use rand::SeedableRng;
pub use wasm_bindgen_rayon::init_thread_pool;
use wasm_bindgen_test::*;
#[cfg(feature = "web")]
pub use wasm_bindgen_rayon::init_thread_pool;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
wasm_bindgen_test_configure!(run_in_browser);
pub const KZG_PARAMS: &[u8] = include_bytes!("../tests/wasm/kzg");
pub const CIRCUIT_PARAMS: &[u8] = include_bytes!("../tests/wasm/settings.json");