-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use alloc::vec::Vec instead of Vec for no_std support #4378
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.
Exposing an std
crate feature in web-sys
was a mistake to begin with I believe. Too late now unfortunately. This also prevents us from properly testing it in CI.
In any case, thank you for catching this!
Could you just add a changelog entry?
In that case; how about we just switch web-sys to be It wouldn't solve testability entirely but it'd mean we at least have two crates where std can't sneak in unnoticed |
So making |
That's stable in core now - but I just noticed the MSRV is Added changelog and made web_sys |
CHANGELOG.md
Outdated
@@ -67,6 +67,9 @@ | |||
* Internal functions are now removed instead of invalidly imported if they are unused. | |||
[#4366](https://github.com/rustwasm/wasm-bindgen/pull/4366) | |||
|
|||
* `web-sys` crate now fully works on `no_std`. |
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.
* `web-sys` crate now fully works on `no_std`. | |
* Fixed `no_std` support for all APIs in `web-sys`. |
It sounds like the std
Vec
usage was on purpose, it was just an oversight 😅!
Just for context: this is always a bug, because crate features have to be additive and they are not supposed to break compilation when you add a crate feature!
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.
Thank you and merry Christmas as well!
Self note: this is already covered by CI, because running |
#![cfg_attr(not(feature = "std"), no_std)] | ||
#![no_std] |
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.
This bit me while working on no_std
for Bevy (you can read about the efforts here). For future reference, if you do this:
#![no_std]
#[cfg(feature = "std")]
extern crate std;
You can have an std
feature without toggling the implicit prelude, which catches these kinds of import issues when compiling with all features.
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.
Uh, that's pretty neat!
Thanks, will keep this in mind!
Whilst
no_std
seems technically supported, in practice it's unusable with a bunch of web-sys features due to relying on the implicitstd::vec::Vec
in places. This fixes that by usingalloc::vec::Vec
explicitly, which works in both std and no_std.A quick test would be to
cargo check -p web-sys --no-default-features --features ImageData
- fails before this PR, succeeds after it.After this change, we don't actually use
std
anywhere withinweb-sys
- it could be permanentlyno_std
if so desired. That'd certainly help keep it no_std compatible in the future.