Add a workspace to the top level directory.

Create a directory `bitcoin` and move into it the following as is with
no code changes:

- src
- Cargo.toml
- contrib
- test_data
- examples

Then do:

- Add a workspace to the repository root directory.
- Add the newly created `bitcoin` crate to the workspace.
- Exclude `fuzz` and `embedded` crates from the workspace.
- Add a contrib/test.sh script that runs contrib/test.sh in each
  sub-crate
- Fix the bitcoin/contrib/test.sh script
This commit is contained in:
Tobin C. Harding 2022-09-08 09:32:08 +10:00
parent a59e0544ec
commit 022730bd8d
76 changed files with 205 additions and 184 deletions

View File

@ -1,62 +1,3 @@
[package] [workspace]
name = "bitcoin" members = ["bitcoin"]
version = "0.29.0" exclude = ["embedded", "fuzz"]
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"
repository = "https://github.com/rust-bitcoin/rust-bitcoin/"
documentation = "https://docs.rs/bitcoin/"
description = "General purpose library for using and interoperating with Bitcoin and other cryptocurrencies."
keywords = [ "crypto", "bitcoin" ]
readme = "README.md"
exclude = ["./test_data"]
edition = "2018"
# Please don't forget to add relevant features to docs.rs below
[features]
default = [ "std", "secp-recovery" ]
rand = ["secp256k1/rand-std"]
serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"]
secp-lowmemory = ["secp256k1/lowmemory"]
secp-recovery = ["secp256k1/recovery"]
# At least one of std, no-std must be enabled.
#
# The no-std feature doesn't disable std - you need to turn off the std feature for that by disabling default.
# Instead no-std enables additional features required for this crate to be usable without std.
# As a result, both can be enabled without conflict.
std = ["secp256k1/std", "bitcoin_hashes/std", "bech32/std"]
no-std = ["hashbrown", "core2/alloc", "bitcoin_hashes/alloc", "secp256k1/alloc"]
[package.metadata.docs.rs]
features = [ "std", "secp-recovery", "base64", "rand", "serde", "bitcoinconsensus" ]
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
bech32 = { version = "0.9.0", default-features = false }
bitcoin_hashes = { version = "0.11.0", default-features = false }
secp256k1 = { version = "0.24.0", default-features = false, features = ["bitcoin_hashes"] }
core2 = { version = "0.3.0", optional = true, default-features = false }
base64 = { version = "0.13.0", optional = true }
bitcoinconsensus = { version = "0.20.2-0.5.0", optional = true }
# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true }
hashbrown = { version = "0.8", optional = true }
[dev-dependencies]
serde_json = "<1.0.45"
serde_test = "1"
secp256k1 = { version = "0.24.0", features = [ "recovery", "rand-std" ] }
bincode = "1.3.1"
[[example]]
name = "bip32"
[[example]]
name = "handshake"
required-features = ["std"]
[[example]]
name = "ecdsa-psbt"
required-features = ["std", "bitcoinconsensus"]

62
bitcoin/Cargo.toml Normal file
View File

@ -0,0 +1,62 @@
[package]
name = "bitcoin"
version = "0.29.0"
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-bitcoin/"
repository = "https://github.com/rust-bitcoin/rust-bitcoin/"
documentation = "https://docs.rs/bitcoin/"
description = "General purpose library for using and interoperating with Bitcoin and other cryptocurrencies."
keywords = [ "crypto", "bitcoin" ]
readme = "README.md"
exclude = ["./test_data"]
edition = "2018"
# Please don't forget to add relevant features to docs.rs below
[features]
default = [ "std", "secp-recovery" ]
rand = ["secp256k1/rand-std"]
serde = ["actual-serde", "bitcoin_hashes/serde", "secp256k1/serde"]
secp-lowmemory = ["secp256k1/lowmemory"]
secp-recovery = ["secp256k1/recovery"]
# At least one of std, no-std must be enabled.
#
# The no-std feature doesn't disable std - you need to turn off the std feature for that by disabling default.
# Instead no-std enables additional features required for this crate to be usable without std.
# As a result, both can be enabled without conflict.
std = ["secp256k1/std", "bitcoin_hashes/std", "bech32/std"]
no-std = ["hashbrown", "core2/alloc", "bitcoin_hashes/alloc", "secp256k1/alloc"]
[package.metadata.docs.rs]
features = [ "std", "secp-recovery", "base64", "rand", "serde", "bitcoinconsensus" ]
rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
bech32 = { version = "0.9.0", default-features = false }
bitcoin_hashes = { version = "0.11.0", default-features = false }
secp256k1 = { version = "0.24.0", default-features = false, features = ["bitcoin_hashes"] }
core2 = { version = "0.3.0", optional = true, default-features = false }
base64 = { version = "0.13.0", optional = true }
bitcoinconsensus = { version = "0.20.2-0.5.0", optional = true }
# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1", default-features = false, features = [ "derive", "alloc" ], optional = true }
hashbrown = { version = "0.8", optional = true }
[dev-dependencies]
serde_json = "<1.0.45"
serde_test = "1"
secp256k1 = { version = "0.24.0", features = [ "recovery", "rand-std" ] }
bincode = "1.3.1"
[[example]]
name = "bip32"
[[example]]
name = "handshake"
required-features = ["std"]
[[example]]
name = "ecdsa-psbt"
required-features = ["std", "bitcoinconsensus"]

127
bitcoin/contrib/test.sh Executable file
View File

@ -0,0 +1,127 @@
#!/bin/sh
set -ex
FEATURES="base64 bitcoinconsensus serde rand secp-recovery"
if [ "$DO_COV" = true ]
then
export RUSTFLAGS="-C link-dead-code"
fi
cargo --version
rustc --version
# Work out if we are using a nightly toolchain.
NIGHTLY=false
if cargo --version | grep nightly; then
NIGHTLY=true
fi
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies
# in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp).
cargo update -p serde --precise 1.0.142
cargo update -p serde_test --precise 1.0.142
cargo update -p serde_derive --precise 1.0.142
duplicate_dependencies=$(cargo tree --target=all --all-features --duplicates | wc -l)
if [ "$duplicate_dependencies" -ne 0 ]; then
echo "Dependency tree is broken, contains duplicates"
cargo tree --target=all --all-features --duplicates
exit 1
fi
if [ "$DO_LINT" = true ]
then
cargo clippy --all-features --all-targets -- -D warnings
cargo clippy --example bip32 -- -D warnings
cargo clippy --example handshake -- -D warnings
cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
fi
echo "********* Testing std *************"
# Test without any features other than std first
cargo test --verbose --no-default-features --features="std"
echo "********* Testing default *************"
# Then test with the default features
cargo test --verbose
if [ "$DO_NO_STD" = true ]
then
echo "********* Testing no-std build *************"
# Build no_std, to make sure that cfg(test) doesn't hide any issues
cargo build --verbose --features="no-std" --no-default-features
# Build std + no_std, to make sure they are not incompatible
cargo build --verbose --features="no-std"
# Test no_std
cargo test --verbose --features="no-std" --no-default-features
# Build all features
cargo build --verbose --features="no-std $FEATURES" --no-default-features
# Build specific features
for feature in ${FEATURES}
do
cargo build --verbose --features="no-std $feature"
done
cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
cargo run --no-default-features --features no-std --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
fi
# Test each feature
for feature in ${FEATURES}
do
echo "********* Testing $feature *************"
cargo test --verbose --features="$feature"
done
cargo run --example ecdsa-psbt --features=bitcoinconsensus
# Build the docs if told to (this only works with the nightly toolchain)
if [ "$DO_DOCS" = true ]; then
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links
fi
# Fuzz if told to
if [ "$DO_FUZZ" = true ]
then
(
cd fuzz
cargo test --verbose
./travis-fuzz.sh
)
fi
# Bench if told to, only works with non-stable toolchain (nightly, beta).
if [ "$DO_BENCH" = true ]
then
if [ "$NIGHTLY" = false ]
then
if [ -n "$RUSTUP_TOOLCHAIN" ]
then
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
else
echo "DO_BENCH requires a nightly toolchain"
fi
exit 1
fi
RUSTFLAGS='--cfg=bench' cargo bench
fi
# Use as dependency if told to
if [ "$AS_DEPENDENCY" = true ]
then
cargo new dep_test 2> /dev/null # Mute warning about workspace, fixed below.
cd dep_test
echo 'bitcoin = { path = "..", features = ["serde"] }\n\n' >> Cargo.toml
# Adding an empty workspace section excludes this crate from the rust-bitcoin workspace.
echo '[workspace]\n\n' >> Cargo.toml
cargo update -p serde --precise 1.0.142
cargo update -p serde_derive --precise 1.0.142
cargo test --verbose
fi

View File

@ -2,123 +2,14 @@
set -ex set -ex
FEATURES="base64 bitcoinconsensus serde rand secp-recovery" CRATES="bitcoin"
if [ "$DO_COV" = true ] for crate in ${CRATES}
then
export RUSTFLAGS="-C link-dead-code"
fi
cargo --version
rustc --version
# Work out if we are using a nightly toolchain.
NIGHTLY=false
if cargo --version | grep nightly; then
NIGHTLY=true
fi
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies
# in one crate and not in another (e.g. upgrade bitcoin_hashes in bitcoin but not in secp).
cargo update -p serde --precise 1.0.142
cargo update -p serde_test --precise 1.0.142
cargo update -p serde_derive --precise 1.0.142
duplicate_dependencies=$(cargo tree --target=all --all-features --duplicates | wc -l)
if [ "$duplicate_dependencies" -ne 0 ]; then
echo "Dependency tree is broken, contains duplicates"
cargo tree --target=all --all-features --duplicates
exit 1
fi
if [ "$DO_LINT" = true ]
then
cargo clippy --all-features --all-targets -- -D warnings
cargo clippy --example bip32 -- -D warnings
cargo clippy --example handshake -- -D warnings
cargo clippy --example ecdsa-psbt --features=bitcoinconsensus -- -D warnings
fi
echo "********* Testing std *************"
# Test without any features other than std first
cargo test --verbose --no-default-features --features="std"
echo "********* Testing default *************"
# Then test with the default features
cargo test --verbose
if [ "$DO_NO_STD" = true ]
then
echo "********* Testing no-std build *************"
# Build no_std, to make sure that cfg(test) doesn't hide any issues
cargo build --verbose --features="no-std" --no-default-features
# Build std + no_std, to make sure they are not incompatible
cargo build --verbose --features="no-std"
# Test no_std
cargo test --verbose --features="no-std" --no-default-features
# Build all features
cargo build --verbose --features="no-std $FEATURES" --no-default-features
# Build specific features
for feature in ${FEATURES}
do do
cargo build --verbose --features="no-std $feature"
done
cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
cargo run --no-default-features --features no-std --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
fi
# Test each feature
for feature in ${FEATURES}
do
echo "********* Testing $feature *************"
cargo test --verbose --features="$feature"
done
cargo run --example ecdsa-psbt --features=bitcoinconsensus
# Build the docs if told to (this only works with the nightly toolchain)
if [ "$DO_DOCS" = true ]; then
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly rustdoc --features="$FEATURES" -- -D rustdoc::broken-intra-doc-links
fi
# Fuzz if told to
if [ "$DO_FUZZ" = true ]
then
( (
cd fuzz cd "$crate"
cargo test --verbose ./contrib/test.sh
./travis-fuzz.sh
) )
fi done
# Bench if told to, only works with non-stable toolchain (nightly, beta). exit 0
if [ "$DO_BENCH" = true ]
then
if [ "$NIGHTLY" = false ]
then
if [ -n "$RUSTUP_TOOLCHAIN" ]
then
echo "RUSTUP_TOOLCHAIN is set to a non-nightly toolchain but DO_BENCH requires a nightly toolchain"
else
echo "DO_BENCH requires a nightly toolchain"
fi
exit 1
fi
RUSTFLAGS='--cfg=bench' cargo bench
fi
# Use as dependency if told to
if [ "$AS_DEPENDENCY" = true ]
then
cargo new dep_test
cd dep_test
echo 'bitcoin = { path = "..", features = ["serde"] }' >> Cargo.toml
cargo update -p serde --precise 1.0.142
cargo update -p serde_derive --precise 1.0.142
cargo test --verbose
fi

View File

@ -11,7 +11,7 @@ cortex-m-rt = "0.6.10"
cortex-m-semihosting = "0.3.3" cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0" panic-halt = "0.2.0"
alloc-cortex-m = "0.4.1" alloc-cortex-m = "0.4.1"
bitcoin = { path="../", default-features = false, features = ["no-std", "secp-lowmemory"] } bitcoin = { path="../bitcoin", default-features = false, features = ["no-std", "secp-lowmemory"] }
[[bin]] [[bin]]
name = "embedded" name = "embedded"

View File

@ -14,7 +14,7 @@ honggfuzz_fuzz = ["honggfuzz"]
[dependencies] [dependencies]
honggfuzz = { version = "0.5", optional = true, default-features = false } honggfuzz = { version = "0.5", optional = true, default-features = false }
afl = { version = "0.4", optional = true } afl = { version = "0.4", optional = true }
bitcoin = { path = ".." } bitcoin = { path = "../bitcoin" }
# Prevent this from interfering with workspaces # Prevent this from interfering with workspaces
[workspace] [workspace]

View File

@ -1,9 +1,9 @@
# Eventually this shoud be: ignore = [] # Eventually this shoud be: ignore = []
ignore = [ ignore = [
"src/blockdata", "bitcoin/src/blockdata",
"src/consensus", "bitcoin/src/consensus",
"src/network", "bitcoin/src/network",
"src/util", "bitcoin/src/util",
] ]
hard_tabs = false hard_tabs = false