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

Conversation

LucasSte
Copy link
Contributor

@LucasSte LucasSte commented Apr 11, 2025

Problem

solana-program and solana-sdk have both cdylib and rlib declared as crate types. Both crates are supposed to be used as libraries by other projects. This crate setting is specially problematic for SBF programs that import solana-program, since it does not permit us to run link-time optimizations:

   Compiling solana-program v2.2.1
error: lto can only be run for executables, cdylibs and static library outputs

error: could not compile `solana-program` (lib) due to 1 previous error

Summary of changes

  1. Since the cdylib and the rlib types are only here to be compatible with the wasm target for wasm-pack, I created a new crate solana-sdk-wasm to hold all the items necessary for such a target.
  2. Use only rlib for crate types in both solana-program and solana-sdk.
  3. Updated the CI jobs accordingly.
  4. Update the comments in program/src/lib.rs to correctly mention how to use the crate types.

Basic benchmark

This is not a comprehensive benchmark. I was just curious on the impact on a small Hello, Solana! program, like this:

entrypoint!(process_instruction);
fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    msg!("Hello, Solana!");
    Ok(())
}

These are the results:

No LTO: 18kb (18504 bytes) with 728 CUs consumed.
LTO enabled: 17kb (17576 bytes) with 638 CUs consumed.

@LucasSte LucasSte force-pushed the wasm-1 branch 3 times, most recently from 5777d50 to ff8edb4 Compare April 15, 2025 18:44
@LucasSte LucasSte requested review from joncinque and febo and removed request for joncinque April 15, 2025 20:24
@LucasSte LucasSte marked this pull request as ready for review April 15, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant