Clean up tlsn-wasm build (#553)

ci: automate tlsn-wasm build + store artifact for tags + manual workflow for npm release

+ Improved package: add description, repo information etc
This commit is contained in:
Hendrik Eeckhaut
2024-12-06 11:03:23 +01:00
committed by GitHub
parent cacca108ed
commit 85e0f5b467
7 changed files with 92 additions and 17 deletions

View File

@@ -62,8 +62,8 @@ jobs:
- name: Test
run: cargo test
build-wasm:
name: Build and test wasm
wasm:
name: Build and Test wasm
runs-on: ubuntu-latest
steps:
- name: Checkout repository
@@ -97,6 +97,25 @@ jobs:
run: |
cd crates/wasm-test-runner
./run.sh
- name: Run build
run: |
cd crates/wasm
./build.sh
- name: Dry Run NPM Publish
run: |
cd crates/wasm/pkg
npm publish --dry-run
- name: Save tlsn-wasm package for tagged builds
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}-tlsn-wasm-pkg
path: ./crates/wasm/pkg
if-no-files-found: error
tests-integration:
name: Run tests release build
runs-on: ubuntu-latest

27
.github/workflows/releng.yml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: Publish tlsn-wasm to NPM
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to publish to NPM'
required: true
default: '0.1.0-alpha.8-pre'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.event.inputs.tag }}-tlsn-wasm-pkg
path: tlsn-wasm-pkg
- name: NPM Publish for tlsn-wasm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd tlsn-wasm-pkg
npm publish

View File

@@ -16,14 +16,14 @@ serio = { workspace = true }
anyhow = { workspace = true }
tracing = { workspace = true }
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4.37"
wasm-bindgen = { version = "0.2.87" }
wasm-bindgen-futures = { version = "0.4.37" }
web-time = { workspace = true }
# Use the patched ws_stream_wasm to fix the issue https://github.com/najamelan/ws_stream_wasm/issues/12#issuecomment-1711902958
ws_stream_wasm = { version = "0.7.4", git = "https://github.com/tlsnotary/ws_stream_wasm", rev = "2ed12aad9f0236e5321f577672f309920b2aef51", features = ["tokio_io"]}
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-rayon = { version = "1", features = ["no-bundler"] }
wasm-bindgen-rayon = { version = "1.2", features = ["no-bundler"] }
[package.metadata.wasm-pack.profile.release]
# Note: these wasm-pack options should match those in crates/wasm/Cargo.toml

View File

@@ -2,6 +2,11 @@
name = "tlsn-wasm"
version = "0.1.0-alpha.8-pre"
edition = "2021"
repository = "https://github.com/tlsnotary/tlsn.git"
description = "A core WebAssembly package for TLSNotary."
license = "MIT OR Apache-2.0"
keywords = ["tls", "tlsn", "tlsnotary"]
homepage = "https://tlsnotary.org"
[lib]
crate-type = ["cdylib", "rlib"]

View File

@@ -1,13 +1,11 @@
# TLSNotary WASM bindings
# TLSNotary WASM Bindings
## Build
This crate provides a WebAssembly package for TLSNotary, offering core functionality for the TLSNotary attestation protocol along with useful TypeScript types.
This crate must be built using the nightly rust compiler with the following flags:
```bash
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
rustup run nightly \
wasm-pack build --target web . -- -Zbuild-std=panic_abort,std
```
For most use cases, you may prefer to use the `tlsn-js` package instead: [tlsn-js on npm](https://www.npmjs.com/package/tlsn-js).
## Links
- [Website](https://tlsnotary.org)
- [Documentation](https://docs.tlsnotary.org)
- [API Docs](https://tlsnotary.github.io/tlsn)

View File

@@ -1,3 +1,27 @@
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' \
rustup run nightly \
wasm-pack build --target web . -- -Zbuild-std=panic_abort,std
#!/bin/sh
# This crate must be built using the nightly Rust compiler with specific flags.
# This script automates the build process.
set -e
# Clean up older builds
rm -rf pkg
# Build tlsn_wasm package
wasm-pack build --target web .
# Patch tlsn_wasm.js import in workerHelpers.worker.js
file=$(find ./pkg/snippets -name "workerHelpers.worker.js" -print -quit)
if [ -z "$file" ]; then
echo "Error: workerHelpers.worker.js not found"
find pkg
exit 1
fi
temp=$(mktemp)
sed 's|../../../|../../../tlsn_wasm.js|' "$file" >"$temp" && mv "$temp" "$file"
# Add snippets directory to package.json
file="pkg/package.json"
temp=$(mktemp)
jq '.files += ["snippets/"]' "$file" >"$temp" && mv "$temp" "$file"

View File

@@ -1,2 +1,4 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]