build(wasm): add wasm profile and optimize for perf (#933)

This commit is contained in:
sinu.eth
2025-07-02 08:52:47 -07:00
committed by GitHub
parent 008b901913
commit af85fa100f
9 changed files with 41 additions and 8 deletions

View File

@@ -112,7 +112,8 @@ jobs:
sudo apt-get install -y chromium-chromedriver
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# we install a specific version which supports custom profiles
run: cargo install --git https://github.com/rustwasm/wasm-pack.git --rev 32e52ca
- name: Use caching
uses: Swatinem/rust-cache@v2.7.7

View File

@@ -40,11 +40,9 @@ resolver = "2"
inherits = "release"
opt-level = 1
[profile.release.package."tlsn-wasm"]
opt-level = "z"
[profile.dev.package."tlsn-wasm"]
debug = false
[profile.wasm]
inherits = "release"
lto = true
[workspace.dependencies]
notary-client = { path = "crates/notary/client" }

View File

@@ -2,6 +2,15 @@
A harness for testing and benchmarking the TLSNotary protocol with both native and browser support.
## Installation
The harness requires the nightly compiler to build the WASM binary. Additionally, we depend on a specific
version of `wasm-pack` which must be installed:
```bash
cargo install --git https://github.com/rustwasm/wasm-pack.git --rev 32e52ca
```
## Getting started
First build the harness.

View File

@@ -4,4 +4,8 @@
cd "$(dirname "$0")"
rustup run nightly \
wasm-pack build executor --target web --no-pack --out-dir=../static/generated -- -Zbuild-std=panic_abort,std
wasm-pack build executor \
--profile wasm \
--target web \
--out-dir=../static/generated \
-- -Zbuild-std=panic_abort,std

View File

@@ -8,6 +8,9 @@ publish = false
name = "harness_executor"
crate-type = ["cdylib", "rlib"]
[package.metadata.wasm-pack.profile.custom]
wasm-opt = ["-O3"]
[dependencies]
tlsn-harness-core = { workspace = true }
tlsn-prover = { workspace = true }

View File

@@ -79,6 +79,10 @@ pub async fn main() -> Result<()> {
HeaderName::from_static("cross-origin-opener-policy"),
HeaderValue::from_static("same-origin"),
))
.layer(SetResponseHeaderLayer::overriding(
HeaderName::from_static("cache-control"),
HeaderValue::from_static("no-store"),
))
.service(files);
// build our application with a single route

View File

@@ -14,6 +14,9 @@ workspace = true
[lib]
crate-type = ["cdylib", "rlib"]
[package.metadata.wasm-pack.profile.custom]
wasm-opt = ["-O3"]
[features]
default = []
test = []

View File

@@ -4,6 +4,14 @@ This crate provides a WebAssembly package for TLSNotary, offering core functiona
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).
## Dependencies
A specific version of `wasm-pack` must be installed to build the WASM binary:
```bash
cargo install --git https://github.com/rustwasm/wasm-pack.git --rev 32e52ca
```
## Links
- [Website](https://tlsnotary.org)

View File

@@ -9,7 +9,10 @@ set -e
rm -rf pkg
# Build tlsn_wasm package
wasm-pack build --release --target web .
wasm-pack build \
--profile wasm \
--target web \
.
# Patch tlsn_wasm.js import in spawn.js snippet and copy it to the main folder
file=$(find ./pkg/snippets -name "spawn.js" -print -quit)