Skip to content

Commit

Permalink
Clean up tlsn-wasm build (#553)
Browse files Browse the repository at this point in the history
ci: automate tlsn-wasm build + store artifact for tags + manual workflow for npm release

+ Improved package: add description, repo information etc
  • Loading branch information
heeckhau authored Dec 6, 2024
1 parent cacca10 commit 85e0f5b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 17 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/releng.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions crates/benches/browser/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
16 changes: 7 additions & 9 deletions crates/wasm/README.md
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 27 additions & 3 deletions crates/wasm/build.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions crates/wasm/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[toolchain]
channel = "nightly"
components = ["rust-src"]
targets = ["wasm32-unknown-unknown"]

0 comments on commit 85e0f5b

Please sign in to comment.