dtolnay/cxx

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

Open

#1,299 创建于 2024年1月3日

在 GitHub 查看
 (0 评论) (2 反应) (0 负责人)Rust (4,472 star) (253 fork)batch import
help wanted

描述

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.

贡献者指南

#[cxx::bridge] doesn't apply #[cfg(not(feature))] · dtolnay/cxx#1299 | Good First Issue