Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

rename type by annotation #934

Open
virusdefender opened this issue Mar 20, 2024 · 2 comments
Open

rename type by annotation #934

virusdefender opened this issue Mar 20, 2024 · 2 comments

Comments

@virusdefender
Copy link

virusdefender commented Mar 20, 2024

it seems that cbindgen can only rename a type by writing config file like

[export.rename]
"Feature" = "MODULE_NAME_FEATURE"

if there are multi Feature types in different modules, the generated header file only contains the last type.

so, if cbindgen can write rename rule in annotations, the problem can be solved, for example

// in crate::a

/// cbindgen:export-rename=A_FEATURE
pub enum Feature {...}

// in crate::b

/// cbindgen:export-rename=B_FEATURE
pub enum Feature {...}

there are already some similar annotations in cbindgen like cbindgen:no-export cbindgen:eq-attributes=MY_ATTRIBUTES, i think it's not difficult to implement it.

@emilio
Copy link
Collaborator

emilio commented Apr 14, 2024

Yeah, sounds like a useful enhancement.

@bavalpey
Copy link

bavalpey commented Oct 21, 2024

I really need this. Right now, I am using FfiStr to manage passing strings across ffi boundaries (I haven't found a suitable alternative). However, cbindgen is outputting garbage when I try to pass around pointers.
For one, I have already renamed FfiStr to const char* in my cbindgen.toml. However, this does not play nicely at all with the *const renaming done by cbindgen. It ends up being const const char * which is wrong.

Not sure how to get around this other than with something that lets me completely rename the type that cbindgen will emit for a specific method argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants