Merge bitcoindevkit/bdk#894: Better no-std support
7ab84be9c747fd73fc5d1bd0706e7027a66aadb5 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 7ab84be9c747fd73fc5d1bd0706e7027a66aadb5 Tree-SHA512: 217e0ebc04cd59898d4de1c4f8cc6c87de2561659e277cc6e0d969c8bc61142ca62c8bda86643d55676dce39da25891b516a901005a03a31404dae118a5fce76
This commit is contained in:
		
						commit
						5d1f922b3b
					
				
							
								
								
									
										32
									
								
								.github/workflows/cont_integration.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										32
									
								
								.github/workflows/cont_integration.yml
									
									
									
									
										vendored
									
									
								
							| @ -32,6 +32,34 @@ jobs: | |||||||
|       - name: Test |       - name: Test | ||||||
|         run: cargo test ${{ matrix.features }} |         run: cargo test ${{ matrix.features }} | ||||||
| 
 | 
 | ||||||
|  |   check-no-std: | ||||||
|  |     name: Check no_std | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     steps: | ||||||
|  |       - name: Checkout | ||||||
|  |         uses: actions/checkout@v2 | ||||||
|  |       - name: Install Rust toolchain | ||||||
|  |         uses: actions-rs/toolchain@v1 | ||||||
|  |         with: | ||||||
|  |           toolchain: stable | ||||||
|  |           override: true | ||||||
|  |           profile: minimal | ||||||
|  |           # target: "thumbv6m-none-eabi" | ||||||
|  |       - name: Rust Cache | ||||||
|  |         uses: Swatinem/rust-cache@v2.2.1 | ||||||
|  |       - name: Check bdk_chain | ||||||
|  |         working-directory: ./crates/chain | ||||||
|  |         # TODO "--target thumbv6m-none-eabi" should work but currently does not | ||||||
|  |         run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,hashbrown | ||||||
|  |       - name: Check bdk | ||||||
|  |         working-directory: ./crates/bdk | ||||||
|  |         # TODO "--target thumbv6m-none-eabi" should work but currently does not | ||||||
|  |         run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown | ||||||
|  |       - name: Check esplora | ||||||
|  |         working-directory: ./crates/esplora | ||||||
|  |         # TODO "--target thumbv6m-none-eabi" should work but currently does not | ||||||
|  |         run: cargo check --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown | ||||||
|  | 
 | ||||||
|   check-wasm: |   check-wasm: | ||||||
|     name: Check WASM |     name: Check WASM | ||||||
|     runs-on: ubuntu-20.04 |     runs-on: ubuntu-20.04 | ||||||
| @ -57,10 +85,10 @@ jobs: | |||||||
|         uses: Swatinem/rust-cache@v2.2.1 |         uses: Swatinem/rust-cache@v2.2.1 | ||||||
|       - name: Check bdk |       - name: Check bdk | ||||||
|         working-directory: ./crates/bdk |         working-directory: ./crates/bdk | ||||||
|         run: cargo check --target wasm32-unknown-unknown --features dev-getrandom-wasm |         run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,dev-getrandom-wasm | ||||||
|       - name: Check esplora |       - name: Check esplora | ||||||
|         working-directory: ./crates/esplora |         working-directory: ./crates/esplora | ||||||
|         run: cargo check --target wasm32-unknown-unknown --features async --no-default-features |         run: cargo check --target wasm32-unknown-unknown --no-default-features --features bitcoin/no-std,miniscript/no-std,bdk_chain/hashbrown,async | ||||||
| 
 | 
 | ||||||
|   fmt: |   fmt: | ||||||
|     name: Rust fmt |     name: Rust fmt | ||||||
|  | |||||||
| @ -15,11 +15,11 @@ rust-version = "1.57" | |||||||
| [dependencies] | [dependencies] | ||||||
| log = "=0.4.18" | log = "=0.4.18" | ||||||
| rand = "^0.8" | rand = "^0.8" | ||||||
| miniscript = { version = "9", features = ["serde"] } | miniscript = { version = "9", features = ["serde"], default-features = false } | ||||||
| bitcoin = { version = "0.29", features = ["serde", "base64", "rand"] } | bitcoin = { version = "0.29", features = ["serde", "base64", "rand"], default-features = false } | ||||||
| serde = { version = "^1.0", features = ["derive"] } | serde = { version = "^1.0", features = ["derive"] } | ||||||
| serde_json = { version = "^1.0" } | serde_json = { version = "^1.0" } | ||||||
| bdk_chain = { path = "../chain", version = "0.4.0", features = ["miniscript", "serde"] } | bdk_chain = { path = "../chain", version = "0.4.0", features = ["miniscript", "serde"], default-features = false } | ||||||
| 
 | 
 | ||||||
| # Optional dependencies | # Optional dependencies | ||||||
| hwi = { version = "0.5", optional = true, features = [ "use-miniscript"] } | hwi = { version = "0.5", optional = true, features = [ "use-miniscript"] } | ||||||
| @ -29,17 +29,15 @@ bip39 = { version = "1.0.1", optional = true } | |||||||
| getrandom = "0.2" | getrandom = "0.2" | ||||||
| js-sys = "0.3" | js-sys = "0.3" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| [features] | [features] | ||||||
| default = ["std"] | default = ["std"] | ||||||
| std = [] | std = ["bitcoin/std", "miniscript/std", "bdk_chain/std"] | ||||||
| compiler = ["miniscript/compiler"] | compiler = ["miniscript/compiler"] | ||||||
| all-keys = ["keys-bip39"] | all-keys = ["keys-bip39"] | ||||||
| keys-bip39 = ["bip39"] | keys-bip39 = ["bip39"] | ||||||
| hardware-signer = ["hwi"] | hardware-signer = ["hwi"] | ||||||
| test-hardware-signer = ["hardware-signer"] | test-hardware-signer = ["hardware-signer"] | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| # This feature is used to run `cargo check` in our CI targeting wasm. It's not recommended | # This feature is used to run `cargo check` in our CI targeting wasm. It's not recommended | ||||||
| # for libraries to explicitly include the "getrandom/js" feature, so we only do it when | # for libraries to explicitly include the "getrandom/js" feature, so we only do it when | ||||||
| # necessary for running our CI. See: https://docs.rs/getrandom/0.2.8/getrandom/#webassembly-support | # necessary for running our CI. See: https://docs.rs/getrandom/0.2.8/getrandom/#webassembly-support | ||||||
| @ -52,12 +50,10 @@ env_logger = "0.7" | |||||||
| base64 = "^0.13" | base64 = "^0.13" | ||||||
| assert_matches = "1.5.0" | assert_matches = "1.5.0" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| [package.metadata.docs.rs] | [package.metadata.docs.rs] | ||||||
| all-features = true | all-features = true | ||||||
| rustdoc-args = ["--cfg", "docsrs"] | rustdoc-args = ["--cfg", "docsrs"] | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| [[example]] | [[example]] | ||||||
| name = "mnemonic_to_descriptors" | name = "mnemonic_to_descriptors" | ||||||
| path = "examples/mnemonic_to_descriptors.rs" | path = "examples/mnemonic_to_descriptors.rs" | ||||||
|  | |||||||
| @ -11,6 +11,8 @@ | |||||||
| 
 | 
 | ||||||
| //! Descriptor errors
 | //! Descriptor errors
 | ||||||
| 
 | 
 | ||||||
|  | use core::fmt; | ||||||
|  | 
 | ||||||
| /// Errors related to the parsing and usage of descriptors
 | /// Errors related to the parsing and usage of descriptors
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub enum Error { | pub enum Error { | ||||||
| @ -51,8 +53,8 @@ impl From<crate::keys::KeyError> for Error { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Display for Error { | impl fmt::Display for Error { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|         match self { |         match self { | ||||||
|             Self::InvalidHdKeyPath => write!(f, "Invalid HD key path"), |             Self::InvalidHdKeyPath => write!(f, "Invalid HD key path"), | ||||||
|             Self::InvalidDescriptorChecksum => { |             Self::InvalidDescriptorChecksum => { | ||||||
|  | |||||||
| @ -107,8 +107,10 @@ impl fmt::Display for MiniscriptPsbtError { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[cfg(feature = "std")] | ||||||
| impl std::error::Error for MiniscriptPsbtError {} | impl std::error::Error for MiniscriptPsbtError {} | ||||||
| 
 | 
 | ||||||
|  | #[cfg(feature = "std")] | ||||||
| impl fmt::Display for Error { | impl fmt::Display for Error { | ||||||
|     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|         match self { |         match self { | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ use crate::collections::HashSet; | |||||||
| use alloc::string::{String, ToString}; | use alloc::string::{String, ToString}; | ||||||
| use alloc::vec::Vec; | use alloc::vec::Vec; | ||||||
| use core::any::TypeId; | use core::any::TypeId; | ||||||
|  | use core::fmt; | ||||||
| use core::marker::PhantomData; | use core::marker::PhantomData; | ||||||
| use core::ops::Deref; | use core::ops::Deref; | ||||||
| use core::str::FromStr; | use core::str::FromStr; | ||||||
| @ -934,8 +935,8 @@ pub enum KeyError { | |||||||
| impl_error!(miniscript::Error, Miniscript, KeyError); | impl_error!(miniscript::Error, Miniscript, KeyError); | ||||||
| impl_error!(bitcoin::util::bip32::Error, Bip32, KeyError); | impl_error!(bitcoin::util::bip32::Error, Bip32, KeyError); | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Display for KeyError { | impl fmt::Display for KeyError { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|         match self { |         match self { | ||||||
|             Self::InvalidScriptContext => write!(f, "Invalid script context"), |             Self::InvalidScriptContext => write!(f, "Invalid script context"), | ||||||
|             Self::InvalidNetwork => write!(f, "Invalid network"), |             Self::InvalidNetwork => write!(f, "Invalid network"), | ||||||
|  | |||||||
| @ -170,9 +170,9 @@ pub enum NewError<P> { | |||||||
|     Persist(P), |     Persist(P), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<P> core::fmt::Display for NewError<P> | impl<P> fmt::Display for NewError<P> | ||||||
| where | where | ||||||
|     P: core::fmt::Display, |     P: fmt::Display, | ||||||
| { | { | ||||||
|     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||||||
|         match self { |         match self { | ||||||
|  | |||||||
| @ -13,18 +13,18 @@ readme = "README.md" | |||||||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| bitcoin = { version = "0.29" } | bitcoin = { version = "0.29", default-features = false } | ||||||
| serde_crate = { package = "serde", version = "1", optional = true, features = ["derive"] } | serde_crate = { package = "serde", version = "1", optional = true, features = ["derive"] } | ||||||
| 
 | 
 | ||||||
| # Use hashbrown as a feature flag to have HashSet and HashMap from it. | # Use hashbrown as a feature flag to have HashSet and HashMap from it. | ||||||
| # note version 0.13 breaks outs MSRV. | # note version 0.13 breaks outs MSRV. | ||||||
| hashbrown = { version = "0.12", optional = true, features = ["serde"] } | hashbrown = { version = "0.12", optional = true, features = ["serde"] } | ||||||
| miniscript = { version = "9.0.0", optional = true  } | miniscript = { version = "9.0.0", optional = true, default-features = false } | ||||||
| 
 | 
 | ||||||
| [dev-dependencies] | [dev-dependencies] | ||||||
| rand = "0.8" | rand = "0.8" | ||||||
| 
 | 
 | ||||||
| [features] | [features] | ||||||
| default = ["std", "miniscript"] | default = ["std"] | ||||||
| std = [] | std = ["bitcoin/std"] | ||||||
| serde = ["serde_crate", "bitcoin/serde" ] | serde = ["serde_crate", "bitcoin/serde" ] | ||||||
|  | |||||||
| @ -12,13 +12,18 @@ readme = "README.md" | |||||||
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| bdk_chain = { path = "../chain", version = "0.4.0", features = ["serde", "miniscript"] } | bdk_chain = { path = "../chain", version = "0.4.0", default-features = false, features = ["serde", "miniscript"] } | ||||||
| esplora-client = { version = "0.5", default-features = false } | esplora-client = { version = "0.5", default-features = false } | ||||||
| async-trait = { version = "0.1.66", optional = true } | async-trait = { version = "0.1.66", optional = true } | ||||||
| futures = { version = "0.3.26", optional = true } | futures = { version = "0.3.26", optional = true } | ||||||
| 
 | 
 | ||||||
|  | # use these dependencies if you need to enable their /no-std features | ||||||
|  | bitcoin = { version = "0.29", optional = true, default-features = false } | ||||||
|  | miniscript = { version = "9.0.0", optional = true, default-features = false } | ||||||
|  | 
 | ||||||
| [features] | [features] | ||||||
| default = ["blocking"] | default = ["std", "async-https", "blocking"] | ||||||
|  | std = ["bdk_chain/std"] | ||||||
| async = ["async-trait", "futures", "esplora-client/async"] | async = ["async-trait", "futures", "esplora-client/async"] | ||||||
| async-https = ["async", "esplora-client/async-https"] | async-https = ["async", "esplora-client/async-https"] | ||||||
| blocking = ["esplora-client/blocking"] | blocking = ["esplora-client/blocking"] | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user