-
Notifications
You must be signed in to change notification settings - Fork 360
Description
Given the following files:
# cbindgen.toml
[defines]
"feature = feat" = "FEAT"
[parse.expand]
crates = ["test-rust"]
features = ["feat"]# Cargo.toml
[package]
name = "test-rust"
version = "0.1.0"
edition = "2021"
[features]
feat = []// lib.rs
#[no_mangle]
#[cfg(feature = "feat")]
pub extern "C" fn exported() {}Running RUSTUP_TOOLCHAIN=nightly-2025-02-25 cbindgen produces
#if defined(FEAT)
void exported();
#endifBut running RUSTUP_TOOLCHAIN=nightly-2025-09-12 cbindgen produces
void exported();Removing the crate from parse.expand.crates restores the preprocessor guard (but would break our real case where we do in fact have macros that expand to exported C functions).
Looking at the output of cargo-expand, presumably produced directly from -Zunpretty=expanded, this seems to be a real change in the behavior of rustc, which means cbindgen probably can't do anything about it. However, it's probably worth documenting at least. (Being able to manually mark an item as guarded by a flag would also be a nice mitigation for someone who really does need the guard; we'll probably just be careful not to invoke the cfg'd-out functions.)