program-error: Remove solana-program usage#51
Conversation
#### Problem A few SPL programs use `spl-program-error`, but it brings in solana-program by default, which makes program-error definitions very heavy to include. #### Summary of changes Split up the usage of `solana-program-error` and `solana-decode-error`, parametrize them just like `solana-program` used to be. As part of this change, I *didn't* parametrize `solana-msg`, since that just resolves to a simple syscall. We could inline the syscall and avoid its usage entirely, but that seems a bit harsh. With this change, we go from building 192 crates to 40, and build times go from ~6.5s to ~2.2s on my machine. NOTE: This is a breaking change.
Yeah, I think wait to do this unless someone has a build issue with |
| num-traits = "0.2" | ||
| solana-program = "2.2.1" | ||
| solana-decode-error = "2.2.1" | ||
| solana-msg = "2.2.1" |
There was a problem hiding this comment.
This is actually almost a leaf dependency. It depends on solana-define-syscall, which is a leaf.
So, this should work for all versions past 2.2.1 for 2.2 SDK crates. It's 2.3 where we'll see how it behaves, and if we do semver right in the SDK repo, we should be good!
There was a problem hiding this comment.
Hehe I did think about doing that -- we could even just redefine the syscall directly in this crate 😈
| use spl_program_error_derive::*; | ||
|
|
||
| /// Example error | ||
| #[solana_program_error] |
| /// Struct representing the path to a `solana_decode_error` crate, which may | ||
| /// be renamed or otherwise. | ||
| pub struct SolanaDecodeError { | ||
| import: Ident, | ||
| explicit: bool, | ||
| } |
There was a problem hiding this comment.
I'll leave this up to you, since I don't feel strongly about it, but from what I can tell, the original struct and the anon_const_trick function could have been made reusable across the two attributes/imports, and it would have saved you a good amount of code. But on the other hand, the explicit structs per attribute make it a bit more readable.
There was a problem hiding this comment.
Yeah, I decided to go with total clarity over reuse... I'm hoping we don't have to do this too much more
Problem
A few SPL programs use
spl-program-error, but it brings in solana-program by default, which makes program-error definitions very heavy to include.Summary of changes
Split up the usage of
solana-program-errorandsolana-decode-error, parametrize them just likesolana-programused to be.As part of this change, I didn't parametrize
solana-msg, since that just resolves to a simple syscall. We could inline the syscall and avoid its usage entirely, but that seems a bit harsh.With this change, we go from building 192 crates to 40, and build times go from ~6.5s to ~2.2s on my machine.
NOTE: This is a breaking change.