I stumbled upon a weird case... it's unlikely to appear in real code but rust supports it, so cbindgen should support it too.
example.rs
#[allow(unexpected_cfgs)]
#[no_mangle]
pub extern "C" fn foobar(a1: u32, #[cfg(feature = "baz")] a2: u32) -> u32 {
#[cfg(feature = "baz")]
{
a1 + a2
}
#[cfg(not(feature = "baz"))]
{
a1
}
}
cbindgen.toml
language = "C"
[defines]
"feature = baz" = "FEATURE_BAZ"
BAD example.h (generated)
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
uint32_t foobar(uint32_t a1, uint32_t a2);
What would be the preferred way to handle this case?
- generate multiple function declarations, each surrounded by an appropriate ifdef
- surround each optional argument with an appropriate ifdef
- apply a macro call to the optional argument text
- something else
I stumbled upon a weird case... it's unlikely to appear in real code but
rustsupports it, so cbindgen should support it too.example.rs
cbindgen.toml
BAD example.h (generated)
What would be the preferred way to handle this case?