Skip to content
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

Other calling conventions #979

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

novafacing
Copy link
Contributor

@novafacing novafacing commented Jun 28, 2024

This PR adds support for other calling conventions as discussed in #55 and #718. It adds an ABI field (instead of just an extern field) to Functions and adds a concept of Predefines which right now only contains the compiler/platform-specific #defines needed to make the calling conventions work nicely but may be useful in the future for other cases where something needs to look at all the code, then conditionally emit some lines at the top of the file.

This use case is very important to my work to adopt Rust for UEFI/firmware programming, since cbindgen is needed to integrate Rust into existing C codebases easily. Most of these environments define an explicit calling convention, which we need to be able to export from Rust code for interoperability.

@novafacing
Copy link
Contributor Author

Here's a godbolt with the generated headers (test cconv.rs): https://godbolt.org/z/MqPhhzqcf

There are a few compile errors which I intentionally left in (like requesting sysv64 on clang/gcc non-x86_64). I can change that behavior so a compile error is never emitted and a warning is instead if that's preferred.

@novafacing
Copy link
Contributor Author

Realized I had a misunderstanding about what the extern_decl flag was doing (toggling extern keyword in output). I put it back to how it was, so now that plays nice with the ABI detection and dispatching.

@novafacing
Copy link
Contributor Author

Documented the configuration option added for this feature. Should be ready to merge :)

@novafacing
Copy link
Contributor Author

novafacing commented Jun 28, 2024

Calling convention predefines are now emitted in a defined order, should actually be ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant