cbindgen
cbindgen copied to clipboard
Extern "C" functions being re-exported
We have an application that is part Rust, part C. We use extern "C" {
to define C functions to Rust. However, cbindgen
appears to re-export these back out. Short of listing all these in the exclude list, can they still be ignored?
We still want to export Rust functions that are declared extern so our C code can bind to them.
Note: When just extern {
is used these C functions are not re-exported, but we'd like to use as many rustfmt
defaults as possible, which rewrites these to extern "C"
.
Can you annotate them on the source with /// cbindgen:ignore
?
Comment /// cbindgen:ignore
actually works but it would be nice to ignore those by default.
Can you annotate them on the source with
/// cbindgen:ignore
?
This works on the module level, but not just on an extern "C" {}
block which would be more useful.
I think the bigger question is why extern "C" {}
and extern {}
are treated differently by cbindgen? And why export functions defined this way anyways, presumably they're in a C header already. Our use case is to create C bindings for a C app to use our Rust code. We don't need cbindgen to re-export definitions of extern functions.
Happy to look at a fix if there is not a specific reason for the current behaviour.
I think this works now.
extern "C" {
fn foo();
}
/// cbindgen:ignore
extern "C" {
fn bar();
}
Generates only foo. As for why extern {} and extern "C" {} are different, that's cbindgen being overly restrictive.