Skip to content

Commit 8440d80

Browse files
committed
Merge rust-bitcoin#1696: Remove schemars pin from manifest
6c61e10 Fix pinning (schemars and MSRV) (Tobin C. Harding) c8e38d6 hashes: Implement JsonSchema for sha256t::Hash<T> (Tobin C. Harding) Pull request description: This has grown due to now including pinning work also done in rust-bitcoin#1736, I decided to do this because the PRs conflict and doing it all here saves accidentally getting out of sync. And rust-bitcoin#1764 requires this PR. - Patch 1 is unchanged - Patch 2 now fixes pinning in bitcoin and hashes CI scripts and in the docs of both as well as the manifest stuff relating to `schemars` - phew. Fix: rust-bitcoin#1687 ACKs for top commit: Kixunil: ACK 6c61e10 apoelstra: ACK 6c61e10 Tree-SHA512: eae4aa9700817bab6ad444e07709e8b1a4ffb1625e08be6ba399abde38bf6f8e5ea216a0836e2e26dfaddc76c392802cd016738ea6e753a1bca2584d9d2a9796
2 parents 0af8d45 + 6c61e10 commit 8440d80

File tree

9 files changed

+54
-24
lines changed

9 files changed

+54
-24
lines changed

README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,16 @@ For more information please see `./CONTRIBUTING.md`.
7777

7878
This library should always compile with any combination of features on **Rust 1.48.0**.
7979

80-
To build with the MSRV you will need to pin some dependencies:
80+
To build with the MSRV you will need to pin `serde` (if you have the feature enabled)
81+
8182
```
83+
# serde 1.0.157 uses syn 2.0 which requires edition 2021
8284
cargo update -p serde --precise 1.0.156
83-
cargo update -p syn --precise 1.0.107
8485
```
8586

87+
before building. (And if your code is a library, your downstream users will need to run these
88+
commands, and so on.)
89+
8690
## Installing Rust
8791

8892
Rust can be installed using your package manager of choice or

bitcoin/contrib/test.sh

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ fi
2727
if cargo --version | grep "1\.48"; then
2828
# 1.0.157 uses syn 2.0 which requires edition 2018
2929
cargo update -p serde --precise 1.0.156
30-
# 1.0.108 uses `matches!` macro so does not work with Rust 1.41.1, bad `syn` no biscuit.
31-
cargo update -p syn --precise 1.0.107
3230
fi
3331

3432
# We should not have any duplicate dependencies. This catches mistakes made upgrading dependencies

hashes/Cargo.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ exclude = ["tests", "contrib"]
1616
default = ["std"]
1717
std = ["alloc", "internals/std"]
1818
alloc = ["internals/alloc"]
19-
schemars = ["actual-schemars", "dyn-clone"]
2019
serde-std = ["serde/std"]
2120

2221
[package.metadata.docs.rs]
@@ -27,13 +26,9 @@ rustdoc-args = ["--cfg", "docsrs"]
2726
internals = { path = "../internals", package = "bitcoin-private", version = "0.1.0" }
2827

2928
core2 = { version = "0.3.0", default_features = false, optional = true }
29+
schemars = { version = "0.8.3", optional = true }
3030
# Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std".
3131
serde = { version = "1.0", default-features = false, optional = true }
32-
# Do NOT use this as a feature! Use the `schemars` feature instead. Can only be used with "std" enabled.
33-
actual-schemars = { package = "schemars", version = "<=0.8.3", optional = true }
34-
# Do NOT enable this dependency, this is just to pin dyn-clone (transitive dep from schemars)
35-
# because 1.0.8 does not build with Rust 1.41.1 (because of useage of `Arc::as_ptr`).
36-
dyn-clone = { version = "<=1.0.7", default_features = false, optional = true }
3732

3833
[dev-dependencies]
3934
serde_test = "1.0"

hashes/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ since these are needed to display hashes anway.
1313

1414
This library should always compile with any combination of features on **Rust 1.48.0**.
1515

16+
17+
To build with the MSRV you will need to pin `serde` (if you have either the `serde` or the
18+
`schemars` feature enabled)
19+
20+
```
21+
# serde 1.0.157 uses syn 2.0 which requires edition 2021
22+
cargo update -p serde --precise 1.0.156
23+
```
24+
25+
before building. (And if your code is a library, your downstream users will need to run these
26+
commands, and so on.)
27+
1628
## Contributions
1729

1830
Contributions are welcome, including additional hash function implementations.

hashes/contrib/test.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
set -ex
44

@@ -17,6 +17,12 @@ if cargo --version | grep nightly >/dev/null; then
1717
NIGHTLY=true
1818
fi
1919

20+
# Pin dependencies as required if we are using MSRV toolchain.
21+
if cargo --version | grep "1\.48"; then
22+
# 1.0.157 uses syn 2.0 which requires edition 2021
23+
cargo update -p serde --precise 1.0.156
24+
fi
25+
2026
# Make all cargo invocations verbose
2127
export CARGO_TERM_VERBOSE=true
2228

@@ -52,8 +58,12 @@ if [ "$DO_FEATURE_MATRIX" = true ]; then
5258
cargo test --no-default-features --features="std,schemars"
5359
fi
5460

61+
REPO_DIR=$(git rev-parse --show-toplevel)
62+
5563
if [ "$DO_SCHEMARS_TESTS" = true ]; then
56-
(cd extended_tests/schemars && cargo test)
64+
pushd "$REPO_DIR/hashes/extended_tests/schemars" > /dev/null
65+
cargo test
66+
popd > /dev/null
5767
fi
5868

5969
# Build the docs if told to (this only works with the nightly toolchain)

hashes/extended_tests/schemars/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ path = "../.."
1313
features = ['schemars', 'serde']
1414

1515
[dependencies]
16-
jsonschema-valid = "^0.4.0"
16+
jsonschema-valid = "0.4.0"
1717
serde = { version = "1.0", default-features = false}
18-
schemars = { version = "<=0.8.3"}
18+
schemars = "0.8.3"
1919
serde_test = "1.0"
2020
serde_json = "1.0"
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Test crate for the schemars feature
2+
3+
Run as usual with `cargo test`.
4+
5+
## Minimum Supported Rust Version (MSRV)
6+
7+
To run the tests with the MSRV you will need to pin some dependencies:
8+
9+
- `cargo update -p serde --precise 1.0.156`
10+
- `cargo update -p syn --precise 1.0.107`

hashes/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub mod _export {
113113
}
114114

115115
#[cfg(feature = "schemars")]
116-
extern crate actual_schemars as schemars;
116+
extern crate schemars;
117117

118118
mod internal_macros;
119119
#[macro_use]

hashes/src/sha256t.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@ pub trait Tag {
3131
}
3232

3333
/// Output of the SHA256t hash function.
34-
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
3534
#[repr(transparent)]
36-
pub struct Hash<T: Tag>(
37-
#[cfg_attr(
38-
feature = "schemars",
39-
schemars(schema_with = "crate::util::json_hex_string::len_32")
40-
)]
41-
[u8; 32],
42-
#[cfg_attr(feature = "schemars", schemars(skip))] PhantomData<T>,
43-
);
35+
pub struct Hash<T: Tag>([u8; 32], PhantomData<T>);
36+
37+
#[cfg(feature = "schemars")]
38+
impl<T: Tag> schemars::JsonSchema for Hash<T> {
39+
fn schema_name() -> String { "Hash".to_owned() }
40+
41+
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
42+
crate::util::json_hex_string::len_32(gen)
43+
}
44+
}
4445

4546
impl<T: Tag> Hash<T> {
4647
fn internal_new(arr: [u8; 32]) -> Self { Hash(arr, Default::default()) }

0 commit comments

Comments
 (0)