From 6c61e1019efa4f4719026980b9506ff79eafc552 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 7 Mar 2023 09:39:20 +1100 Subject: [PATCH] Fix pinning (schemars and MSRV) Done as is single patch to make sure all the docs and CI are in sync and correct. We currently pin the `schemars` dependency using `<=0.8.3` as well as a the `dyn-clone` transient dependency in the manifest (`hashes` and the extended test crate). This is incorrect because it makes usage of the crate klunky (or possibly impossible) if downstream users wish to use a later version of `schemars`. Observe also that we do not have to pin `schemars`, we do however have to pin the `serde` crate if either `serde` or `schemars` features are enabled. Do so in CI and document in the readme file within hashes. Currently we have a pin remaining from the old MSRV (`syn` due to use of `matches!`). Fix pinning by: - Remove pin in manifest for `schemars` - Fix pinning for MSRV in CI and docs (this includes documenting pinning requirements for `schemars` feature because it is related to the other pin of `serde`) in both `hashes` readme and main repo readme. --- README.md | 8 ++++++-- bitcoin/contrib/test.sh | 2 -- hashes/Cargo.toml | 7 +------ hashes/README.md | 12 ++++++++++++ hashes/contrib/test.sh | 14 ++++++++++++-- hashes/extended_tests/schemars/Cargo.toml | 4 ++-- hashes/extended_tests/schemars/README.md | 10 ++++++++++ hashes/src/lib.rs | 2 +- 8 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 hashes/extended_tests/schemars/README.md 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]