Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 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 @@ -71,6 +71,7 @@ members = [
"sdk",
"sdk-ids",
"sdk-macro",
"sdk-wasm-js",
"secp256k1-program",
"secp256k1-recover",
"secp256r1-program",
Expand Down
8 changes: 1 addition & 7 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all-features = true
rustdoc-args = ["--cfg=docsrs"]

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["rlib"]

[features]
default = ["borsh"]
Expand Down Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -489,7 +495,6 @@ pub mod slot_hashes;
pub mod slot_history;
pub mod syscalls;
pub mod sysvar;
pub mod wasm;
Comment thread
LucasSte marked this conversation as resolved.

#[deprecated(since = "2.2.0", note = "Use `solana-big-mod-exp` crate instead")]
pub use solana_big_mod_exp as big_mod_exp;
Expand Down Expand Up @@ -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;
Comment thread
LucasSte marked this conversation as resolved.
pub use {
solana_account_info::{self as account_info, debug_account_data},
solana_clock as clock,
Expand Down
1 change: 1 addition & 0 deletions scripts/build-sbf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exclude_list=(
"presigner"
"quic-definitions"
"rent-collector"
"sdk-wasm-js"
"secp256k1-program"
"secp256r1-program"
"system-transaction"
Expand Down
10 changes: 3 additions & 7 deletions scripts/test-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
33 changes: 33 additions & 0 deletions sdk-wasm-js/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions sdk-wasm-js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<p align="center">
<a href="https://solana.com">
<img alt="Solana" src="https://i.imgur.com/IKyzQ6T.png" width="250" />
</a>
</p>

# Solana SDK WASM JS

Use the Solana SDK WASM JS crate to build a JS package with `wasm-pack` usable in Node or browser environments.
See the [Solana Program Crate](https://crates.io/crates/solana-program) instead for on-chain programs, and, the [Solana SDK Crate](https://crates.io/crates/solana-sdk) for client-side
applications.

More information about Solana is available in the [Solana documentation](https://solana.com/docs).

Still have questions? Ask us on [Stack Exchange](https://sola.na/sse)
File renamed without changes.
21 changes: 19 additions & 2 deletions program/src/wasm/mod.rs → sdk-wasm-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,24 @@
#![cfg(target_arch = "wasm32")]
#[deprecated(since = "2.2.0", note = "Use solana_instruction::wasm instead.")]
pub use solana_instruction::wasm as instructions;
use wasm_bindgen::prelude::*;
use {::log::Level, wasm_bindgen::prelude::*};
Comment thread
joncinque marked this conversation as resolved.
pub use {
solana_program::*,
solana_sdk::{
// These imports exist in both solana_sdk and solana_program, so we use
// direct imports to suppress ambiguous re-export warnings.
declare_deprecated_id,
declare_id,
entrypoint,
entrypoint_deprecated,
example_mocks,
hash,
program_stubs,
pubkey,
*,
},
};

// This module is intentionally left empty. The wasm system instruction impl can be
// found in the `solana-system-interface` crate.
pub mod system_instruction {}
Expand All @@ -15,7 +32,7 @@ pub fn solana_program_init() {

INIT.call_once(|| {
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init_with_level(log::Level::Info).unwrap();
console_log::init_with_level(Level::Info).unwrap();
});
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/farf/
/node_modules/
/package-lock.json
/target/
4 changes: 1 addition & 3 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all-features = true
rustdoc-args = ["--cfg=docsrs"]

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["rlib"]

[features]
# "program" feature is a legacy feature retained to support v1.3 and older
Expand Down Expand Up @@ -110,8 +110,6 @@ thiserror = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.1.1", features = ["wasm-bindgen"] }
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }
Comment thread
LucasSte marked this conversation as resolved.

[dev-dependencies]
solana-instructions-sysvar = { workspace = true, features = ["dev-context-only-utils"] }
Expand Down
1 change: 0 additions & 1 deletion sdk/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ extern crate self as solana_sdk;
pub use solana_message as message;
#[cfg(not(target_os = "solana"))]
pub use solana_program::program_stubs;
#[cfg(target_arch = "wasm32")]
pub use solana_program::wasm_bindgen;
pub use solana_program::{
account_info, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated, clock, config,
custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id,
Expand Down Expand Up @@ -67,7 +65,6 @@ pub mod signature;
pub mod signer;
pub mod transaction;
pub mod transport;
pub mod wasm;

#[deprecated(since = "2.1.0", note = "Use `solana-account` crate instead")]
pub use solana_account as account;
Expand Down
3 changes: 0 additions & 3 deletions sdk/src/wasm/keypair.rs

This file was deleted.

5 changes: 0 additions & 5 deletions sdk/src/wasm/mod.rs

This file was deleted.

3 changes: 0 additions & 3 deletions sdk/src/wasm/transaction.rs

This file was deleted.