Skip to content

Commit 5d1f922

Browse files
committed
Merge #894: Better no-std support
7ab84be Better no-std support (Steve Myers) Pull request description: This replaces #893 ### Description Carrying over relevant maintenance changes from release 0.27.2 to bdk `master`. - Use `default-features = false` for `miniscript` and `bitcoin` - Introduce `std` features for `bdk`, `bdk_chain` and `bdk_esplora` ### Notes to the reviewers The `default-features = false`for `bitcoin` and `miniscript` is to let `bdk` be unbiased for things like no-std. ### Changelog notice - Set default-features = false for rust-bitcoin and rust-miniscript #894 - Introduce `std` features for `bdk`, `bdk_chain` and `bdk_esplora` ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK 7ab84be Tree-SHA512: 217e0ebc04cd59898d4de1c4f8cc6c87de2561659e277cc6e0d969c8bc61142ca62c8bda86643d55676dce39da25891b516a901005a03a31404dae118a5fce76
2 parents b184e35 + 7ab84be commit 5d1f922

File tree

8 files changed

+57
-23
lines changed

8 files changed

+57
-23
lines changed

.github/workflows/cont_integration.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ jobs:
3232
- name: Test
3333
run: cargo test ${{ matrix.features }}
3434

35+
check-no-std:
36+
name: Check no_std
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v2
41+
- name: Install Rust toolchain
42+
uses: actions-rs/toolchain@v1
43+
with:
44+
toolchain: stable
45+
override: true
46+
profile: minimal
47+
# target: "thumbv6m-none-eabi"
48+
- name: Rust Cache
49+
uses: Swatinem/[email protected]
50+
- name: Check bdk_chain
51+
working-directory: ./crates/chain
52+
# TODO "--target thumbv6m-none-eabi" should work but currently does not
53+
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,hashbrown
54+
- name: Check bdk
55+
working-directory: ./crates/bdk
56+
# TODO "--target thumbv6m-none-eabi" should work but currently does not
57+
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown
58+
- name: Check esplora
59+
working-directory: ./crates/esplora
60+
# TODO "--target thumbv6m-none-eabi" should work but currently does not
61+
run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown
62+
3563
check-wasm:
3664
name: Check WASM
3765
runs-on: ubuntu-20.04
@@ -57,10 +85,10 @@ jobs:
5785
uses: Swatinem/[email protected]
5886
- name: Check bdk
5987
working-directory: ./crates/bdk
60-
run: cargo check --target wasm32-unknown-unknown --features dev-getrandom-wasm
88+
run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm
6189
- name: Check esplora
6290
working-directory: ./crates/esplora
63-
run: cargo check --target wasm32-unknown-unknown --features async --no-default-features
91+
run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async
6492

6593
fmt:
6694
name: Rust fmt

crates/bdk/Cargo.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ rust-version = "1.57"
1515
[dependencies]
1616
log = "=0.4.18"
1717
rand = "^0.8"
18-
miniscript = { version = "9", features = ["serde"] }
19-
bitcoin = { version = "0.29", features = ["serde", "base64", "rand"] }
18+
miniscript = { version = "9", features = ["serde"], default-features = false }
19+
bitcoin = { version = "0.29", features = ["serde", "base64", "rand"], default-features = false }
2020
serde = { version = "^1.0", features = ["derive"] }
2121
serde_json = { version = "^1.0" }
22-
bdk_chain = { path = "../chain", version = "0.4.0", features = ["miniscript", "serde"] }
22+
bdk_chain = { path = "../chain", version = "0.4.0", features = ["miniscript", "serde"], default-features = false }
2323

2424
# Optional dependencies
2525
hwi = { version = "0.5", optional = true, features = [ "use-miniscript"] }
@@ -29,17 +29,15 @@ bip39 = { version = "1.0.1", optional = true }
2929
getrandom = "0.2"
3030
js-sys = "0.3"
3131

32-
3332
[features]
3433
default = ["std"]
35-
std = []
34+
std = ["bitcoin/std", "miniscript/std", "bdk_chain/std"]
3635
compiler = ["miniscript/compiler"]
3736
all-keys = ["keys-bip39"]
3837
keys-bip39 = ["bip39"]
3938
hardware-signer = ["hwi"]
4039
test-hardware-signer = ["hardware-signer"]
4140

42-
4341
# This feature is used to run `cargo check` in our CI targeting wasm. It's not recommended
4442
# for libraries to explicitly include the "getrandom/js" feature, so we only do it when
4543
# necessary for running our CI. See: https://docs.rs/getrandom/0.2.8/getrandom/#webassembly-support
@@ -52,12 +50,10 @@ env_logger = "0.7"
5250
base64 = "^0.13"
5351
assert_matches = "1.5.0"
5452

55-
5653
[package.metadata.docs.rs]
5754
all-features = true
5855
rustdoc-args = ["--cfg", "docsrs"]
5956

60-
6157
[[example]]
6258
name = "mnemonic_to_descriptors"
6359
path = "examples/mnemonic_to_descriptors.rs"

crates/bdk/src/descriptor/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
//! Descriptor errors
1313
14+
use core::fmt;
15+
1416
/// Errors related to the parsing and usage of descriptors
1517
#[derive(Debug)]
1618
pub enum Error {
@@ -51,8 +53,8 @@ impl From<crate::keys::KeyError> for Error {
5153
}
5254
}
5355

54-
impl std::fmt::Display for Error {
55-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56+
impl fmt::Display for Error {
57+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5658
match self {
5759
Self::InvalidHdKeyPath => write!(f, "Invalid HD key path"),
5860
Self::InvalidDescriptorChecksum => {

crates/bdk/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ impl fmt::Display for MiniscriptPsbtError {
107107
}
108108
}
109109

110+
#[cfg(feature = "std")]
110111
impl std::error::Error for MiniscriptPsbtError {}
111112

113+
#[cfg(feature = "std")]
112114
impl fmt::Display for Error {
113115
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114116
match self {

crates/bdk/src/keys/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::collections::HashSet;
1515
use alloc::string::{String, ToString};
1616
use alloc::vec::Vec;
1717
use core::any::TypeId;
18+
use core::fmt;
1819
use core::marker::PhantomData;
1920
use core::ops::Deref;
2021
use core::str::FromStr;
@@ -934,8 +935,8 @@ pub enum KeyError {
934935
impl_error!(miniscript::Error, Miniscript, KeyError);
935936
impl_error!(bitcoin::util::bip32::Error, Bip32, KeyError);
936937

937-
impl std::fmt::Display for KeyError {
938-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
938+
impl fmt::Display for KeyError {
939+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
939940
match self {
940941
Self::InvalidScriptContext => write!(f, "Invalid script context"),
941942
Self::InvalidNetwork => write!(f, "Invalid network"),

crates/bdk/src/wallet/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ pub enum NewError<P> {
170170
Persist(P),
171171
}
172172

173-
impl<P> core::fmt::Display for NewError<P>
173+
impl<P> fmt::Display for NewError<P>
174174
where
175-
P: core::fmt::Display,
175+
P: fmt::Display,
176176
{
177177
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
178178
match self {

crates/chain/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ readme = "README.md"
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
bitcoin = { version = "0.29" }
16+
bitcoin = { version = "0.29", default-features = false }
1717
serde_crate = { package = "serde", version = "1", optional = true, features = ["derive"] }
1818

1919
# Use hashbrown as a feature flag to have HashSet and HashMap from it.
2020
# note version 0.13 breaks outs MSRV.
21-
hashbrown = { version = "0.12", optional = true, features = ["serde"] }
22-
miniscript = { version = "9.0.0", optional = true }
21+
hashbrown = { version = "0.12", optional = true, features = ["serde"] }
22+
miniscript = { version = "9.0.0", optional = true, default-features = false }
2323

2424
[dev-dependencies]
2525
rand = "0.8"
2626

2727
[features]
28-
default = ["std", "miniscript"]
29-
std = []
28+
default = ["std"]
29+
std = ["bitcoin/std"]
3030
serde = ["serde_crate", "bitcoin/serde" ]

crates/esplora/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ readme = "README.md"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies]
15-
bdk_chain = { path = "../chain", version = "0.4.0", features = ["serde", "miniscript"] }
15+
bdk_chain = { path = "../chain", version = "0.4.0", default-features = false, features = ["serde", "miniscript"] }
1616
esplora-client = { version = "0.5", default-features = false }
1717
async-trait = { version = "0.1.66", optional = true }
1818
futures = { version = "0.3.26", optional = true }
1919

20+
# use these dependencies if you need to enable their /no-std features
21+
bitcoin = { version = "0.29", optional = true, default-features = false }
22+
miniscript = { version = "9.0.0", optional = true, default-features = false }
23+
2024
[features]
21-
default = ["blocking"]
25+
default = ["std", "async-https", "blocking"]
26+
std = ["bdk_chain/std"]
2227
async = ["async-trait", "futures", "esplora-client/async"]
2328
async-https = ["async", "esplora-client/async-https"]
2429
blocking = ["esplora-client/blocking"]

0 commit comments

Comments
 (0)