diff --git a/Cargo.lock b/Cargo.lock index 5ae0261d9..ec635a6ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3522,8 +3522,6 @@ dependencies = [ "borsh 0.10.4", "borsh 1.5.5", "bytemuck", - "console_error_panic_hook", - "console_log", "getrandom 0.2.15", "lazy_static", "log", @@ -3575,7 +3573,6 @@ dependencies = [ "solana-sysvar", "solana-sysvar-id", "thiserror 2.0.12", - "wasm-bindgen", ] [[package]] @@ -3726,7 +3723,6 @@ dependencies = [ "bincode", "bs58", "getrandom 0.1.16", - "js-sys", "serde", "solana-account", "solana-derivation-path", @@ -3760,7 +3756,6 @@ dependencies = [ "solana-transaction", "solana-transaction-error", "thiserror 2.0.12", - "wasm-bindgen", ] [[package]] @@ -3780,6 +3775,20 @@ dependencies = [ "syn 2.0.98", ] +[[package]] +name = "solana-sdk-wasm-js" +version = "1.0.0" +dependencies = [ + "console_error_panic_hook", + "console_log", + "js-sys", + "log", + "solana-instruction", + "solana-program", + "solana-sdk", + "wasm-bindgen", +] + [[package]] name = "solana-secp256k1-program" version = "2.2.3" @@ -4771,7 +4780,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 4dcf9b4ca..3c8476212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,6 +71,7 @@ members = [ "sdk", "sdk-ids", "sdk-macro", + "sdk-wasm-js", "secp256k1-program", "secp256k1-recover", "secp256r1-program", diff --git a/program/Cargo.toml b/program/Cargo.toml index c99dc1bbc..e6fe6f240 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -18,7 +18,7 @@ all-features = true rustdoc-args = ["--cfg=docsrs"] [lib] -crate-type = ["cdylib", "rlib"] +crate-type = ["rlib"] [features] default = ["borsh"] @@ -113,12 +113,6 @@ thiserror = { workspace = true } num-bigint = { workspace = true } solana-example-mocks = { workspace = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_error_panic_hook = { workspace = true } -console_log = { workspace = true } -getrandom = { workspace = true, features = ["js", "wasm-bindgen"] } -wasm-bindgen = { workspace = true } - # This is currently needed to build on-chain programs reliably. # Borsh 0.10 may pull in hashbrown 0.13, which uses ahash 0.8, which uses # getrandom 0.2 underneath. This explicit dependency allows for no-std if cargo diff --git a/program/src/lib.rs b/program/src/lib.rs index c148b4daf..36c35c3b5 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -94,16 +94,22 @@ //! //! ```toml //! [lib] -//! crate-type = ["cdylib", "rlib"] +//! crate-type = ["cdylib"] //! //! [features] //! no-entrypoint = [] //! ``` //! -//! Note that a Solana program must specify its crate-type as "cdylib", and -//! "cdylib" crates will automatically be discovered and built by the `cargo -//! build-bpf` command. Solana programs also often have crate-type "rlib" so -//! they can be linked to other Rust crates. +//! Note that a Solana program must specify its crate-type as "cdylib", to +//! be discovered and built by the `cargo-build-sbf` command as a deployable program. +//! Solana programs also often have crate-type "rlib" so they can be linked to other Rust crates. +//! Avoid using "rlib" and "cdylib" crates together, since their combined usage precludes +//! compiler optimizations that may decrease program size and CU usage. +//! +//! Prefer writing a separate package if it is supposed to be used as a library for other Solana +//! programs (i.e. a "rlib" only crate). This would be normally the case for defining account +//! types and helpers that are used by both clients and program. When creating a Rust project +//! intended to be a program ready for deployment, use only the "cdylib" crate type. //! //! # On-chain vs. off-chain compilation targets //! @@ -489,7 +495,6 @@ pub mod slot_hashes; pub mod slot_history; pub mod syscalls; pub mod sysvar; -pub mod wasm; #[deprecated(since = "2.2.0", note = "Use `solana-big-mod-exp` crate instead")] pub use solana_big_mod_exp as big_mod_exp; @@ -528,8 +533,6 @@ pub use solana_short_vec as short_vec; pub use solana_stable_layout as stable_layout; #[cfg(not(target_os = "solana"))] pub use solana_sysvar::program_stubs; -#[cfg(target_arch = "wasm32")] -pub use wasm_bindgen::prelude::wasm_bindgen; pub use { solana_account_info::{self as account_info, debug_account_data}, solana_clock as clock, diff --git a/scripts/build-sbf.sh b/scripts/build-sbf.sh index d73b55f83..d39654f80 100755 --- a/scripts/build-sbf.sh +++ b/scripts/build-sbf.sh @@ -19,6 +19,7 @@ exclude_list=( "presigner" "quic-definitions" "rent-collector" + "sdk-wasm-js" "secp256k1-program" "secp256r1-program" "system-transaction" diff --git a/scripts/test-wasm.sh b/scripts/test-wasm.sh index 12b224f86..3f8fee394 100755 --- a/scripts/test-wasm.sh +++ b/scripts/test-wasm.sh @@ -5,10 +5,6 @@ here="$(dirname "$0")" src_root="$(readlink -f "${here}/..")" cd "${src_root}" -for dir in program sdk ; do - ( - cd "$dir" - npm install - npm test - ) -done +cd sdk-wasm-js +npm install +npm test diff --git a/program/.gitignore b/sdk-wasm-js/.gitignore similarity index 100% rename from program/.gitignore rename to sdk-wasm-js/.gitignore diff --git a/sdk-wasm-js/Cargo.toml b/sdk-wasm-js/Cargo.toml new file mode 100644 index 000000000..ed838d355 --- /dev/null +++ b/sdk-wasm-js/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "solana-sdk-wasm-js" +description = "Solana SDK Wasm JS" +documentation = "https://docs.rs/solana-sdk-wasm-js" +version = "1.0.0" +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[package.metadata.docs.rs] +targets = ["wasm32-unknown-unknown"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[lib] +crate-type = ["cdylib"] + +[dependencies] +solana-instruction = { workspace = true, features = ["std"] } +solana-program = { workspace = true } +solana-sdk = { workspace = true } + +[target.'cfg(target_arch = "wasm32")'.dependencies] +console_error_panic_hook = { workspace = true } +console_log = { workspace = true } +js-sys = { workspace = true } +log = { workspace = true } +wasm-bindgen = { workspace = true } + +[lints] +workspace = true diff --git a/sdk-wasm-js/README.md b/sdk-wasm-js/README.md new file mode 100644 index 000000000..7d6f12cc1 --- /dev/null +++ b/sdk-wasm-js/README.md @@ -0,0 +1,15 @@ +
+
+
+
+