Sean1708 / rusty-cheddar

A Rust crate for automatically generating C header files from Rust source file.
http://sean1708.github.io/rusty-cheddar/
191 stars 25 forks source link

Provide more control over type names in generated headers #43

Open trombonehero opened 8 years ago

trombonehero commented 8 years ago

It would be handy if I could annotate types with the name I want the C header to use. This wouldn't work with functions (since the name in the header must correspond to the name in the library), but it would for types, since the thing we actually care about there is the ABI rather than the name.

As things stand today, I have to live with non-C-friendly type names (e.g., State, which is a recipe for trouble in C's flat namespace) or else I need to compromise on my Rust names (e.g., struct foolib_state). I'd like the ability to explicitly name my generated C types:

#[repr(C)]
#[cheddar(name=foolib_state)]
pub struct State {
    // ...
}

Alternatively (or also?), it would be great if I could tell rusty-cheddar how to automatically C-ify my names:

Cheddar::new()
    .expect(...)
    .prefix("foolib_")
    .convert_camel_cased_type_names(true)
    .run_build(...)
Sean1708 commented 8 years ago

I really like this idea, I'll have to give it some thought though. I think the former suggestion is better in the long run, but I don't think there's any way to do it on stable yet (since you'd have to register the attribute with the actual compiler). So I'll probably implement the second suggestion for now, then come back to the first one later if I can think of a good way to implement it.