You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering you were interested in letting bindgen::Builder provide a HashMap<String, String>, or something similar, mapping the original name of a C-type to its Rust rust-bindgen generated binding. This would give a mapping like:
// C => Rust
"type_A" => "type_A" // for a typedef type
"struct type_B" => "type_B" // for a normal struct type
I could also build this mapping myself if the bindgen::callbacks::ParseCallbacks trait had a callback method providing both the "original" name and the final "binding" name but this is currently not the case.
Use case
I am working on a library that imports some structs from a C library using rust-bindgen, defines some functions that return the imported types and are made available to C using cbindgen through the cargo-c crate.
My issue is that the types in the function signatures exported by cbindgen are not the same as the one imported (see example): struct MySuperStruct becomes MySuperStruct in Rust and stay MySuperStruct when re-exported to C. This unnecessarily duplicates all type definitions.
This is however only partially a cbindgen issue since this happens because depending on whether the type was declared using a typedef or not. cbindgen has no way to know what the original name was. cbindgen however provides a way to rename types by manually providing a new name for some types, which works.
My goal would be to get the mapping from rust-bindgen and generate a rename config for cbindgen
(this is a feature request)
Hello,
I was wondering you were interested in letting
bindgen::Builder
provide aHashMap<String, String>
, or something similar, mapping the original name of a C-type to its Rustrust-bindgen
generated binding. This would give a mapping like:I could also build this mapping myself if the
bindgen::callbacks::ParseCallbacks
trait had a callback method providing both the "original" name and the final "binding" name but this is currently not the case.Use case
I am working on a library that imports some structs from a C library using
rust-bindgen
, defines some functions that return the imported types and are made available to C usingcbindgen
through thecargo-c
crate.My issue is that the types in the function signatures exported by
cbindgen
are not the same as the one imported (see example):struct MySuperStruct
becomesMySuperStruct
in Rust and stayMySuperStruct
when re-exported to C. This unnecessarily duplicates all type definitions.This is however only partially a
cbindgen
issue since this happens because depending on whether the type was declared using atypedef
or not.cbindgen
has no way to know what the original name was.cbindgen
however provides a way to rename types by manually providing a new name for some types, which works.My goal would be to get the mapping from
rust-bindgen
and generate a rename config forcbindgen
Example:
the C header
the Rust bindings from rust-bindgen
my Rust function
the C function generated by
cbindgen
Notice that the type loses the
struct
keyword here and thus requires an additional unwanted typedef / cast to the correct type.The text was updated successfully, but these errors were encountered: