Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Optional function argument is not exported correctly #1037

Open
flaviojs opened this issue Jan 7, 2025 · 0 comments
Open

Optional function argument is not exported correctly #1037

flaviojs opened this issue Jan 7, 2025 · 0 comments

Comments

@flaviojs
Copy link
Contributor

flaviojs commented Jan 7, 2025

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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant