-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Extern blob is duplicated per platform #8509
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
Comments
I don't think it's generally true that a cdecl function on unix would be a stdcall function on win32. The win32 API specifically is stdcall, but the C api is still cdecl on windows. The win32/win64 split seems to be the place where this is a problem. This specific case could be solved with a macro. |
I wonder if MSVC uses the stdcall abi by default for normal user code. |
Making "stdcall" just mean 'the x86_64 abi ' on 64-bit platforms (the same way "cdecl" does) would also solve this problem, though I don't think we should. |
In fact, the ABI strings were designed to accommodate this. They can handle "platform-specific" ABIs, and trans will select the most appropriate. The current rules may need some tweaking, I don't remember how stdcall fits in etc. |
Hmm, well, the ABI strings aren't quite able to handle this example because they only distinguish by architecture, not by O/S. But perhaps we should fix this. In that case, one could put |
#10367 added |
Fix `unncessary_to_owned` false positive Fix rust-lang#8507 changelog: none
Usually C bindings requires different calling conventions per platform. For example, linux-32 usually uses cdecl, win-32 uses stdcall, and win-64 uses win64-specific convention.
So if we want to bind a function universally, we have to duplicate
extern ... {}
block for each platform, e.g.which is inconvenient and fragile. (I actually copied large extern blob for Mingw-w64 support (#8488).)
Other option is to generate binding code per platform from template. lifthrasiir/rust-opengles-angle uses the approach for egl binding.
I think it's good to add default calling convention keyword e.g. "platform" so that
where "platform" is interpreted as cdecl for linux-32, stdcall for win32, and so on. It would solve the issue for most cases.
EDIT: in irc @luqmana suggested to change
extern {}
(no abi specified) as platform-native callconv. (It's currently interpreted as "cdecl".) I think it's the best option.The text was updated successfully, but these errors were encountered: