Skip to content

Create solana-sdk-wasm crate #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 16 additions & 7 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 @@ -86,6 +86,7 @@ members = [
"sdk",
"sdk-ids",
"sdk-macro",
"sdk-wasm",
"secp256k1-program",
"secp256k1-recover",
"secp256r1-program",
Expand Down
7 changes: 2 additions & 5 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,7 @@ arbitrary = { workspace = true, features = ["derive"] }
solana-logger = { 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 }

[dev-dependencies]
array-bytes = { workspace = true }
Expand All @@ -122,12 +119,12 @@ solana-pubkey = { workspace = true, features = ["dev-context-only-utils"] }
solana-sysvar = { workspace = true, features = ["dev-context-only-utils"] }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

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

[features]
default = ["borsh"]
Expand Down
18 changes: 10 additions & 8 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,21 @@
//!
//! ```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). When created a Rust project intended to be a program
//! ready for deployment, ues only the "cdylib" crate type.
//!
//! # On-chain vs. off-chain compilation targets
//!
Expand Down Expand Up @@ -512,7 +517,6 @@ pub mod syscalls;
pub mod system_instruction;
pub mod system_program;
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;
Expand Down Expand Up @@ -567,8 +571,6 @@ pub use solana_stable_layout as stable_layout;
pub use solana_sysvar::program_stubs;
#[deprecated(since = "2.2.0", note = "Use `solana-vote-interface` crate instead")]
pub use solana_vote_interface as vote;
#[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,
Expand Down
1 change: 1 addition & 0 deletions scripts/build-sbf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exclude_list=(
"quic-definitions"
"rent-collector"
"reserved-account-keys"
"sdk-wasm"
"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
npm install
npm test
File renamed without changes.
33 changes: 33 additions & 0 deletions sdk-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "solana-sdk-wasm"
description = "Solana SDK Wasm"
documentation = "https://docs.rs/solana-sdk"
version = "2.2.2"
authors = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
edition = { workspace = true }

[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 }
wasm-bindgen = { workspace = true }
log = { workspace = true }
js-sys = { workspace = true }

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

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["wasm32-unknown-unknown"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]
16 changes: 16 additions & 0 deletions sdk-wasm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p align="center">
<a href="https://solana.com">
<img alt="Solana" src="https://i.imgur.com/IKyzQ6T.png" width="250" />
</a>
</p>

# Solana SDK

Use the Solana SDK Crate to be consumed by Javascript libraries. Sse 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).

The [Solana Program Library](https://github.com/solana-labs/solana-program-library) provides examples of how to use this crate.

Still have questions? Ask us on [Stack Exchange](https://sola.na/sse)
File renamed without changes.
22 changes: 20 additions & 2 deletions program/src/wasm/mod.rs → sdk-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@
#![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::*};
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,
feature,
hash,
program_utils,
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 +33,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/
6 changes: 2 additions & 4 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,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 }

[dev-dependencies]
curve25519-dalek = { workspace = true }
Expand All @@ -192,12 +190,12 @@ solana-program = { workspace = true, features = ["dev-context-only-utils"] }
solana-sdk = { path = ".", features = ["dev-context-only-utils"] }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

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

[lints]
workspace = true
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 @@ -42,8 +42,6 @@ pub use solana_program::program_stubs;
// confusing duplication in the docs due to a rustdoc bug. #26211
#[allow(deprecated)]
pub use solana_program::sdk_ids;
#[cfg(target_arch = "wasm32")]
pub use solana_program::wasm_bindgen;
pub use solana_program::{
account_info, address_lookup_table, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable, clock, config, custom_heap_default, custom_panic_default,
Expand Down Expand Up @@ -97,7 +95,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.