From 98f9cb07bd55510b005110cb965722f99e9169cf Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Fri, 13 Sep 2024 21:35:06 +0400 Subject: [PATCH] extract stable-layout crate --- Cargo.lock | 10 ++++++++++ Cargo.toml | 2 ++ programs/sbf/Cargo.lock | 9 +++++++++ sdk/program/Cargo.toml | 1 + sdk/program/src/lib.rs | 3 ++- sdk/stable-layout/Cargo.toml | 19 +++++++++++++++++++ .../src/lib.rs} | 0 .../src}/stable_instruction.rs | 12 ++++++------ .../src}/stable_rc.rs | 0 .../src}/stable_ref_cell.rs | 0 .../src}/stable_slice.rs | 0 .../src}/stable_vec.rs | 2 +- 12 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 sdk/stable-layout/Cargo.toml rename sdk/{program/src/stable_layout.rs => stable-layout/src/lib.rs} (100%) rename sdk/{program/src/stable_layout => stable-layout/src}/stable_instruction.rs (91%) rename sdk/{program/src/stable_layout => stable-layout/src}/stable_rc.rs (100%) rename sdk/{program/src/stable_layout => stable-layout/src}/stable_ref_cell.rs (100%) rename sdk/{program/src/stable_layout => stable-layout/src}/stable_slice.rs (100%) rename sdk/{program/src/stable_layout => stable-layout/src}/stable_vec.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index fb0f87b78b7640..0843b0960401ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7140,6 +7140,7 @@ dependencies = [ "solana-serde-varint", "solana-sha256-hasher", "solana-short-vec", + "solana-stable-layout", "static_assertions", "test-case", "thiserror", @@ -7780,6 +7781,15 @@ dependencies = [ "solana-sanitize", ] +[[package]] +name = "solana-stable-layout" +version = "2.1.0" +dependencies = [ + "memoffset 0.9.1", + "solana-instruction", + "solana-pubkey", +] + [[package]] name = "solana-stake-accounts" version = "2.1.0" diff --git a/Cargo.toml b/Cargo.toml index 2b8cbd137f4e12..8e08685c50ba3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,6 +121,7 @@ members = [ "sdk/serde-varint", "sdk/sha256-hasher", "sdk/signature", + "sdk/stable-layout", "send-transaction-service", "short-vec", "stake-accounts", @@ -450,6 +451,7 @@ solana-sdk-macro = { path = "sdk/macro", version = "=2.1.0" } solana-secp256k1-recover = { path = "curves/secp256k1-recover", version = "=2.1.0", default-features = false } solana-send-transaction-service = { path = "send-transaction-service", version = "=2.1.0" } solana-short-vec = { path = "short-vec", version = "=2.1.0" } +solana-stable-layout = { path = "sdk/stable-layout", version = "=2.1.0" } solana-stake-program = { path = "programs/stake", version = "=2.1.0" } solana-storage-bigtable = { path = "storage-bigtable", version = "=2.1.0" } solana-storage-proto = { path = "storage-proto", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index cbe090c6449fe3..d21452a4b55d8f 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5525,6 +5525,7 @@ dependencies = [ "solana-serde-varint", "solana-sha256-hasher", "solana-short-vec", + "solana-stable-layout", "thiserror", "wasm-bindgen", ] @@ -6519,6 +6520,14 @@ dependencies = [ "solana-sanitize", ] +[[package]] +name = "solana-stable-layout" +version = "2.1.0" +dependencies = [ + "solana-instruction", + "solana-pubkey", +] + [[package]] name = "solana-stake-program" version = "2.1.0" diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 2f2c6feaebad69..e1127998cfa996 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -56,6 +56,7 @@ solana-secp256k1-recover = { workspace = true } solana-serde-varint = { workspace = true } solana-sha256-hasher = { workspace = true, features = ["sha2"] } solana-short-vec = { workspace = true } +solana-stable-layout = { workspace = true } thiserror = { workspace = true } # This is currently needed to build on-chain programs reliably. diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 7fb630240861de..67442045943aa4 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -516,7 +516,6 @@ pub mod secp256k1_program; pub mod serialize_utils; pub mod slot_hashes; pub mod slot_history; -pub mod stable_layout; pub mod stake; pub mod stake_history; pub mod syscalls; @@ -536,6 +535,8 @@ pub use solana_secp256k1_recover as secp256k1_recover; pub use solana_serde_varint as serde_varint; #[deprecated(since = "2.1.0", note = "Use `solana-short-vec` crate instead")] pub use solana_short_vec as short_vec; +#[deprecated(since = "2.1.0", note = "Use `solana-stable-layout` crate instead")] +pub use solana_stable_layout as stable_layout; #[cfg(target_arch = "wasm32")] pub use wasm_bindgen::prelude::wasm_bindgen; pub use { diff --git a/sdk/stable-layout/Cargo.toml b/sdk/stable-layout/Cargo.toml new file mode 100644 index 00000000000000..3e81077050b9d4 --- /dev/null +++ b/sdk/stable-layout/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "solana-stable-layout" +description = "Solana types with stable memory layouts. Internal use only." +documentation = "https://docs.rs/solana-stable-layout" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +solana-instruction = { workspace = true, default-features = false, features = [ + "std", +] } +solana-pubkey = { workspace = true, default-features = false } + +[dev-dependencies] +memoffset = { workspace = true } diff --git a/sdk/program/src/stable_layout.rs b/sdk/stable-layout/src/lib.rs similarity index 100% rename from sdk/program/src/stable_layout.rs rename to sdk/stable-layout/src/lib.rs diff --git a/sdk/program/src/stable_layout/stable_instruction.rs b/sdk/stable-layout/src/stable_instruction.rs similarity index 91% rename from sdk/program/src/stable_layout/stable_instruction.rs rename to sdk/stable-layout/src/stable_instruction.rs index e01bd37477b5f7..423ceb71e46411 100644 --- a/sdk/program/src/stable_layout/stable_instruction.rs +++ b/sdk/stable-layout/src/stable_instruction.rs @@ -1,11 +1,9 @@ //! `Instruction`, with a stable memory layout use { - crate::{ - instruction::{AccountMeta, Instruction}, - pubkey::Pubkey, - stable_layout::stable_vec::StableVec, - }, + crate::stable_vec::StableVec, + solana_instruction::{AccountMeta, Instruction}, + solana_pubkey::Pubkey, std::fmt::Debug, }; @@ -21,7 +19,9 @@ use { /// Creating a `StableInstruction` from an `Instruction` /// /// ``` -/// # use solana_program::{instruction::Instruction, pubkey::Pubkey, stable_layout::stable_instruction::StableInstruction}; +/// # use solana_instruction::Instruction; +/// # use solana_pubkey::Pubkey; +/// # use solana_stable_layout::stable_instruction::StableInstruction; /// # let program_id = Pubkey::default(); /// # let accounts = Vec::default(); /// # let data = Vec::default(); diff --git a/sdk/program/src/stable_layout/stable_rc.rs b/sdk/stable-layout/src/stable_rc.rs similarity index 100% rename from sdk/program/src/stable_layout/stable_rc.rs rename to sdk/stable-layout/src/stable_rc.rs diff --git a/sdk/program/src/stable_layout/stable_ref_cell.rs b/sdk/stable-layout/src/stable_ref_cell.rs similarity index 100% rename from sdk/program/src/stable_layout/stable_ref_cell.rs rename to sdk/stable-layout/src/stable_ref_cell.rs diff --git a/sdk/program/src/stable_layout/stable_slice.rs b/sdk/stable-layout/src/stable_slice.rs similarity index 100% rename from sdk/program/src/stable_layout/stable_slice.rs rename to sdk/stable-layout/src/stable_slice.rs diff --git a/sdk/program/src/stable_layout/stable_vec.rs b/sdk/stable-layout/src/stable_vec.rs similarity index 98% rename from sdk/program/src/stable_layout/stable_vec.rs rename to sdk/stable-layout/src/stable_vec.rs index 25a317076d117f..5596ab08775e6d 100644 --- a/sdk/program/src/stable_layout/stable_vec.rs +++ b/sdk/stable-layout/src/stable_vec.rs @@ -18,7 +18,7 @@ use std::{marker::PhantomData, mem::ManuallyDrop, ptr::NonNull}; /// Creating a `StableVec` from a `Vec` /// /// ``` -/// # use solana_program::stable_layout::stable_vec::StableVec; +/// # use solana_stable_layout::stable_vec::StableVec; /// let vec = vec!["meow", "woof", "moo"]; /// let vec = StableVec::from(vec); /// ```