-
Notifications
You must be signed in to change notification settings - Fork 73
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
base: master
Are you sure you want to change the base?
Conversation
a880ac3
to
2e6e1fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main change introduced in this PR is that people need to run wasm-pack
against your new package to get a binary that's usable in JS, and that should be the only breakage.
It's as if solana-sdk
had a binary output and a library output (like solana-gossip), but we're just factoring the binary part into a new crate.
This means we can keep all of the code as is, but just re-export functions from the new crate, along with instructions for building. Does that make sense?
I didn't quite get the idea. Can I still maintain the wasm-specifc code in the new crate, but then re-export it in Solana-program and in solana-sdk? Or is it the opposite? |
Ah, sorry it wasn't clear. The wasm-specific code should still live in the original crate, and the new crate just re-exports everything and can be built into a JS package with |
fbbc3d6
to
99e99ed
Compare
Based on the above, it looks like in order to run LTO, you need the
And yet, later, you are saying that You are saying that you do see a size reduction. So, I'm probably missing something. Or is it that the type of the dependent crates does not matter, and only the type of the final artifact matters? |
@ilya-bobyr The problem is the usage of multiple crate types together. A short answer is that dependencies should be The option The plan is to support LTO via cargo-build-sbf, in which case we need the correct configuration of crate types. Since most solana programs depend on our own library, setting it to rlib facilitates it. |
As per the discussion on Discord (https://discord.com/channels/428295358100013066/476811830145318912/1370445804078235908), I reverted the PR back to its original form. Let me know if there is any other feedback to be addressed. |
Problem
solana-program
andsolana-sdk
have both cdylib and rlib declared as crate types. Both crates are supposed to be used as libraries by other projects. This setting is specially problematic for SBF programs that importsolana-program
, since it does not permit us to run link-time optimizations:The problem lies in using cdylib and rlib together, since that prevents Rust from running LTO, when using Solana-program as a dependency. See rust-lang/rust#51009 for more information.
Summary of changes
solana-sdk-wasm
to hold all the items necessary for such a target.solana-program
andsolana-sdk
.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:These are the results:
No LTO: 18kb (18504 bytes) with 728 CUs consumed.
LTO enabled: 17kb (17576 bytes) with 638 CUs consumed.