Skip to content
Draft
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
13 changes: 11 additions & 2 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ jobs:
- name: Install clang
run: sudo apt-get install -y clang

- name: Run tests in wasm
run: RUSTFLAGS='-Dwarnings' make wasm
- name: Check that SDK crates compile to WASM
run: make wasm-check

- name: Install WASM bindings prerequisites
run: |
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --version 0.2.114
npm install -g pnpm@10

- name: Build WASM bindings
run: make wasm

- run: make is-dirty
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ __pycache__
build
.vscode
.kotlin
.vite
node_modules
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ members = [
"crates/iota-sdk-graphql-client-build",
"crates/iota-sdk-transaction-builder",
"crates/iota-sdk-types",
"crates/iota-sdk-wasm",
"crates/iota-sdk-wasm-types",
"crates/iota-sdk-wasm-client",
"crates/iota-sdk-wasm-crypto",
"crates/iota-sdk-wasm-transaction-builder",
"crates/iota-sdk/examples/polling-indexer",
]

Expand Down Expand Up @@ -48,3 +53,18 @@ iota-graphql-client-build = { version = "0.0.1-alpha.1", package = "iota-sdk-gra
iota-sdk = { version = "3.0.0-alpha.1", package = "iota-sdk", path = "crates/iota-sdk", default-features = false }
iota-transaction-builder = { version = "0.0.1-alpha.1", package = "iota-sdk-transaction-builder", path = "crates/iota-sdk-transaction-builder", default-features = false }
iota-types = { version = "0.0.1-alpha.1", package = "iota-sdk-types", path = "crates/iota-sdk-types", default-features = false }

# Custom profile for WASM builds — optimizes for binary size.
# Usage: cargo build -p iota-sdk-wasm --profile wasm-release --target wasm32-unknown-unknown
[profile.wasm-release]
inherits = "release"
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = "abort"

# Replace async-compat with a wasm32-compatible version that uses a transparent
# passthrough on wasm32 (no thread spawning, no Instant::now).
[patch.crates-io]
async-compat = { path = "patches/async-compat" }
53 changes: 47 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,33 @@ package_%.json: crates/iota-sdk-transaction-builder/tests/%/Move.toml crates/iot
test-with-localnet: package_test_example_v1.json package_test_example_v2.json ## Run tests with localnet
cargo nextest run -p iota-sdk-graphql-client -p iota-sdk-transaction-builder

.PHONY: wasm
wasm: ## Build WASM modules
# Verify that individual SDK crates compile to wasm32-unknown-unknown.
# This is a quick compatibility check, not the full WASM bindings build.
.PHONY: wasm-check
wasm-check: ## Check that SDK crates compile to WASM
$(MAKE) -C crates/iota-sdk wasm
$(MAKE) -C crates/iota-sdk-crypto wasm
$(MAKE) -C crates/iota-sdk-graphql-client wasm
$(MAKE) -C crates/iota-sdk-transaction-builder wasm
$(MAKE) -C crates/iota-sdk-types wasm

# Build the full WASM bindings package for browsers.
# Uses ubrn (uniffi-bindgen-react-native) to generate TS bindings, compile
# to wasm32, and run wasm-bindgen. Then esbuild bundles into dist/.
.PHONY: wasm
wasm: ## Build WASM bindings for browsers
cd bindings/wasm && pnpm install && npx ubrn build web --config ubrn.config.yaml --profile wasm-release
@# Optionally run wasm-opt on the wasm-bindgen output for size reduction.
@if command -v wasm-opt >/dev/null 2>&1; then \
printf "Running wasm-opt for size reduction...\n"; \
wasm-opt -Oz --vacuum --strip-debug \
--enable-bulk-memory --enable-mutable-globals --enable-sign-ext --enable-nontrapping-float-to-int \
bindings/wasm/src/ts/wasm-bindgen/index_bg.wasm \
-o bindings/wasm/src/ts/wasm-bindgen/index_bg.wasm; \
fi
cd bindings/wasm && pnpm run build
@printf "WASM bindings built successfully in bindings/wasm/dist/\n"

.PHONY: doc
doc: ## Generate documentation
RUSTDOCFLAGS="-Dwarnings --cfg=doc_cfg -Zunstable-options --generate-link-to-definition" RUSTC_BOOTSTRAP=1 cargo doc --all-features --no-deps
Expand All @@ -59,7 +78,7 @@ is-dirty: ## Checks if repository is dirty
@(test -z "$$(git diff)" || (git diff && false)) && (test -z "$$(git status --porcelain)" || (git status --porcelain && false))

.PHONY: ci
ci: check-features check-fmt test wasm ## Run the full CI process
ci: check-features check-fmt test wasm-check ## Run the full CI process

.PHONY: ci-full
ci-full: ci doc ## Run the full CI process and generate documentation
Expand All @@ -83,6 +102,7 @@ bindings: ## Build all bindings
@$(MAKE) python
@$(MAKE) csharp
@$(MAKE) swift
@$(MAKE) wasm

.PHONY: bindings-example
bindings-example: ## Run a specific example for all bindings. Usage: make bindings-example example
Expand Down Expand Up @@ -116,9 +136,9 @@ bindings-examples-format: ## Format all bindings examples
@$(MAKE) csharp-examples-format
@$(MAKE) swift-examples-format

# Build ffi crate and detect platform
define build_binding
cargo build -p iota-sdk-ffi --lib --release; \
# Detect the shared library extension for the current platform.
# Used by binding targets that need to locate libiota_sdk_ffi.
define detect_lib_ext
case "$$(uname -s)" in \
Darwin) LIB_EXT=".dylib" ;; \
Linux) LIB_EXT=".so" ;; \
Expand All @@ -127,6 +147,12 @@ case "$$(uname -s)" in \
esac;
endef

# Build the FFI crate (release) and detect the library extension.
define build_binding
cargo build -p iota-sdk-ffi --lib --release; \
$(detect_lib_ext)
endef

.PHONY: go
go: ## Build Go bindings
@printf "Building Go bindings...\n"
Expand Down Expand Up @@ -319,6 +345,21 @@ swift-examples-format-check: ## Check format of all Swift bindings examples
swift-examples-format: ## Format all Swift bindings examples
@swift-format format --recursive bindings/swift/examples --in-place

# WASM examples are browser-based HTML files served via a local dev server.
# "make wasm-example chain_id" serves the bindings/wasm directory and opens the example.
.PHONY: wasm-example
wasm-example: ## Serve a WASM example in the browser. Usage: make wasm-example chain_id
%:
@true
wasm-example:
@printf "\nServing WASM example \"$(word 2,$(MAKECMDGOALS))\" at http://localhost:5173/examples/$(word 2,$(MAKECMDGOALS)).html\n"
@cd bindings/wasm && pnpm run serve

.PHONY: wasm-examples
wasm-examples: ## List available WASM examples (browser-based, must be opened manually)
@printf "Available WASM examples (serve with 'make wasm-example <name>'):\n"
@find bindings/wasm/examples -name "*.html" -exec basename {} .html \; | sort

.PHONY: example
example: ## Run a specific Rust example. Usage: make example example
%:
Expand Down
Binary file added bindings/wasm-client/dist/index_bg.wasm
Binary file not shown.
Loading
Loading