Skip to content

Document that "defines" and "parse.expand" no longer work together with latest nightlies #1107

@jrose-signal

Description

@jrose-signal

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();
#endif

But 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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions