Skip to content

Commit

Permalink
Remove frozen ABI modules from solana-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Oct 20, 2020
1 parent a18add6 commit 0cef6e2
Show file tree
Hide file tree
Showing 38 changed files with 240 additions and 106 deletions.
60 changes: 42 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"dos",
"download-utils",
"faucet",
"frozen-abi",
"perf",
"validator",
"genesis",
Expand Down
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ solana-net-utils = { path = "../net-utils", version = "1.5.0" }
solana-perf = { path = "../perf", version = "1.5.0" }
solana-runtime = { path = "../runtime", version = "1.5.0" }
solana-sdk = { path = "../sdk", version = "1.5.0" }
solana-sdk-macro-frozen-abi = { path = "../sdk/macro-frozen-abi", version = "1.5.0" }
solana-frozen-abi = { path = "../frozen-abi", version = "1.5.0" }
solana-frozen-abi-macro = { path = "../frozen-abi/macro", version = "1.5.0" }
solana-stake-program = { path = "../programs/stake", version = "1.5.0" }
solana-storage-bigtable = { path = "../storage-bigtable", version = "1.5.0" }
solana-streamer = { path = "../streamer", version = "1.5.0" }
Expand Down
2 changes: 1 addition & 1 deletion core/build.rs
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern crate serde_json;
extern crate solana_metrics;

#[macro_use]
extern crate solana_sdk_macro_frozen_abi;
extern crate solana_frozen_abi_macro;

#[cfg(test)]
#[macro_use]
Expand Down
27 changes: 27 additions & 0 deletions frozen-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "solana-frozen-abi"
version = "1.5.0"
description = "Solana Frozen ABI"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
homepage = "https://solana.com/"
license = "Apache-2.0"
edition = "2018"

[dependencies]
bs58 = "0.3.1"
bv = { version = "0.11.1", features = ["serde"] }
log = "0.4.8"
serde = "1.0.112"
serde_derive = "1.0.103"
sha2 = "0.8.2"
solana-frozen-abi-macro = { path = "macro", version = "1.5.0" }
thiserror = "1.0"

[target.'cfg(not(target_arch = "bpf"))'.dependencies]
solana-logger = { path = "../logger", version = "1.5.0" }
generic-array = { version = "0.14.3", default-features = false, features = ["serde", "more_lengths"]}
memmap = "0.7.0"

[build-dependencies]
rustc_version = "0.2"
27 changes: 27 additions & 0 deletions frozen-abi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel};

fn main() {
// Copied and adapted from
// https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example
// Licensed under Apache-2.0 + MIT
match version_meta().unwrap().channel {
Channel::Stable => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Beta => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Nightly => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
}
Channel::Dev => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
// See https://github.com/solana-labs/solana/issues/11055
// We may be running the custom `rust-bpf-builder` toolchain,
// which currently needs `#![feature(proc_macro_hygiene)]` to
// be applied.
println!("cargo:rustc-cfg=RUSTC_NEEDS_PROC_MACRO_HYGIENE");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "solana-sdk-macro-frozen-abi"
name = "solana-frozen-abi-macro"
version = "1.5.0"
description = "Solana SDK Macro frozen abi"
description = "Solana Frozen ABI Macro"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
homepage = "https://solana.com/"
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions sdk/macro-frozen-abi/src/lib.rs → frozen-abi/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn derive_abi_sample_enum_type(input: ItemEnum) -> TokenStream {
#injection
#[automatically_derived]
#( #attrs )*
impl #impl_generics ::solana_sdk::abi_example::AbiExample for #type_name #ty_generics #where_clause {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause {
fn example() -> Self {
::log::info!(
"AbiExample for enum: {}",
Expand Down Expand Up @@ -221,13 +221,13 @@ fn derive_abi_sample_struct_type(input: ItemStruct) -> TokenStream {
#injection
#[automatically_derived]
#( #attrs )*
impl #impl_generics ::solana_sdk::abi_example::AbiExample for #type_name #ty_generics #where_clause {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiExample for #type_name #ty_generics #where_clause {
fn example() -> Self {
::log::info!(
"AbiExample for struct: {}",
std::any::type_name::<#type_name #ty_generics>()
);
use ::solana_sdk::abi_example::AbiExample;
use ::solana_frozen_abi::abi_example::AbiExample;

#type_name #turbofish #sample_fields
}
Expand Down Expand Up @@ -272,11 +272,11 @@ fn do_derive_abi_enum_visitor(input: ItemEnum) -> TokenStream {

let type_str = format!("{}", type_name);
(quote! {
impl #impl_generics ::solana_sdk::abi_example::AbiEnumVisitor for #type_name #ty_generics #where_clause {
fn visit_for_abi(&self, digester: &mut ::solana_sdk::abi_digester::AbiDigester) -> ::solana_sdk::abi_digester::DigestResult {
impl #impl_generics ::solana_frozen_abi::abi_example::AbiEnumVisitor for #type_name #ty_generics #where_clause {
fn visit_for_abi(&self, digester: &mut ::solana_frozen_abi::abi_digester::AbiDigester) -> ::solana_frozen_abi::abi_digester::DigestResult {
let enum_name = #type_str;
use ::serde::ser::Serialize;
use ::solana_sdk::abi_example::AbiExample;
use ::solana_frozen_abi::abi_example::AbiExample;
digester.update_with_string(format!("enum {} (variants = {})", enum_name, #variant_count));
#serialized_variants
Ok(digester.create_child())
Expand Down Expand Up @@ -310,12 +310,12 @@ fn quote_for_test(
#[cfg(test)]
mod #test_mod_ident {
use super::*;
use ::solana_sdk::abi_example::{AbiExample, AbiEnumVisitor};
use ::solana_frozen_abi::abi_example::{AbiExample, AbiEnumVisitor};

#[test]
fn test_abi_digest() {
::solana_logger::setup();
let mut digester = ::solana_sdk::abi_digester::AbiDigester::create();
let mut digester = ::solana_frozen_abi::abi_digester::AbiDigester::create();
let example = <#type_name>::example();
let result = <_>::visit_for_abi(&&example, &mut digester);
let mut hash = digester.finalize();
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/abi_digester.rs → frozen-abi/src/abi_digester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ mod tests {
test_field2: i8,
}

#[frozen_abi(digest = "Hv597t4PieHYvgiXnwRSpKBRTWqteUS4nHZHY6ZxX69v")]
#[frozen_abi(digest = "GMeECsxg37a5qznstWXeeX3d6HXs6j12oB4SKaZZuNJk")]
#[derive(Serialize, AbiExample)]
struct TestNest {
nested_field: [TestStruct; 5],
Expand All @@ -573,7 +573,7 @@ mod tests {
VARIANT2(u8, u16),
}

#[frozen_abi(digest = "CKxzv7VjyUrNR9fGJpTpKyMBWJM4gepKshCS8oV14T1Q")]
#[frozen_abi(digest = "DywMfwKq8HZCbUfTwnemHWMN8LvMZCvipQuLddQ2ywwG")]
#[derive(Serialize, AbiExample)]
struct TestVecEnum {
enums: Vec<TestTupleVariant>,
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/abi_example.rs → frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ atomic_example_impls! { AtomicI64 }
atomic_example_impls! { AtomicIsize }
atomic_example_impls! { AtomicBool }

#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
use generic_array::{ArrayLength, GenericArray};
#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl<T: Default, U: ArrayLength<T>> AbiExample for GenericArray<T, U> {
fn example() -> Self {
Self::default()
Expand Down Expand Up @@ -413,14 +413,14 @@ impl<T: std::cmp::Ord + AbiExample> AbiExample for BTreeSet<T> {
}
}

#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl AbiExample for memmap::MmapMut {
fn example() -> Self {
memmap::MmapMut::map_anon(1).expect("failed to map the data file")
}
}

#[cfg(feature = "everything")]
#[cfg(not(target_arch = "bpf"))]
impl AbiExample for std::path::PathBuf {
fn example() -> Self {
std::path::PathBuf::from(String::example())
Expand Down
28 changes: 28 additions & 0 deletions frozen-abi/src/hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use sha2::{Digest, Sha256};
use std::{convert::TryFrom, fmt};

const HASH_BYTES: usize = 32;
#[derive(AbiExample)]
pub struct Hash(pub [u8; HASH_BYTES]);

#[derive(Default)]
pub struct Hasher {
hasher: Sha256,
}

impl Hasher {
pub fn hash(&mut self, val: &[u8]) {
self.hasher.input(val);
}
pub fn result(self) -> Hash {
// At the time of this writing, the sha2 library is stuck on an old version
// of generic_array (0.9.0). Decouple ourselves with a clone to our version.
Hash(<[u8; HASH_BYTES]>::try_from(self.hasher.result().as_slice()).unwrap())
}
}

impl fmt::Display for Hash {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", bs58::encode(self.0).into_string())
}
}
22 changes: 22 additions & 0 deletions frozen-abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]

// Allows macro expansion of `use ::solana_frozen_abi::*` to work within this crate
extern crate self as solana_frozen_abi;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
pub mod abi_digester;
#[cfg(RUSTC_WITH_SPECIALIZATION)]
pub mod abi_example;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
mod hash;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
#[macro_use]
extern crate solana_frozen_abi_macro;

#[cfg(RUSTC_WITH_SPECIALIZATION)]
#[cfg(test)]
#[macro_use]
extern crate serde_derive;
Loading

0 comments on commit 0cef6e2

Please sign in to comment.