From fb232f070793dba59f101ea2e3378fadd43d54f5 Mon Sep 17 00:00:00 2001 From: Ross Savage <551697+dangeross@users.noreply.github.com> Date: Mon, 24 Mar 2025 06:21:58 +0100 Subject: [PATCH] Setup emscripten (#782) --- .github/workflows/main.yml | 9 +++++++++ CONTRIBUTING.md | 6 +++++- lib/Cargo.lock | 10 ++++++++++ lib/wasm/DEVELOPING.md | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lib/wasm/DEVELOPING.md diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6492616..1b44384 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -79,6 +79,9 @@ jobs: version: "27.2" repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup emsdk + uses: mymindstorm/setup-emsdk@v14 + - name: Clippy run: make wasm-clippy @@ -143,6 +146,9 @@ jobs: version: "27.2" repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup emsdk + uses: mymindstorm/setup-emsdk@v14 + - name: Cargo build working-directory: lib/wasm run: cargo build --target=wasm32-unknown-unknown @@ -295,6 +301,9 @@ jobs: version: "27.2" repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup emsdk + uses: mymindstorm/setup-emsdk@v14 + - name: Test WASM run: make wasm-test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 049e097..b576d62 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,7 +34,11 @@ __*[lib/bindings](lib/bindings)*__ __*[lib/core](lib/core)*__ * [bindings.rs](lib/core/src/bindings.rs) - Update the Rust interface for the Flutter Rust Bridge bindings. -After making these changes the [Dart](packages/dart), [Flutter](packages/flutter) and [React Native](packages/react-native) bindings code also need to be regenerated and included in your pull request. You can regenerate these from the project root using `make codegen`. Please see the prerequisites for [Flutter](lib/bindings/langs/flutter/README.md) and [React Native](packages/react-native/DEVELOPING.md) if this is your first time generating code. +__*[lib/wasm](lib/wasm)*__ +* [model.rs](lib/wasm/src/model.rs) - Update the structs/enums exported. +* [lib.rs](lib/wasm/src/lib.rs) - Update the Rust interface for the WASM bindings. + +After making these changes the [Dart](packages/dart), [Flutter](packages/flutter) and [React Native](packages/react-native) bindings code also need to be regenerated and included in your pull request. You can regenerate these from the project root using `make codegen`. Please see the prerequisites for [Flutter](lib/bindings/langs/flutter/README.md), [React Native](packages/react-native/DEVELOPING.md) and [WASM](lib/wasm/DEVELOPING.md) if this is your first time generating code. #### Testing Please adequately test your code using the existing tests and write additional tests for new features. You can run the tests from the project root using `make test`. You can also make use of the [CLI](cli) to test changes while developing your feature. diff --git a/lib/Cargo.lock b/lib/Cargo.lock index 766603e..6339064 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -5974,6 +5974,16 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "webpki" version = "0.22.4" diff --git a/lib/wasm/DEVELOPING.md b/lib/wasm/DEVELOPING.md new file mode 100644 index 0000000..bcc725e --- /dev/null +++ b/lib/wasm/DEVELOPING.md @@ -0,0 +1,33 @@ +# Building WASM + +## Prerequisites + +To build some dependencies you need to first install [emscripten](https://emscripten.org/docs/getting_started/downloads.html): +```bash +brew install emscripten +``` + +On first usage you will need to run: +```bash +make init +``` + +## Building + +```bash +make pack +``` + +This will generate the following artifacts: + +- `pkg/package.json` +- `pkg/breez_sdk_liquid_wasm_bg.wasm` +- `pkg/breez_sdk_liquid_wasm_bg.d.wasm` +- `pkg/breez_sdk_liquid_wasm.d.ts` +- `pkg/breez_sdk_liquid_wasm.js` + +## Testing + +```bash +make test +```