Skip to content

Improve fallback for no_std#146

Merged
febo merged 3 commits into
mainfrom
febo/nostd-fallback
Apr 30, 2025
Merged

Improve fallback for no_std#146
febo merged 3 commits into
mainfrom
febo/nostd-fallback

Conversation

@febo
Copy link
Copy Markdown
Collaborator

@febo febo commented Apr 29, 2025

Problem

Currently, the "fallback" panic handler and allocator set up creates different problems when using cargo test or cargo test-sbf. This happens since tests in general depend on the std and therefore create a conflict when the fallback tries to set up a panic handler or global allocator.

Solution

This PR improves the set up of the fallbacks by simply linking the std library instead of trying to set them up, avoiding conflicts if another library links the std. Note that the std is only linked in targets different than "solana", so no_std programs are not affected – e.g., they will continue to be no_std.

It also addresses a comment from #136, removing the need for feature(const_mut_refs) to use allocate_unchecked.

cc: @publicqi

Copy link
Copy Markdown
Contributor

@sonicfromnewyoke sonicfromnewyoke left a comment

Choose a reason for hiding this comment

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

tested locally, have no annoying errors

Copy link
Copy Markdown
Collaborator

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

This looks good to me!

I was worried about a case where someone wants to use a program crate as a dependency in a nostd environment that isn't Solana, then they would get std without knowing better.

This situation shouldn't happen though, since program entrypoints should only be enabled when building a Solana program, so I think we're all good!

Comment thread sdk/pinocchio/src/entrypoint/mod.rs
@febo febo merged commit 7fe6176 into main Apr 30, 2025
9 checks passed
@febo febo deleted the febo/nostd-fallback branch April 30, 2025 23:31
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.

3 participants