Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"packages/wasm-dpp",
"packages/withdrawals-contract",
"packages/token-history-contract",
"packages/keyword-search-contract"
"packages/keyword-search-contract",
"packages/wasm-drive-verify"
],
"resolutions": {
"pbkdf2": "^3.1.3",
Expand Down
18 changes: 5 additions & 13 deletions packages/wasm-drive-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
drive = { path = "../rs-drive", default-features = false, features = ["verify"] }
dpp = { path = "../rs-dpp", default-features = false, features = [
"state-transitions",
"state-transitions",
"system_contracts",
"data-contract-serde-conversion",
"data-contract-json-conversion",
Expand Down Expand Up @@ -42,10 +42,10 @@ bincode = { version = "2.0.0-rc.3" }
wasm-bindgen-test = "0.3.39"
criterion = { version = "0.5", default-features = false, features = [] }
dpp = { path = "../rs-dpp", default-features = false, features = [
"state-transitions",
"random-public-keys",
"random-identities",
"random-documents",
"state-transitions",
"random-public-keys",
"random-identities",
"random-documents",
"system_contracts",
"data-contract-serde-conversion",
"data-contract-json-conversion",
Expand Down Expand Up @@ -75,14 +75,6 @@ governance = []
transitions = []
debug_logs = []

[profile.release]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these settings to .cargo/config.toml and .cargo/config-release.toml instead of adding them to the build script?

Copilot suggests (but I didn't test):

[target.wasm32-unknown-unknown.profile.release]
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work.
3.6 mb instead of 3 mb.

And if you put it in .cargo/config.toml, it throws an error

error: expected a string, but found a table for `release` in /Users/bebra/Documents/Dash/verify/platform/packages/wasm-drive-verify/.cargo/config.toml

# Optimize for small code size
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"

[[bench]]
name = "simple_benchmarks"
harness = false
Expand Down
90 changes: 58 additions & 32 deletions packages/wasm-drive-verify/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,74 @@ echo "Building wasm-drive-verify..."

# Build the Rust WASM target
echo "Building Rust WASM target..."
cargo build --target wasm32-unknown-unknown --release
cargo build --target wasm32-unknown-unknown --release \
--config 'profile.release.panic="abort"' \
--config 'profile.release.strip=true' \
--config 'profile.release.debug=false' \
--config 'profile.release.incremental=false' \
--config 'profile.release.lto=true' \
--config 'profile.release.opt-level="z"' \
--config 'profile.release.codegen-units=1' \

# Create pkg directory if it doesn't exist
mkdir -p pkg

if command -v wasm-snip &> /dev/null; then
wasm-snip ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm -o ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm --snip-rust-fmt-code --snip-rust-panicking-code
fi

# Run wasm-bindgen
echo "Running wasm-bindgen..."
if ! command -v wasm-bindgen &> /dev/null; then
echo "Error: 'wasm-bindgen' not found. Install via 'cargo install wasm-bindgen-cli'." >&2
exit 1
fi
wasm-bindgen ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm \
--out-dir pkg \
--target web

# Create proper package.json if it doesn't exist or is incomplete
if [ ! -f pkg/package.json ] || ! grep -q '"name"' pkg/package.json; then
echo "Creating package.json..."
# Extract version from Cargo.toml
VERSION=$(grep -E '^version =' Cargo.toml | head -1 | sed -E 's/version = "([^"]+)"/\1/')
cat > pkg/package.json << EOF
{
"name": "wasm-drive-verify",
"version": "$VERSION",
"description": "WASM bindings for Drive verify functions",
"main": "wasm_drive_verify.js",
"types": "wasm_drive_verify.d.ts",
"author": "Dash Core Group <dev@dash.org>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/dashpay/platform.git"
},
"files": [
"wasm_drive_verify_bg.wasm",
"wasm_drive_verify.js",
"wasm_drive_verify.d.ts",
"wasm_drive_verify_bg.wasm.d.ts"
]
}
EOF
wasm-bindgen \
--typescript \
--out-dir=pkg \
--target=web \
--omit-default-module-path ../../target/wasm32-unknown-unknown/release/wasm_drive_verify.wasm

if command -v wasm-opt &> /dev/null; then
echo "Optimizing wasm using Binaryen"
wasm-opt \
--code-folding \
--const-hoisting \
--abstract-type-refining \
--dce \
--strip-producers \
-Oz \
Comment thread
owl352 marked this conversation as resolved.
--generate-global-effects \
--enable-bulk-memory \
--enable-nontrapping-float-to-int \
-tnh \
--flatten \
--rereloop \
-Oz \
--converge \
--vacuum \
--dce \
--gsi \
--inlining-optimizing \
--merge-blocks \
--simplify-locals \
--optimize-added-constants \
--optimize-casts \
--optimize-instructions \
--optimize-stack-ir \
--remove-unused-brs \
--remove-unused-module-elements \
--remove-unused-names \
--remove-unused-types \
--post-emscripten \
-Oz \
-Oz \
"pkg/wasm_drive_verify_bg.wasm" \
-o \
"pkg/wasm_drive_verify_bg.wasm"
else
echo "wasm-opt command not found. Skipping wasm optimization."
fi

echo "Build complete!"
echo "Output files are in the pkg/ directory"
echo "Output files are in the pkg/ directory"
8 changes: 6 additions & 2 deletions packages/wasm-drive-verify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "wasm-drive-verify",
"collaborators": ["Dash Core Group <dev@dash.org>"],
"collaborators": [
"Dash Core Group <dev@dash.org>"
],
"version": "1.8.0",
"license": "MIT",
"description": "WASM bindings for Drive verify functions",
Expand All @@ -9,6 +11,8 @@
"url": "https://github.com/dashpay/platform.git"
},
"type": "module",
"main": "pkg/wasm_drive_verify.js",
"types": "pkg/wasm_drive_verify.d.ts",
Comment thread
owl352 marked this conversation as resolved.
"exports": {
".": {
"import": "./dist/index.js",
Expand Down Expand Up @@ -52,4 +56,4 @@
"build": "./build.sh",
"build:modules": "./scripts/build-modules.sh"
}
}
}
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16284,6 +16284,12 @@ __metadata:
languageName: node
linkType: hard

"wasm-drive-verify@workspace:packages/wasm-drive-verify":
version: 0.0.0-use.local
resolution: "wasm-drive-verify@workspace:packages/wasm-drive-verify"
languageName: unknown
linkType: soft

"wasm-x11-hash@npm:~0.0.2":
version: 0.0.2
resolution: "wasm-x11-hash@npm:0.0.2"
Expand Down