Skip to content

Commit

Permalink
Expose rkyv features as features for chrono users.
Browse files Browse the repository at this point in the history
rkyv by default serializes usize as u32. This isn't ideal
on most modern platforms and unfortunately is configured through
a feature flag.

If we just set `default-features = false` in the rkyv Cargo
dependency, the crate fails to compile because all the size features
are mutually exclusive. On the other hand if we want to
e.g., change the serialization of usize to 64-bit and
we also want to use chrono this currently fails to compile
because chrono always enables rkyv/size_32.

This re-exports the relevant rkyv features so users can
choose which serialization to enable. The approach
is similar to what the ordered-float crate does:

https://github.com/reem/rust-ordered-float/blob/8111b345372632893af0b8aa12152f3dc7278aba/Cargo.toml#L37

Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>
  • Loading branch information
gz committed Dec 27, 2023
1 parent d7b4a82 commit f26895a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rust-version = "1.61.0"
name = "chrono"

[features]
# Don't forget to adjust `ALL_NON_EXCLUSIVE_FEATURES` in CI scripts when adding a feature or an optional dependency.
default = ["clock", "std", "oldtime", "wasmbind"]
alloc = []
libc = []
Expand All @@ -27,15 +28,20 @@ now = ["std"]
oldtime = []
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales"]
rkyv-validation = ["rkyv/validation"]
# Note that rkyv-16, rkyv-32, and rkyv-64 are mutually exclusive.
rkyv-16 = ["rkyv", "rkyv?/size_16"]
rkyv-32 = ["rkyv", "rkyv?/size_32"]
rkyv-64 = ["rkyv", "rkyv?/size_64"]
rkyv-validation = ["rkyv?/validation"]
# Features for internal use only:
__internal_bench = []

[dependencies]
num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.7", optional = true }
rkyv = { version = "0.7.41", optional = true }
rkyv = { version = "0.7.43", optional = true, default-features = false }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::OutOfRange;
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(
feature = "rkyv",
archive(compare(PartialEq)),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
Expand Down
2 changes: 1 addition & 1 deletion src/naive/isoweek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rkyv::{Archive, Deserialize, Serialize};
#[cfg_attr(feature = "rkyv", derive(Archive, Deserialize, Serialize))]
#[cfg_attr(
feature = "rkyv",
archive(compare(PartialEq)),
archive(compare(PartialEq, PartialOrd)),
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
Expand Down

0 comments on commit f26895a

Please sign in to comment.