diff --git a/README.md b/README.md index c2612010..26ab1069 100644 --- a/README.md +++ b/README.md @@ -77,12 +77,16 @@ For more information please see `./CONTRIBUTING.md`. This library should always compile with any combination of features on **Rust 1.48.0**. -To build with the MSRV you will need to pin some dependencies: +To build with the MSRV you will need to pin `serde` (if you have the feature enabled) + ``` +# serde 1.0.157 uses syn 2.0 which requires edition 2021 cargo update -p serde --precise 1.0.156 -cargo update -p syn --precise 1.0.107 ``` +before building. (And if your code is a library, your downstream users will need to run these +commands, and so on.) + ## Installing Rust Rust can be installed using your package manager of choice or diff --git a/bitcoin/contrib/test.sh b/bitcoin/contrib/test.sh index b5dacb67..07c3b1e1 100755 --- a/bitcoin/contrib/test.sh +++ b/bitcoin/contrib/test.sh @@ -27,8 +27,6 @@ fi if cargo --version | grep "1\.48"; then # 1.0.157 uses syn 2.0 which requires edition 2018 cargo update -p serde --precise 1.0.156 - # 1.0.108 uses `matches!` macro so does not work with Rust 1.41.1, bad `syn` no biscuit. - cargo update -p syn --precise 1.0.107 fi # We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml index be318b2d..c96cc7a8 100644 --- a/hashes/Cargo.toml +++ b/hashes/Cargo.toml @@ -16,7 +16,6 @@ exclude = ["tests", "contrib"] default = ["std"] std = ["alloc", "internals/std"] alloc = ["internals/alloc"] -schemars = ["actual-schemars", "dyn-clone"] serde-std = ["serde/std"] [package.metadata.docs.rs] @@ -27,13 +26,9 @@ rustdoc-args = ["--cfg", "docsrs"] internals = { path = "../internals", package = "bitcoin-private", version = "0.1.0" } core2 = { version = "0.3.0", default_features = false, optional = true } +schemars = { version = "0.8.3", optional = true } # Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std". serde = { version = "1.0", default-features = false, optional = true } -# Do NOT use this as a feature! Use the `schemars` feature instead. Can only be used with "std" enabled. -actual-schemars = { package = "schemars", version = "<=0.8.3", optional = true } -# Do NOT enable this dependency, this is just to pin dyn-clone (transitive dep from schemars) -# because 1.0.8 does not build with Rust 1.41.1 (because of useage of `Arc::as_ptr`). -dyn-clone = { version = "<=1.0.7", default_features = false, optional = true } [dev-dependencies] serde_test = "1.0" diff --git a/hashes/README.md b/hashes/README.md index 9cd6f8fd..786ea77a 100644 --- a/hashes/README.md +++ b/hashes/README.md @@ -13,6 +13,18 @@ since these are needed to display hashes anway. This library should always compile with any combination of features on **Rust 1.48.0**. + +To build with the MSRV you will need to pin `serde` (if you have either the `serde` or the +`schemars` feature enabled) + +``` +# serde 1.0.157 uses syn 2.0 which requires edition 2021 +cargo update -p serde --precise 1.0.156 +``` + +before building. (And if your code is a library, your downstream users will need to run these +commands, and so on.) + ## Contributions Contributions are welcome, including additional hash function implementations. diff --git a/hashes/contrib/test.sh b/hashes/contrib/test.sh index 466644a0..b934976d 100755 --- a/hashes/contrib/test.sh +++ b/hashes/contrib/test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash set -ex @@ -17,6 +17,12 @@ if cargo --version | grep nightly >/dev/null; then NIGHTLY=true fi +# Pin dependencies as required if we are using MSRV toolchain. +if cargo --version | grep "1\.48"; then + # 1.0.157 uses syn 2.0 which requires edition 2021 + cargo update -p serde --precise 1.0.156 +fi + # Make all cargo invocations verbose export CARGO_TERM_VERBOSE=true @@ -52,8 +58,12 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then cargo test --no-default-features --features="std,schemars" fi +REPO_DIR=$(git rev-parse --show-toplevel) + if [ "$DO_SCHEMARS_TESTS" = true ]; then - (cd extended_tests/schemars && cargo test) + pushd "$REPO_DIR/hashes/extended_tests/schemars" > /dev/null + cargo test + popd > /dev/null fi # Build the docs if told to (this only works with the nightly toolchain) diff --git a/hashes/extended_tests/schemars/Cargo.toml b/hashes/extended_tests/schemars/Cargo.toml index 35900f75..2a58bce1 100644 --- a/hashes/extended_tests/schemars/Cargo.toml +++ b/hashes/extended_tests/schemars/Cargo.toml @@ -13,8 +13,8 @@ path = "../.." features = ['schemars', 'serde'] [dependencies] -jsonschema-valid = "^0.4.0" +jsonschema-valid = "0.4.0" serde = { version = "1.0", default-features = false} -schemars = { version = "<=0.8.3"} +schemars = "0.8.3" serde_test = "1.0" serde_json = "1.0" diff --git a/hashes/extended_tests/schemars/README.md b/hashes/extended_tests/schemars/README.md new file mode 100644 index 00000000..d8ff3278 --- /dev/null +++ b/hashes/extended_tests/schemars/README.md @@ -0,0 +1,10 @@ +# Test crate for the schemars feature + +Run as usual with `cargo test`. + +## Minimum Supported Rust Version (MSRV) + +To run the tests with the MSRV you will need to pin some dependencies: + +- `cargo update -p serde --precise 1.0.156` +- `cargo update -p syn --precise 1.0.107` diff --git a/hashes/src/lib.rs b/hashes/src/lib.rs index 3bfb18c0..4cc74cb1 100644 --- a/hashes/src/lib.rs +++ b/hashes/src/lib.rs @@ -113,7 +113,7 @@ pub mod _export { } #[cfg(feature = "schemars")] -extern crate actual_schemars as schemars; +extern crate schemars; mod internal_macros; #[macro_use] diff --git a/hashes/src/sha256t.rs b/hashes/src/sha256t.rs index 469a3816..3c7e83a0 100644 --- a/hashes/src/sha256t.rs +++ b/hashes/src/sha256t.rs @@ -31,16 +31,17 @@ pub trait Tag { } /// Output of the SHA256t hash function. -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[repr(transparent)] -pub struct Hash( - #[cfg_attr( - feature = "schemars", - schemars(schema_with = "crate::util::json_hex_string::len_32") - )] - [u8; 32], - #[cfg_attr(feature = "schemars", schemars(skip))] PhantomData, -); +pub struct Hash([u8; 32], PhantomData); + +#[cfg(feature = "schemars")] +impl schemars::JsonSchema for Hash { + fn schema_name() -> String { "Hash".to_owned() } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + crate::util::json_hex_string::len_32(gen) + } +} impl Hash { fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, Default::default()) }