-
Notifications
You must be signed in to change notification settings - Fork 58
Add no_std
support
#265
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
base: main
Are you sure you want to change the base?
Add no_std
support
#265
Conversation
There was a problem hiding this 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 } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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+.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're committing to a slow but steady thiserror 2
upgrade now, fine to take it in via this pull request. Would it make sense to force the thiserror/std
feature when gpu-allocator/std
is enabled? I have not read up on the features that it provides, nor weighed the advantages of forcing the feature on versus having downstream users lack std
capabilities on returned thiserror
types unless they take a dependency with "std"
feature on thiserror
themselves.
Almost forgot to mention: can you please drop the
I don't think a one-off |
a22352a
to
eb9e04c
Compare
|
c5b70f0
to
f2a6bfb
Compare
There was a problem hiding this 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.
There was a problem hiding this 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.
Accidentally posted "Approved" instead of "Comment"
a315296
to
541e814
Compare
edaf69e
to
541e814
Compare
There was a problem hiding this 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.
ef44339
to
e896fab
Compare
95587a0
to
c4da9ba
Compare
0b6904c
to
b0b38a9
Compare
d45044d
to
6fd4a3a
Compare
I'm thinking of raising the MSRV unconditionally, that seems a lot less tricky to users than pretending it's |
82655c3
to
790f7a7
Compare
commit 790f7a7 Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 22:13:17 2025 +0200 CI: Ensure MSRV of `std` and `no_std` are tested independently commit fdf945c Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 22:10:10 2025 +0200 Test `visualizer` feature with `std` requirement separately from `no_std` commit dab3bb6 Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 22:07:26 2025 +0200 README: Remove manual reflows commit 6fd4a3a Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 21:43:44 2025 +0200 Revert "update `CI`" This reverts commit e896fab. commit c7e3c3c Merge: c3e2d51 0c5fc95 Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 21:42:56 2025 +0200 Merge remote-tracking branch 'origin/main' into no-std-support commit c3e2d51 Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 21:28:57 2025 +0200 Revert `version = ""` addition where not needed commit 477b6c5 Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 21:36:43 2025 +0200 Fix greedy match that would truncate a trailing `, default-features ... "` commit b37c69f Author: Marijn Suijten <[email protected]> Date: Thu Jun 12 21:32:39 2025 +0200 release: Fix unescaped `{` (otherwise treated as repetition quantifier) commit f93b1da Author: CrazyboyQCD <[email protected]> Date: Thu Apr 17 09:04:22 2025 +0800 update `README` commit b0b38a9 Author: CrazyboyQCD <[email protected]> Date: Thu Apr 17 08:49:37 2025 +0800 update `release.toml` commit d27a627 Merge: d73de57 642dc91 Author: CrazyboyQCD <[email protected]> Date: Thu Apr 3 09:05:10 2025 +0800 Merge branch 'main' into no-std-support commit d73de57 Author: CrazyboyQCD <[email protected]> Date: Thu Apr 3 08:59:50 2025 +0800 fix `CI` commit c4da9ba Author: CrazyboyQCD <[email protected]> Date: Thu Apr 3 08:42:56 2025 +0800 add `no_std` content in `README` commit 8bdedba Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 17:46:51 2025 +0800 fix lint commit e896fab Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 17:44:42 2025 +0800 update `CI` commit 0ab0c88 Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 17:40:17 2025 +0800 fix lint commit 10d0742 Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 17:35:05 2025 +0800 update missed `std` usages commit 66dbf08 Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 17:21:23 2025 +0800 add todo related with storing of `format_args!` outside `format!` commit 3d962a4 Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 09:06:09 2025 +0800 keep style of compile error the same commit 4123593 Author: CrazyboyQCD <[email protected]> Date: Wed Apr 2 09:03:37 2025 +0800 update missed `std` usages commit 541e814 Author: Marijn Suijten <[email protected]> Date: Tue Apr 1 12:54:04 2025 +0200 CI: Simplify and complete `matrix` setup commit 3e453ed Author: CrazyboyQCD <[email protected]> Date: Tue Apr 1 17:59:54 2025 +0800 emit compile error when none of `std` and `hashbrown` is enabled commit 694b6ff Author: CrazyboyQCD <[email protected]> Date: Tue Apr 1 17:24:56 2025 +0800 update `CI` with `no_std` commit 742a2ce Author: CrazyboyQCD <[email protected]> Date: Tue Apr 1 17:23:55 2025 +0800 document the `hashbrown` feature in `Cargo.toml` commit 39abe59 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 27 09:41:57 2025 +0800 update `CI` for `std` environment commit 578ada0 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 27 09:37:05 2025 +0800 prefer using `hashbrown`'s collections when `std` and `hashbrown` are both enabled commit 457411a Author: CrazyboyQCD <[email protected]> Date: Thu Feb 27 09:30:58 2025 +0800 simplify memory leak logging commit 3e00364 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 27 09:14:16 2025 +0800 remove empty line and reorder import commit d59fe26 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 27 09:09:24 2025 +0800 restore trailing comma commit f2a6bfb Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 10:50:51 2025 +0800 make `std` feature conflict with `hashbrown` in compile error and gate `free_list_allocator` by feature commit 4c45a01 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 10:27:19 2025 +0800 reorder mod in allocator module commit d1caf98 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 10:17:14 2025 +0800 format backtrace ahead by feature instead of duplicated log statements commit a4d3463 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 09:54:11 2025 +0800 reorder imports and mods commit 51e8723 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 09:46:52 2025 +0800 add non_exhaustive for `AllocatorDebugSettings` for backward compatible commit 3cee15f Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 09:43:13 2025 +0800 fix typos in deps commit 4d7b668 Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 09:43:01 2025 +0800 revert formatting of `Cargo.toml` commit 48be63c Author: CrazyboyQCD <[email protected]> Date: Thu Feb 13 09:35:20 2025 +0800 add clippy lints for `no_std` maintenance commit eb9e04c Author: CrazyboyQCD <[email protected]> Date: Wed Feb 12 16:20:03 2025 +0800 replace `std::*` with `core::*` or `alloc::*` commit e3ca7fb Author: CrazyboyQCD <[email protected]> Date: Wed Feb 12 16:19:21 2025 +0800 remove `std::backtrace::Backtrace` in `no_std` commit 8f853b0 Author: CrazyboyQCD <[email protected]> Date: Wed Feb 12 16:03:09 2025 +0800 add `no_std` feature compile error commit fbc57a3 Author: CrazyboyQCD <[email protected]> Date: Wed Feb 12 16:02:29 2025 +0800 add `default-feature = false` to some deps, `std` feature and `hashbrown`
790f7a7
to
e0a278c
Compare
I've squashed everything down into a single commit because our branch protection requires every individual commit to have been signed. Even if squash-merging will squash and resign the entire PR with GitHub's "web workflow" signature anyway 🤷 Since I contributed to and approve the final result, it makes sense for me to sign such a final result (but not individual commits) :) |
Should we go ahead and merge this? |
No description provided.