starkat99 / half-rs

Half-precision floating point types f16 and bf16 for Rust.

Home Page:https://docs.rs/half/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build fails when selecting serde feature but not std feature

tspiteri opened this issue · comments

Build fails with this dependency setting:

[dependencies.half]
version = "2"
default-features = false
features = ["serde"]

Adding the "std" feature makes the build work.

[dependencies.half]
version = "2"
default-features = false
features = ["serde", "std"]

There are two possible solutions I can think of:

  1. Make the serde feature depend on the std feature. With rust 1.60 this would be simple; just add a new feature in Cargo.toml:

    [features]
    serde = ["dep:serde", "std"]

    But with earlier rust I didn't manage to get it to work. I tried to import serde with a different name e.g.

    [dependencies]
    serde_crate = { package = "serde", version = "1.0" ... }

    and then use serde_crate instead of serde in the code, or add

    #[cfg(feature = "serde")]
    extern crate serde_crate as serde;

    but that broke derive(Serialize). Maybe a manual implementation could replace the derive, or there's another fix, but I am completely unfamiliar with serde's derives.

  2. Otherwise features that are now gated with #[cfg(feature = "serde")] could be gated with #[cfg(all(feature = "serde", feature = "std"))] instead.

(Some serde stuff just depends on alloc not on std.)

Just hit this issue. Would appreciate a dot release on the 2.x channel to fix it.