jonasbb / serde_with

This crate provides custom de/serialization helpers to use in combination with serde's `with`-annotation and with the improved `serde_as`-annotation.
https://docs.rs/serde_with
Apache License 2.0
636 stars 67 forks source link

serde_with without android dependencies #741

Closed avahahn closed 4 months ago

avahahn commented 4 months ago

The serde_with crate uses chrono, which pulls in a number of android specific dependencies (which you can see in your top level Cargo.lock). Chrono does not need to pull these in if you arent using the Clock feature. It did not look like you were using offset::local so I think you can turn it off and ship without those dependencies. Doing so would lead to a smaller and faster to build library, which I would really appreciate. It was entertaining to find android centric dependencies in a CLI application I am developing.

For more information: https://github.com/chronotope/chrono/pull/1220

jonasbb commented 4 months ago

The local timezone is used, for example here. As such, disabling the clock feature would be a breaking change.

https://github.com/jonasbb/serde_with/blob/71d30991b79cba3771fc90fa33d809442529f4a8/serde_with/src/chrono_0_4.rs#L12

I would love to have a way to not use the clock feature and instead just "detect" that it is enabled somewhere else in the dependency tree. Something like #[cfg(accessible(...))], but that isn't anywhere near stabilization https://github.com/rust-lang/rust/issues/64797.

The timezone dependency is gated by [target.'cfg(target_os = "android")'.dependencies] so it will only be built if you target Android. Otherwise, it is just an entry in the lock file. Further, there is a cargo bug where it includes dependencies in the lockfile, even though they are disabled https://github.com/rust-lang/cargo/issues/10801. However, they are never compiled.