-
Notifications
You must be signed in to change notification settings - Fork 720
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
Add an option to override the representation of enums #1907
Comments
Because that's what the underlying platform is using, see #1361. So that part of the report is invalid (MSVC is weird here :/). A callback or such to override the enum repr may be worth it as an option, but note that as soon as you do that (if you make it |
Bindgen seems to be doing the wrong thing based on the C standard. I understand that making things On the other hand, MSVC is not the weird one in this case. It is the Unix behaviour that seems wrong. First, lets look at the C standard for what type enums should be: In both cases you're looking for Section 6.7.2.2, paragraph 3 - Semantics. There it writes (and I quote directly here):
They always have type Beyond that, Modern C provides similar advice:
I'm not sure why |
Why is
As noted, a C |
Also #1966 is somewhat related to this. |
we could add a flag to switch between |
That would be great for my case, just another thing that works a little bit better cross platform without necessarily needing to regenerate bindings. Is there any reason not to make this option the default for rust style enums? |
I don't have strong arguments against enabling |
One "open question" that I see here is if we can use Apparently, C23 allows to specify the underlying type of an I'm not sure if there's another way this feature could break something or not. Edit: An alternative would be to leave this reasoning to the user . What I mean is we could use regular expressions so people can use |
Interesting caveat with the C23 syntax! I guess in those cases it's already determined.
I think this is pretty unlikely, and there are probably more cases the other way around where i32 is not the correct enum representation. Since the enum size is ABI defined (per the nomicon) and the size of c_int isn't fixed anyway (16 bits on avr and msp430, looking at the source), I don't think defaulting to |
I'll start working on this but I'll wait for @emilio's opinion on which should be the default. |
In https://github.com/nbigaouette/onnxruntime-rs I use bindgen in
onnxruntime-sys/build.rs
to generate bindings on different platforms (macos, linux, windows).The original C header file is https://github.com/microsoft/onnxruntime/blob/v1.5.2/include/onnxruntime/core/session/onnxruntime_c_api.h (which is quite large).
This header contains a couple of enums, for example
OrtLoggingLevel
that gets wrapper asu32
: https://docs.rs/onnxruntime-sys/0.0.9/onnxruntime_sys/type.OrtLoggingLevel.htmlBut on Windows, I get
i32
s for them (docs.rs doesn't contain windows values, yet).Because of this I have trouble creating an API that can work both on Windows an other platforms.
Input C/C++ Header
wrapper.h
onnxruntime_c_api.h
Bindgen Invocation
On macOS:
On Windows:
Actual Results
On macOS:
On Windows:
Using
--rustified-enum="*"
I get:Expected Results
Note how macOS gives me a
std::os::raw::c_uint
and Windows gives me astd::os::raw::c_int
(or#[repr(u32)]
vs#[repr(i32)]
) for the enum representation.Why does bindgen generates different code on macOS/Linux and Windows? Can I tell bindgen to use
std::os::raw::c_int
everywhere? Ori64
, or whatever else?Thank you!
The text was updated successfully, but these errors were encountered: