Skip to content

Commit d893d59

Browse files
authored
frozen-abi: add re-exports / patch to support rust edition 2021/2024 (#466)
* - replace workspace rand import with strict 0.8.5 (versions above has changed api) - make default implementation of random in StableAbi trait, compatible with rust edition 2024 - add re-exports to rand, rand_chacha and bincode (narrows StableAbi strict versions) * update test_abi_digest to reference frozen-abi re-exports * add better explination why frozen-abi re-exports rand, rand_chacha and bincode * more concise cfg attributes for re-exported types / StableAbi mod * align re-export deps commentary * add edition 2024 lints
1 parent 4dd9b57 commit d893d59

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frozen-abi-macro/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ fn quote_for_test(
345345
quote! {
346346
#[test]
347347
fn test_abi_digest() {
348-
use ::rand::{SeedableRng, RngCore};
349-
use ::rand_chacha::ChaCha8Rng;
350-
use ::bincode;
348+
use ::solana_frozen_abi::rand::{SeedableRng, RngCore};
349+
use ::solana_frozen_abi::rand_chacha::ChaCha8Rng;
350+
use ::solana_frozen_abi::bincode;
351351
use ::solana_frozen_abi::stable_abi::StableAbi;
352352

353353
let mut rng = ChaCha8Rng::seed_from_u64(20666175621446498);

frozen-abi/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ solana-frozen-abi-macro = { workspace = true }
3535
thiserror = { workspace = true }
3636

3737
[target.'cfg(not(target_os = "solana"))'.dependencies]
38+
# These dependencies are used only to back `frozen-abi` StableAbi API,
39+
# to avoid version skew and keep digest computation stable regardless of consumer dependencies.
40+
bincode = "1.3.3"
3841
im = { workspace = true, features = ["rayon", "serde"] }
3942
memmap2 = { workspace = true }
40-
rand = { workspace = true }
43+
# These dependencies are used only to back `frozen-abi` StableAbi API,
44+
# to avoid version skew and keep digest computation stable regardless of consumer dependencies.
45+
rand = "0.8.5"
46+
rand_chacha = "0.3.1"
4147

4248
[target.'cfg(not(target_os = "solana"))'.dev-dependencies]
4349
bitflags = { workspace = true, features = ["serde"] }

frozen-abi/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#![allow(incomplete_features)]
22
#![cfg_attr(docsrs, feature(doc_cfg))]
33
#![cfg_attr(feature = "frozen-abi", feature(specialization))]
4+
// Activate some of the Rust 2024 lints to make the future migration easier.
5+
#![warn(if_let_rescope)]
6+
#![warn(keyword_idents_2024)]
7+
#![warn(rust_2024_incompatible_pat)]
8+
#![warn(tail_expr_drop_order)]
9+
#![warn(unsafe_attr_outside_unsafe)]
10+
#![warn(unsafe_op_in_unsafe_fn)]
411

512
// Allows macro expansion of `use ::solana_frozen_abi::*` to work within this crate
613
extern crate self as solana_frozen_abi;
@@ -11,14 +18,17 @@ pub mod abi_digester;
1118
pub mod abi_example;
1219
#[cfg(feature = "frozen-abi")]
1320
pub mod hash;
14-
#[cfg(feature = "frozen-abi")]
15-
#[cfg(not(target_os = "solana"))]
21+
22+
#[cfg(all(feature = "frozen-abi", not(target_os = "solana")))]
1623
pub mod stable_abi;
1724

1825
#[cfg(feature = "frozen-abi")]
1926
#[macro_use]
2027
extern crate solana_frozen_abi_macro;
2128

29+
#[cfg(all(feature = "frozen-abi", not(target_os = "solana")))]
30+
pub use {bincode, rand, rand_chacha};
31+
2232
// Not public API. Previously referenced by macro-generated code. Remove the
2333
// `log` dependency from Cargo.toml when this is cleaned up in the next major
2434
// version bump

frozen-abi/src/stable_abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ pub trait StableAbi: Sized {
55
where
66
Standard: rand::distributions::Distribution<Self>,
77
{
8-
rng.gen::<Self>()
8+
rng.r#gen::<Self>()
99
}
1010
}

0 commit comments

Comments
 (0)