Skip to content

program-error: Remove solana-program usage#51

Merged
joncinque merged 1 commit intosolana-program:mainfrom
joncinque:nosolanaprogram
Mar 3, 2025
Merged

program-error: Remove solana-program usage#51
joncinque merged 1 commit intosolana-program:mainfrom
joncinque:nosolanaprogram

Conversation

@joncinque
Copy link
Contributor

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.

#### 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.
@joncinque joncinque requested a review from buffalojoec March 3, 2025 10:26
@buffalojoec
Copy link
Contributor

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.

Yeah, I think wait to do this unless someone has a build issue with solana-msg.

num-traits = "0.2"
solana-program = "2.2.1"
solana-decode-error = "2.2.1"
solana-msg = "2.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha whoops. Thanks!

Comment on lines +53 to +58
/// Struct representing the path to a `solana_decode_error` crate, which may
/// be renamed or otherwise.
pub struct SolanaDecodeError {
import: Ident,
explicit: bool,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I decided to go with total clarity over reuse... I'm hoping we don't have to do this too much more

@joncinque joncinque merged commit c5c4c19 into solana-program:main Mar 3, 2025
23 of 24 checks passed
@joncinque joncinque deleted the nosolanaprogram branch March 3, 2025 16:26
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.

2 participants