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
By default, GCC targeting embedded platform enables the -fshort-enums flag which dynamically sizes enums based on the greatest value the enum contains. This results in enums being represented by 1/2/3 bytes rather than the platforms default of 4 bytes.
However, bindgen uses clang which doesn't use -fshort-enums by default and so always generates bindings to enums with a size of 4 bytes.
As a result, when structures containing enums are passed between Rust and C they are miss aligned as Rust expects 4 bytes for each enum but it could be represented in a smaller number of bytes from the C side of things.
There are a couple of solutions:
Don't use GCC as your default compiler and use the ARM Clang compiler instead
Add cfg.flag("-fno-short-enums"); to cc Build in lvgl-sys/build.rs script when using GCC which stops the default behaviour of shrinking enums when lvgl-sys is built
Add .clang_arg("-fshort-enums") to bindings Builder also in lvgl-sys/build.rs to make Clang in the bindgen to shrink enums in the same way
I'm not sure if any actions need to be taken off these findings, but I just wanted to put this here in case anyone else has a similar prolem.
The text was updated successfully, but these errors were encountered:
By default, GCC targeting embedded platform enables the
-fshort-enums
flag which dynamically sizes enums based on the greatest value the enum contains. This results in enums being represented by 1/2/3 bytes rather than the platforms default of 4 bytes.However, bindgen uses clang which doesn't use
-fshort-enums
by default and so always generates bindings to enums with a size of 4 bytes.As a result, when structures containing enums are passed between Rust and C they are miss aligned as Rust expects 4 bytes for each enum but it could be represented in a smaller number of bytes from the C side of things.
There are a couple of solutions:
cfg.flag("-fno-short-enums");
to cc Build inlvgl-sys/build.rs
script when using GCC which stops the default behaviour of shrinking enums when lvgl-sys is built.clang_arg("-fshort-enums")
to bindings Builder also inlvgl-sys/build.rs
to make Clang in the bindgen to shrink enums in the same wayI'm not sure if any actions need to be taken off these findings, but I just wanted to put this here in case anyone else has a similar prolem.
The text was updated successfully, but these errors were encountered: