Skip to content

Commit b5f9177

Browse files
Merge #117: Update bdk cli for wasm
731dc74 Add wasm build in CI (Daniela Brozzoni) b3469b4 Add wasm support (Daniela Brozzoni) Pull request description: ### Description This PR adds a module to bdk-cli that exposes some structures/functions to WASM. You can see it in use here: bitcoindevkit/bitcoindevkit.org#118 ### Notes to the reviewers Based on #116 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [ ] I've added docs for the new feature * [x] I've updated `CHANGELOG.md` #### Bugfixes: * [ ] This pull request breaks the existing API * [ ] I've added tests to reproduce the issue which are now passing * [ ] I'm linking the issue being fixed by this PR ACKs for top commit: rajarshimaitra: ACK 731dc74 Tree-SHA512: 69011ab6cb421f7e6f7dd000f9eaf5581428b2288358e31ffaec4425996951443fa2fc79f99db7de9c030d6a3fda57d25eee11564cf2fab9c745da593324f763
2 parents 183e85e + 731dc74 commit b5f9177

File tree

7 files changed

+300
-22
lines changed

7 files changed

+300
-22
lines changed

.github/workflows/cont_integration.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,41 @@ jobs:
5555
- name: Test
5656
run: cargo test --no-default-features --features repl,${{ matrix.features }}
5757

58+
wasm-build:
59+
name: Build WASM
60+
runs-on: ubuntu-latest
61+
env:
62+
CC: clang-10
63+
CFLAGS: -I/usr/include
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v2
67+
- name: Generate cache key
68+
run: echo "Build WASM" | tee .cache_key
69+
- name: Cache
70+
uses: actions/cache@v2
71+
with:
72+
path: |
73+
~/.cargo/registry
74+
~/.cargo/git
75+
target
76+
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
77+
# Install a recent version of clang that supports wasm32
78+
- run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - || exit 1
79+
- run: sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main" || exit 1
80+
- run: sudo apt-get update || exit 1
81+
- run: sudo apt-get install -y libclang-common-10-dev clang-10 libc6-dev-i386 || exit 1
82+
- name: Set default toolchain
83+
run: rustup default 1.56.1 # MSRV
84+
- name: Set profile
85+
run: rustup set profile minimal
86+
- name: Add target wasm32
87+
run: rustup target add wasm32-unknown-unknown
88+
- name: Update toolchain
89+
run: rustup update
90+
- name: Build
91+
run: cargo build --target wasm32-unknown-unknown --no-default-features --features esplora-reqwest,async-interface,compiler
92+
5893
fmt:
5994
name: Rust fmt
6095
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Add new `bdk-cli node <command> [<args>]` to control the backend node deployed by `regtest-*` features.
1717
- Add an integration testing framework in `src/tests/integration.rs`. This framework uses the `regtest-*` feature to run automated testing with bdk-cli.
1818
- Add possible values for `network` option to improve help message, and fix typo in doc.
19+
- Add a module `wasm` containing objects to use bdk-cli from web assembly
1920

2021
## [0.5.0]
2122

Cargo.lock

Lines changed: 38 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ fd-lock = { version = "=3.0.2", optional = true }
2727
regex = { version = "1", optional = true }
2828
bdk-reserves = { version = "0.22", optional = true }
2929
electrsd = { version= "0.19", features = ["bitcoind_22_0"], optional = true}
30-
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"], optional = true }
30+
31+
# Platform-specific dependencies
32+
[target.'cfg(target_arch = "wasm32")'.dependencies]
33+
wasm-bindgen = { version = "=0.2.79", features = ["serde-serialize"] }
34+
wasm-bindgen-futures = { version = "0.4" }
35+
js-sys = "=0.3.56"
36+
wasm-logger = "0.2.0"
37+
secp256k1 = { version = "0.22.0", default-features = false }
38+
rand = { version = "^0.6", features = ["wasm-bindgen"] }
39+
serde = { version = "^1.0", features = ["derive"] }
40+
regex = { version = "1" }
41+
42+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
43+
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
3144

3245
[features]
3346
default = ["repl", "sqlite-db"]
@@ -45,7 +58,7 @@ electrum = ["bdk/electrum"]
4558
compact_filters = ["bdk/compact_filters"]
4659
esplora = []
4760
esplora-ureq = ["esplora", "bdk/use-esplora-ureq"]
48-
async-interface = ["bdk/async-interface", "tokio"]
61+
async-interface = ["bdk/async-interface"]
4962
esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest", "bdk/reqwest-default-tls", "async-interface"]
5063

5164
# Use this to consensus verify transactions at sync time
@@ -68,4 +81,4 @@ regtest-bitcoin = ["regtest-node" , "rpc"]
6881
regtest-electrum = ["regtest-node", "electrum", "electrsd/electrs_0_8_10"]
6982
#TODO: Check why esplora in electrsd isn't working.
7083
#regtest-esplora-ureq = ["regtest-node", "esplora-ureq", "electrsd/esplora_a33e97e1"]
71-
#regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
84+
#regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ pub enum KeySubCommand {
568568
}
569569

570570
/// Subcommands available in REPL mode.
571-
#[cfg(feature = "repl")]
571+
#[cfg(any(feature = "repl", target_arch = "wasm32"))]
572572
#[derive(Debug, StructOpt, Clone, PartialEq)]
573573
#[structopt(global_settings =&[AppSettings::NoBinaryName], rename_all = "lower")]
574574
pub enum ReplSubCommand {

src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ mod commands;
1414
mod handlers;
1515
mod nodes;
1616
mod utils;
17+
#[cfg(target_arch = "wasm32")]
18+
mod wasm;
19+
1720
use bitcoin::Network;
1821

1922
use log::{debug, error, warn};
@@ -24,10 +27,11 @@ use bdk::{bitcoin, Error};
2427
use bdk_macros::{maybe_async, maybe_await};
2528
use structopt::StructOpt;
2629

27-
#[cfg(feature = "repl")]
30+
#[cfg(any(feature = "repl", target_arch = "wasm32"))]
2831
const REPL_LINE_SPLIT_REGEX: &str = r#""([^"]*)"|'([^']*)'|([\w\-]+)"#;
2932

3033
#[maybe_async]
34+
#[cfg(not(target_arch = "wasm32"))]
3135
#[cfg_attr(feature = "async-interface", tokio::main)]
3236
fn main() {
3337
env_logger::init();
@@ -50,3 +54,7 @@ fn main() {
5054
},
5155
}
5256
}
57+
58+
// wasm32 requires a non-async main
59+
#[cfg(target_arch = "wasm32")]
60+
fn main() {}

0 commit comments

Comments
 (0)