Create solana-sdk-wasm-js crate#138
Conversation
a880ac3 to
2e6e1fa
Compare
joncinque
left a comment
There was a problem hiding this comment.
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. |
joncinque
left a comment
There was a problem hiding this comment.
Looks good to me! Just needs to fix the merge conflict, then we can land this
Thanks! I've just rebased the PR. |
Problem
solana-programandsolana-sdkhave 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-wasmto hold all the items necessary for such a target.solana-programandsolana-sdk.program/src/lib.rsto 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.