dtolnay / cxx

Safe interop between Rust and C++
https://cxx.rs
Apache License 2.0
5.68k stars 322 forks source link

#[cxx::bridge] doesn't apply #[cfg(not(feature))] #1299

Open hombit opened 6 months ago

hombit commented 6 months ago

It looks like #[cfg(not(feature))] is ignored by #[cxx::bridge], so the marked field would always exist:

mod ffi {
    #[repr(u32)]
    enum Variant {
        #[cfg(not(feature = "v2"))]
        A,
        B,
    }
}

See this demo repo for a reproducible example.

#[cfg(not(feature))] is useful when a newer version of a C++ library dropped something, while we would like to support both new and old versions with Cargo feature flags.