-
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
Remove Utc::now() and Local::now() on unsupported platforms #1567
Remove Utc::now() and Local::now() on unsupported platforms #1567
Conversation
`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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## 0.5.x #1567 +/- ##
=======================================
Coverage 93.99% 93.99%
=======================================
Files 37 37
Lines 16543 16544 +1
=======================================
+ Hits 15550 15551 +1
Misses 993 993 ☔ View full report in Codecov by Sentry. |
cc: @pitdicker |
I just investigated what the standard library does. It has a platform abstraction layer in the If we want to be consistent and only use I.e. only use |
I think |
@ramosbugs Do you want to update this PR to only make |
Sure. Do we still want |
This does seem like it will break Consequently, I think it would make sense to match the current list of targets supported by the standard library, and wait for issues to get filed after support is added for other targets in the future. Why wait for issues to get filed for supporting targets that are already supported by |
I don't think it's true that std will only ever add targets, but I see your point. Okay, let's add a similar expression to what std has, and please link to the current version of the std attribute so we can easily verify updates. |
On closer inspection, Support for Working on a PR with the following config logic: #[cfg(any(
unix,
windows,
target_os = "solid_asp3",
target_os = "hermit",
target_os = "wasi",
target_os = "xous",
all(target_vendor = "fortanix", target_env = "sgx"),
target_os = "teeos",
all(target_arch = "wasm32", feature = "wasmbind")
))] |
Oops, did I end up confusing
Cool! It should be part of rust 1.78. Given that it will be stable on 2024-05-02 I think you can already add it. We are definitely not going to release 0.5 before that time 🤣 (I hope this year though). |
Sounds good. I confirmed it's in the beta channel: https://github.com/rust-lang/rust/blob/beta/library/std/src/sys/pal/uefi/mod.rs#L35 |
Thank you @ramosbugs! |
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 theUtc::now()
andLocal::now()
functions from this crate's public interface altogether in unsupported WASM environments unless thewasmbind
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.This is a breaking change: WASM targets (other than Emscripten/WASI) that referenced
Utc::now()
orLocal::now()
would previously compile (then panic at runtime). Now they will fail to compile, which is the intended purpose of this PR.Fixes #1301.