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

v0.6 WASM runtime error: 'time not implemented on this platform' #52

Closed
lpotthast opened this issue Jul 15, 2022 · 11 comments
Closed

v0.6 WASM runtime error: 'time not implemented on this platform' #52

lpotthast opened this issue Jul 15, 2022 · 11 comments
Labels

Comments

@lpotthast
Copy link

When using v0.5 everything runs fine in my Yew-WASM-applications, targeting wasm32-unknown-unknown and the web. So the chrono implementation works.

When using v0.6 (with default features), creating a Ulid panics with 'time not implemented on this platform', as the time crate seems to call std::time functions.

Should I use a different set of features? I were not able to find anything to control this. Neither here nor in the time crate..

@dylanhart
Copy link
Owner

Please try v1.0. If that still doesn't work, sticking with v0.5 should be fine as there are no known issues there.

@lpotthast
Copy link
Author

1.0 does not work unfortunately.

time is guarded by the 'std' feature.

This means that I have to disable std in order to run on wasm.
But I do need the serde feature, which relies on std String, leading to compilation errors..

@dylanhart
Copy link
Owner

The grafbase fork looks like it may have a fix: https://github.com/grafbase/ulid-rs/tree/wasm32-unknown-unknown-js-sys-time

@lpotthast
Copy link
Author

Looks promising. It would be great to see these commits upstreamed to this crate!

@Ekleog
Copy link

Ekleog commented Jan 20, 2024

@dylanhart WDYT about upstreaming master...grafbase:ulid-rs:wasm32-unknown-unknown-js-sys-time ? The changes seem simple enough, and could help quite nicely with using this crate on wasm32

@Ekleog
Copy link

Ekleog commented Jan 21, 2024

Actually better than this: Using chrono::Utc::now() to generate the datetime would actually make ULID timestamps be UTC values, rather than localtime values. Currently, two machines in two different timezones generating ULIDs would not actually have them lexicographically sortable. Plus, chrono has a proper implementation on wasm32, so it would also solve this problem.

This would better match the intent of the spec at least (though it does not seem to actually enforce UTC), as this way the ULIDs would actually be universally lexicographically sortable.

Edit: I now notice how stupid I am to have forgotten that SystemTime.duration_since(UNIX_EPOCH) already returns UTC time even on windows machines. Sorry for the noise!

@jakubadamw
Copy link
Contributor

@lpotthast @dylanhart @Ekleog I opened a PR that does this a bit nicer than what we did in the branch that you had found. 🙂

@dylanhart
Copy link
Owner

WASM users, is there a good method of checking WASM support? I'd like to add something to the presubmit CI to check that support doesn't break again in the future.

@jakubadamw
Copy link
Contributor

@dylanhart a test compiled to wasm32-wasi and run with https://github.com/bytecodealliance/wasmtime should be short and simple. I can do it tomorrow if you could wait. 🙂

@jakubadamw
Copy link
Contributor

@dylanhart actually, I managed to do it now, these days it's simpler than I thought. Here's the PR.

@Ekleog
Copy link

Ekleog commented Feb 2, 2024

Awesome, thank you! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants