Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_std support #265

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

CrazyboyQCD
Copy link

No description provided.

Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Nice to see gpu-allocator usable on no_std with relatively minor changes! Thanks for doing the setup work here.

Just not sure if we're happy to commit to this rather tricky list of mutually exclusive features here. Consider someone uses gpu-allocator in their library crate and sets default-features = false to make it compile with a minimal set and no_std-compliance by default. They now have to enable the hashbrown feature to get it to compile.
When some other application crate uses that library crate, and also uses gpu-allocator with std feature to get backtrace support, this will now no longer compile because those are mutually exclusive.
I've suggested a change to make the hashbrown and std features coexist.


Can you add these lints to ensure this'll be easier to maintain in the future:

 #![warn(
    clippy::alloc_instead_of_core,
    clippy::std_instead_of_alloc,
    clippy::std_instead_of_core,
)]

And update the CI to ensure that it tests both no_std as well as std: we can add these to the matrix in the check_msrv, test and clippy jobs.


Finally, I ended up not spending any comments on it but instead recommend you to undo a few unnecessary import reorderings with:

cargo fmt -- --config imports_granularity=Crate --config group_imports=StdExternalCrate

The output isn't ideal (you have to group visualizer mod+use back together for example) but at least the ordering is back in check: log goes separate from the std/core/alloc "standard libraries" for example.

Cargo.toml Outdated
thiserror = "1.0"
presser = { version = "0.3" }
log = { version = "0.4", default-feature = false }
thiserror = { version = "2.0", default-feature = false }
Copy link
Member

Choose a reason for hiding this comment

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

Keep thiserror at 1 for now instead of pushing this drive-by change?

Copy link
Author

Choose a reason for hiding this comment

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

std can be disabled in thiserror since v2, but its msrv is 1.81+ dtolnay/thiserror#373.

But we can use derive_more instead, its msrv is 1.75+.

Copy link
Author

Choose a reason for hiding this comment

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

@MarijnS95
Should we use derive_more for bumping lower MSRV?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm we still need to look into this. IIRC there was some pushback on bumping to thiserror in some of our other repos because the crate is used incredibly frequently and requires an update throughout many (of our) crates in the ecosystem.

OTOH I don't think we require them to match to compile our code, it's just a duplicate dependency we can take on in cargo-deny.

@MarijnS95
Copy link
Member

MarijnS95 commented Feb 12, 2025

Almost forgot to mention: can you please drop the chore: prefix from your commit messages? It's not used by this project and does not have any meaning in this context.

a routine task, especially a household one.

I don't think a one-off no_std conversion in a crate is considered a "routine task" 🙂

@CrazyboyQCD
Copy link
Author

msrv is required to bump to either 1.75+(if we switch from thiserror to derive_more) or 1.81+ to get CI work.

@CrazyboyQCD CrazyboyQCD marked this pull request as ready for review February 26, 2025 07:13
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Nice update!

Only two things remaining: the formatting of the reports is broken, please test your changes to these before pushing them. I've suggested how to fix this in one file.

The previous review contained a request to update the CI to ensure that we test both with and without these new feature combinations, that would be very helpful to prevent breakage going forward. Right now we always build with specific backends and --no-default-features, meaning neither "hashbrown" nor "std" (nor a combination) ever gets exercised properly.

MarijnS95
MarijnS95 previously approved these changes Apr 1, 2025
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Almost there 🤞. We just need proper and complete CI to ensure that the changes are correct as written, and most importantly: won't regress no_std support and feature combinations in the future.

@MarijnS95 MarijnS95 dismissed their stale review April 1, 2025 09:10

Accidentally posted "Approved" instead of "Comment"

@CrazyboyQCD CrazyboyQCD requested a review from MarijnS95 April 1, 2025 10:03
@CrazyboyQCD CrazyboyQCD force-pushed the no-std-support branch 3 times, most recently from edaf69e to 541e814 Compare April 2, 2025 01:01
@CrazyboyQCD CrazyboyQCD requested a review from MarijnS95 April 2, 2025 01:09
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

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

Nice! I trust you'll be able to follow up on the remaining CI errors so that we can merge this! Do you think support for no_std needs a nice shout-out (including how to use it with default-features = false and that "hashbrown" must be used?) in the README?

I'll meanwhile look into how far we are with a thiserror 2.0 migration in our dependency tree, that might be more useful than to switch crates.

@CrazyboyQCD CrazyboyQCD force-pushed the no-std-support branch 2 times, most recently from 2ea0db0 to a33f8b9 Compare April 2, 2025 09:32
@CrazyboyQCD CrazyboyQCD requested a review from MarijnS95 April 2, 2025 10:02
@CrazyboyQCD CrazyboyQCD force-pushed the no-std-support branch 2 times, most recently from 95587a0 to c4da9ba Compare April 3, 2025 00:59
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