Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@stegaBOB
Copy link
Contributor

@stegaBOB stegaBOB commented Oct 7, 2025

Disables default features for serde and borsh, enabing no_std support. That on its own shouldn't be a breaking change since neither dependency is re-exported. Also updated the address crate to support no_std with alloc/borsh/serde enabled.

I enabled no_std for the atomic-u64 crate, but atomics aren't actually supported on the bpfel-unknown-none target (unless I'm configuring something wrong, which very well could be the case). Can definitely remove that change, but still probably beneficial for other no_std targets that do support atomics.

To check that this all works I ran the following in the address crate:

cargo +nightly build -Zbuild-std=alloc,core --target=bpfel-unknown-none --no-default-features --features "decode, error, sanitize, syscalls, borsh, serde, bytemuck"

Closes #354

Copy link
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.

Thanks for your contribution! These are great changes.

I went through and made the suggested changes myself, especially for removing the alloc feature from the serde dep by default, since that was a bit painful to test. It should get CI to pass too: https://github.com/joncinque/solana-sdk/tree/borsh-no-std

Feel free to apply them if you want!

@stegaBOB stegaBOB requested a review from a team as a code owner October 11, 2025 16:28
Copy link
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.

Just one last nit, then just need to run ./cargo nightly fmt --all for the rustfmt issue.

Separately, I'm wondering how we can test this. The upstream BPF target is no-std, but also doesn't allow for alloc. I looked through different possible targets that are no-std but allow alloc, and found this list: https://github.com/search?q=repo%3Arust-lang%2Frust+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Frustc%5C%2F%2F+%22core+and+alloc%22&type=code

Of those targets, maybe we can add a check for building wasm32v1-none with no-default-features and alloc, borsh, and serde enabled. The other targets didn't seem as relevant, but we could always use another.

I took a stab at it with https://github.com/joncinque/solana-sdk/tree/alloc-ci -- let me know how it looks!

serde = ["dep:serde", "dep:serde_derive"]
sha2 = ["dep:solana-sha256-hasher", "error"]
std = ["decode"]
std = ["decode", "borsh?/std", "serde?/std", "alloc"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can you add a comment above this saying to remove the enabling of alloc during the next breaking release?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure we'd want this. I think std should probably enable alloc as well

Copy link
Collaborator

Choose a reason for hiding this comment

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

We're going to break up a few of these features, but it's true that it might be odd to need to enable both separately. What do you think @febo ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, I think we should enable alloc when std is enabled – feels like it would be the expected behaviour since the std includes alloc.

@stegaBOB
Copy link
Contributor Author

Separately, I'm wondering how we can test this. The upstream BPF target is no-std, but also doesn't allow for alloc. I looked through different possible targets that are no-std but allow alloc, and found this list: https://github.com/search?q=repo%3Arust-lang%2Frust+path%3A%2F%5Esrc%5C%2Fdoc%5C%2Frustc%5C%2F%2F+%22core+and+alloc%22&type=code

Are you certain this is the case? If you add alloc with -Zbuild-std=alloc,core, targeting bpfel-unknown-none seems to work fine

cargo +nightly build -Zbuild-std=alloc,core --target=bpfel-unknown-none --no-default-features --features "decode, error, sanitize, syscalls, borsh, serde, bytemuck"

@joncinque
Copy link
Collaborator

Are you certain this is the case? If you add alloc with -Zbuild-std=alloc,core, targeting bpfel-unknown-none seems to work fine

That's much smarter, let's do that. Can you add another line in check-no-std.sh that also runs that command?

@stegaBOB
Copy link
Contributor Author

That's much smarter, let's do that. Can you add another line in check-no-std.sh that also runs that command?

Done @joncinque!

Copy link
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.

Sorry, one last bit, then we can land this!

Copy link
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.

Thanks for your contribution, looks great to me! We'll also need an ok from @anza-xyz/tx-metadata

Copy link
Contributor

@apfitzge apfitzge left a comment

Choose a reason for hiding this comment

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

looked at tx-metadata crates. the functional change seems fine.

curious about the practice of Cargo formatting in this repo - there are a few lines that seem to be changed without reason. Is this not formatted as part of CI somehow? seems like different formatter settings could cause a lot of annoying churn if not.

@joncinque
Copy link
Collaborator

curious about the practice of Cargo formatting in this repo - there are a few lines that seem to be changed without reason. Is this not formatted as part of CI somehow? seems like different formatter settings could cause a lot of annoying churn if not.

We run cargo sort on the workspace, but that only sorts dependencies, not feature declarations within dependencies. We'd need some separate tool to do that, and I haven't looked into it

@joncinque joncinque merged commit 73c19d7 into anza-xyz:master Oct 14, 2025
26 checks passed
@stegaBOB
Copy link
Contributor Author

curious about the practice of Cargo formatting in this repo - there are a few lines that seem to be changed without reason. Is this not formatted as part of CI somehow? seems like different formatter settings could cause a lot of annoying churn if not.

This was annoying me as well. I'm pretty sure I'm just using the defaults in vscode, so not super sure why it was messing things up

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.

Disable borsh default features

4 participants