-
Notifications
You must be signed in to change notification settings - Fork 543
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
Should now
error on wasm (not on emscripten or wasi) without wasmbind?
#1301
Comments
The If I remember right We could remove But if an ecosystem is build on 'pretend you support some features so you can compile, but avoid actually using xyz', it seems chrono is following the conventions for that ecosystem. What do you think? |
I'm ok with how it is, I wanted to make it easier for newcomers, especially if wasmbind get's disabled by default #1164. |
First off, thanks for all the work maintaining this excellent crate! This issue came up in the
This may have been the case in the early WASM days, but this doesn't seem like a viable long-term approach. The current behavior is the equivalent of sprinkling Most of the recent deprecations and breaking changes to
All of these options would be breaking changes, although option 1 could be implemented without breaking changes by deprecating the Panicking at runtime is a foot gun, and the Rust ecosystem generally does its best to remove foot guns. |
@ramosbugs Thank you for the good comment. For 0.5 we are not going to enable the Would you be willing to make a PR for 2 or 3 against the 0.5.x branch? |
Reading #1164 and #1472, it seems like the motivation was to support WASM targets without the JS interface. Option 2 would break compilation for those targets when the default features (which include I'll work on a PR in the next week or so. |
Thank you! |
std::time::SystemTime::now() panics in WASM environments other than Emscripten (i.e., wasm32-unknown-emscripten) and WASI (e.g., wasm32-wasi). Since compilation errors are preferable to unexpected runtime panics, this PR removes the `Utc::now()` function from this crate's public interface altogether in unsupported WASM environments unless the `wasmbind` feature is enabled. This catches the case in which a user of the crate forgets to enable the `wasmbind` feature (see ramosbugs/openidconnect-rs#127 and ramosbugs/oauth2-rs#230) in build targets that require it. Fixes chronotope#1301.
`std::time::SystemTime::now()` panics in WASM environments other than Emscripten (i.e., wasm32-unknown-emscripten) or WASI (e.g., wasm32-wasi). Since compilation errors are preferable to unexpected runtime panics, this PR removes the `Utc::now()` function from this crate's public interface altogether in unsupported WASM environments unless the `wasmbind` feature is enabled. This catches the case in which a user of the crate forgets to enable the `wasmbind` feature (see ramosbugs/openidconnect-rs#127 and ramosbugs/oauth2-rs#230) in build targets that require it. Fixes chronotope#1301.
`std::time::SystemTime::now()` panics in WASM environments other than Emscripten (i.e., wasm32-unknown-emscripten) or WASI (e.g., wasm32-wasi). Since compilation errors are preferable to unexpected runtime panics, this PR removes the `Utc::now()` function from this crate's public interface altogether in unsupported WASM environments unless the `wasmbind` feature is enabled. This catches the case in which a user of the crate forgets to enable the `wasmbind` feature (see ramosbugs/openidconnect-rs#127 and ramosbugs/oauth2-rs#230) in build targets that require it. Fixes chronotope#1301.
I've written a program for wasm and everything worked.
After some time I decided to disable all default features on the dependencies.
I had to enable some features to get it to compile ("clock" for chrono).
But then it worked (it compiled and seem to work).
Though a call to
Local::now()
did now panics (was fine before, it calls something in std which always panics on my target).Now it's clear to me that I should have enabled the feature wasmbind.
But it would've been better if the
now()
function just was not available in my configuration.Removing the line
feature = "wasmbind",
in Utc::now() seems to have that effect.The result is that on wasm (no emscripten or wasi) with wasmbind the replaced function is used. And if not on wasm or with emscripten or wasi the std function is used. And on wasm (no emscripten or wasi) without wasmbind the function is not available.
Of course
Utc::today()
,Local::now()
andLocal::today()
have also to be disabled in that case, the following does just that.This would be of course a breaking change.
And there are probably other targets which also always panic (though I don't know).
I can try to write a PR if that is wanted.
Edit:
As an alternative or first step, all the mentioned functions could be marked as deprecated with a comment which says that it will always panic (of course only for the problematic configuration).
Example:
The text was updated successfully, but these errors were encountered: