-
Notifications
You must be signed in to change notification settings - Fork 534
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
Add initial support for the wasm32
arch
#287
Conversation
I've discussed this with one of the maintainers (Alex Chrichton), and with his blessing I've purged the dependency on the deprecated time crate in favor of folding its code into chrono. This enables further refactoring.
The little buggers snuck through.
While likely providing only incomplete support for WebAssembly, this commit opens up chrono for use on the wasm32 architecture.
Is there a way to return a
when trying to return a |
@oleid That functionality is not covered by this PR. |
Does this PR still support both stable rust and the non-clock / non-wasm-bindgen usecase? Cause that would very much mean that I can't use chrono anymore then. |
With this PR I can use chrono as I would have before, except compiling for WASM does not fail anymore, and the Does that answer your question? |
It does not. Can I use this with wasm32-unknown-unknown on stable Rust? And does this force using wasm-bindgen on me, which is not something I want, as I'm using it in the true "unknown" / "no-std" way. Not in the implicit "wasm32-unknown-web" way. If this works fine on stable rust and the wasm-bindgen dependency doesn't interfere with the "unknown" use case, then I'm fine with this change as is. |
Yes, this is the main point of this PR.
Yes, because as far as I can see it's pretty much the only way to interact with WASM without repeating the work done by
I'm not sure what you mean by this. |
The wasm32-unknown-unknown target should not imply compiling to the web. wasm has more use cases than that. Unfortunately at the moment Rust doesn't have a -web target, and lots of documentation seems to indicate that wasm-bindgen is how you use the -unknown target, but that's just one way of using it. This is similar to including std in a no-std target. The -unknown target explicitly does not target the web, so just like putting std in no-std breaks everyone's use case that isn't targeting std or in this case the web. However chrono already has a solution for this, the |
Then that also breaks wasm32-unknown-emscripten, which does not support wasm-bindgen afaik. |
This PR has been verified to work on both NodeJS and in any WASM-enabled browser (I tested Chrome and Firefox), the 2 places I needed to test. It is not feasible to test random personal projects of the "let's build a WASM interpreter" variety.
That is not possible, as something that does not even exist yet (i.e.
This is not currently implemented (at least consciously), but may well be doable with little effort. |
wasm32-unknown-emscripten was supported, and this PR breaks it.
That's not what wasm32-unknown-unknown not targeting the web implies. What it implies is that there's no environment you can reliably import from, because for example the actual binary part of the project decides which imports and exports exist and how they are named. This is a more than valid way to use the wasm32-unknown-unknown target that does not necessarily imply a "non-web wasm interpreter". This runs just fine in a browser or node.js. It just doesn't use wasm-bindgen which is just one of many flavors of generating the bindings. Another being stdweb, which probably gets broken by this PR too. Considering wasm-bindgen is just one of many ways of going about defining the imports / exports at this point in time, it should absolutely be gated by a feature flag that shouldn't be forced upon users. Chrono works just fine with stdweb and binary defined imports / exports right now, and you are breaking both of these use cases. It certainly makes sense to have better support for wasm-bindgen, but breaking every other use case is not the way to go at this point in time. |
Source? I've never seen or heard of this. Also, isn't the
Without any environment to import, there's no date/time source, especially on As for the millions of other possible configs, that's way outside the scope of this PR, which is essentially only concerned with making |
I'm not sure I can link any source. But I actively use it and it works fine. Emscripten just provides a libc that has all the functions necessary and the time crate and std just use libc.
That's what the clock feature is for. Chrono explicits wants to support use cases where there is no specific environment to get the time from. That doesn't mean you can't use chrono. You can still create time stamps from times sourced through other means in such a no-std like environment. Which in the wasm32-unknown-unknown use case would for example be through an explicit "get_time" like import created by the binary. The |
There's a difference between something being supported, and something working essentially by accident i.e. without the maintainer(s) intending to do so. For example, the former means that it should keep working lest it become a broken feature, but the latter does not. Compare the 2nd case to an internal API: you can use it and it'll work, but the risk of breakage is yours to take. As for the |
Okay, so I tested your branch against a few use cases and it seems wasm32-unknown-emscripten still compiles, but I didn't verify yet if wasm-bindgen has any negative effects that would break emscripten's bindings. It shouldn't be hard to make that target work again though, no matter whether intentionally supported by chrono or not. wasm32-unknown-unknown still compiles on stable without any trickery just fine too, except it adds a whole lot of symbols including one import that shouldn't be there, so I guess if you aren't willing to feature flag wasm-bindgen (which could even be on by default), then I'll probably contribute that. |
@jjpe The So as @CryZe said, this needs to be behind a feature flag, to allow for alternate uses of the |
FWIW: It would seem, that stdweb is going to be based uppon wasm-bindgen (or friends) eventually : rustwasm/team#226 |
@CryZe I encourage you to do so, as I'm currently unable to spend time coding and testing this. |
@CryZe @jjpe what are you currently using to verify that chrono works for you? Despite the fact that I'm very eager to merge this, I'm definitely not going to without any tests. I would like to verify that every If neither of you have time to actually write the tests for the entire wasm community then, if you point me at some things that you're using, that will help me get started. Thanks for the work and for everyone caring that everything still works! |
The PR is in fact a 2-parter:
As for what I've used so far to test, that would be a 20 KSLOC proprietary library that uses dates and times a lot, and must be able to target both native (with std) and wasm32. While I'm perfectly fine with adding tests in and of itself, I'm not sure what actually can be done: the new constructors would never execute on native hosts, and in fact chances are it would not even compile there. I could gate the new tests behind the wasm32 arch Got any ideas to solve that? |
There are two categories of test I would like to see:
Does that seem like it would catch major breakage? I would also prefer to not cause the |
What's the status of this? It would be nice to have Chrono work on wasm. Alternatively, are there any DT crates that work on wasm? Seems like this is worth being fixed, tests or not... The current version's failing as-is! |
Does anyone know what's going on with this? |
This feature has been released via 331. Thanks for everyone's work! |
Building on PR #286, this PR adds initial support to chrono for the wasm32 architecture.
Specifically, it adds wasm32-compatible versions of the
Local::now()
andUtc::now()
constructors.EDIT: merging this would allow this issue to be closed as well.