dtolnay/cxx

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

Open

#1299 opened on Jan 3, 2024

View on GitHub
 (0 comments) (2 reactions) (0 assignees)Rust (4,472 stars) (253 forks)batch import
help wanted

Description

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.

Contributor guide