This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Description
Chrono has been a major blocker for me actually moving fully over to the wasm32-unknown-unknown target. The time crate does not work on wasm32 for obvious reasons. So a lot of people pushed for a feature that conditionally brings in the time crate and just disables everything in chrono that uses the time crate. That sounds like it would solve the problem, but it doesn't actually work out in practice for crates that also need to support other targets. Because that means you need to selectively activate features based on the target that you compile to, but that's not something that cargo supports today. I thought it could be solved by possibly using additional cfg attributes in chrono to not bring in the time crate, but that doesn't work as cargo doesn't actually check to source code for what to compile. So I thought a build.rs would solve it, but that doesn't seem to work. My final solution was to just try this:
[features]
default = ["clock"]
clock = ["time"]
[target.'cfg(not(all(target_arch = "wasm32", target_os = "emscripten")))'.dependencies]
time = { version = "^0.1.36", optional = true }
but that seems to compile the time crate on the wasm32-unknown-unknown target regardless of it not being a dependency of that target. So it looks like there is nothing that could really be done on either the user's side or chrono's side to work around this cargo bug.