From e21e68d59306127cfa702b1edbce31a68a649e91 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 3 Dec 2024 03:30:27 +0400 Subject: [PATCH 1/3] move program::wasm::instructions to instruction crate --- sdk/instruction/src/lib.rs | 2 ++ .../src/wasm/instructions.rs => instruction/src/wasm.rs} | 9 +++++---- sdk/program/src/wasm/mod.rs | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) rename sdk/{program/src/wasm/instructions.rs => instruction/src/wasm.rs} (66%) diff --git a/sdk/instruction/src/lib.rs b/sdk/instruction/src/lib.rs index 12431ba513f91d..201f88813f4f6a 100644 --- a/sdk/instruction/src/lib.rs +++ b/sdk/instruction/src/lib.rs @@ -26,6 +26,8 @@ pub use account_meta::AccountMeta; pub mod error; #[cfg(target_os = "solana")] pub mod syscalls; +#[cfg(feature = "std")] +pub mod wasm; /// A directive for a single invocation of a Solana program. /// diff --git a/sdk/program/src/wasm/instructions.rs b/sdk/instruction/src/wasm.rs similarity index 66% rename from sdk/program/src/wasm/instructions.rs rename to sdk/instruction/src/wasm.rs index 36abe05c6f4d8d..eaa4d313422636 100644 --- a/sdk/program/src/wasm/instructions.rs +++ b/sdk/instruction/src/wasm.rs @@ -1,12 +1,13 @@ -//! The `Instructions` struct is a workaround for the lack of Vec support in wasm-bindgen +//! The `Instructions` struct is a legacy workaround +//! from when wasm-bindgen lacked Vec support //! (ref: https://github.com/rustwasm/wasm-bindgen/issues/111) #![cfg(target_arch = "wasm32")] -use {crate::instruction::Instruction, wasm_bindgen::prelude::*}; +use {crate::Instruction, wasm_bindgen::prelude::*}; #[wasm_bindgen] #[derive(Default)] pub struct Instructions { - instructions: Vec, + instructions: std::vec::Vec, } #[wasm_bindgen] @@ -21,7 +22,7 @@ impl Instructions { } } -impl From for Vec { +impl From for std::vec::Vec { fn from(instructions: Instructions) -> Self { instructions.instructions } diff --git a/sdk/program/src/wasm/mod.rs b/sdk/program/src/wasm/mod.rs index cdf5bdca138482..04fb9b2db0a18b 100644 --- a/sdk/program/src/wasm/mod.rs +++ b/sdk/program/src/wasm/mod.rs @@ -2,7 +2,8 @@ #![cfg(target_arch = "wasm32")] use wasm_bindgen::prelude::*; -pub mod instructions; +#[deprecated(since = "2.2.0", note = "Use solana_instruction::wasm instead.")] +pub use solana_instruction::wasm as instructions; // This module is intentionally left empty. The wasm system instruction impl can be // found in the `solana-system-interface` crate. pub mod system_instruction {} From a4f8f124d9618bb85475c82a3c2c42335d8b4ec5 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 3 Dec 2024 03:39:26 +0400 Subject: [PATCH 2/3] fmt --- sdk/program/src/wasm/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/program/src/wasm/mod.rs b/sdk/program/src/wasm/mod.rs index 04fb9b2db0a18b..337dfb1dbd4887 100644 --- a/sdk/program/src/wasm/mod.rs +++ b/sdk/program/src/wasm/mod.rs @@ -1,9 +1,8 @@ //! solana-program Javascript interface #![cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::*; - #[deprecated(since = "2.2.0", note = "Use solana_instruction::wasm instead.")] pub use solana_instruction::wasm as instructions; +use wasm_bindgen::prelude::*; // This module is intentionally left empty. The wasm system instruction impl can be // found in the `solana-system-interface` crate. pub mod system_instruction {} From 7dc4376371ed2d5ae10ee6e2a4558a8fca689028 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 3 Dec 2024 16:14:44 +0400 Subject: [PATCH 3/3] unify cfg usage --- sdk/instruction/src/lib.rs | 2 +- sdk/instruction/src/wasm.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/instruction/src/lib.rs b/sdk/instruction/src/lib.rs index 201f88813f4f6a..673d379c712109 100644 --- a/sdk/instruction/src/lib.rs +++ b/sdk/instruction/src/lib.rs @@ -26,7 +26,7 @@ pub use account_meta::AccountMeta; pub mod error; #[cfg(target_os = "solana")] pub mod syscalls; -#[cfg(feature = "std")] +#[cfg(all(feature = "std", target_arch = "wasm32"))] pub mod wasm; /// A directive for a single invocation of a Solana program. diff --git a/sdk/instruction/src/wasm.rs b/sdk/instruction/src/wasm.rs index eaa4d313422636..03c88bb757a49f 100644 --- a/sdk/instruction/src/wasm.rs +++ b/sdk/instruction/src/wasm.rs @@ -1,7 +1,6 @@ //! The `Instructions` struct is a legacy workaround //! from when wasm-bindgen lacked Vec support //! (ref: https://github.com/rustwasm/wasm-bindgen/issues/111) -#![cfg(target_arch = "wasm32")] use {crate::Instruction, wasm_bindgen::prelude::*}; #[wasm_bindgen]