jamesmunns / nrf52dk-sys

A Rust Crate to develop on the Nordic nRF52-DK
MIT License
85 stars 19 forks source link

Fix compilation error from generated code (bindgen 0.31.3) #6

Closed anxiousmodernman closed 6 years ago

anxiousmodernman commented 6 years ago

It seems that the latest bindgen is emitting a u8 alias for values from this C enum, which includes negative ints:

https://github.com/jamesmunns/nrf52dk-sys/blob/master/nRF5-sdk/components/device/nrf52.h#L74-L126

There are a couple of strategies related to "bind gen did the wrong thing" in the bindgen docs. Since we need to match those numbers exactly we might need to provide our own Rust implementation.

The error: bindgen

anxiousmodernman commented 6 years ago

One way to deal with this is to "blacklist" the type in build.rs and provide our own Rust type alias for IRQn_Type to the Rust primitive i8. Not sure where to put the Rust code, yet.

anxiousmodernman commented 6 years ago

~I've been asked to open an issue on bindgen re: this.~ So I got some help in the servo IRC, and it seems that our own alias to c_schar is what bindgen is picking up.

Changing this to i8 makes the compiler happy. It seems like that should be fine.

anxiousmodernman commented 6 years ago

Update: definitely not fine. A lot of other enums values that should be u8 are affected, and critically it seems they're passed to functions that expect u8. The simpler route might be to leave mod ctypes alone but provide an i8 implementation of IRQn_Type.