-
Notifications
You must be signed in to change notification settings - Fork 532
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 standalone code generation support for the Rust Standard Library #2439
Conversation
Looks great! Just a couple of issues:
Also just a quality of life thing but the reason for grouping functions in the same extern block was because of how linking libraries works. Currently rustc will read all the #[link(name = "kernel32")]
extern "system" {
pub fn SetLastError(dwerrcode: WIN32_ERROR) -> ();
}
#[link(name = "ws2_32")]
extern "system" {
pub fn WSACleanup() -> i32;
}
#[link(name = "kernel32")]
extern "system" {
pub fn DeleteFileW(lpfilename: PCWSTR) -> BOOL;
} In this example |
All the more reason to switch those handles to Anyway, I've address the main feedback - do check that I got it right. Collapsing the extern blocks is a little more involved but will get to that next. The way the Rust compiler creates these enormous link command lines is quite frustrating. |
Yeah tbh with my libstd hat off I don't really disagree. But with my libstd hat on there's enough controversy around it that I can't really push such a change through the standard library until there's some kind of consensus (or near enough to it).
That's working great, thanks! |
OK, so previously the bindings were sorted by metadata name (including namespace) for stability but now its further sorted by the type names that actually appear in the generated bindings (irrespective of namespace). This makes it a little more readable. The imports are further sorted by library name before function name, so that they should all be grouped together and appear first. They aren't quite collapsed into shared extern blocks. The challenge there is that that would have to further group by calling convention but hopefully this is enough to trigger the compiler's deduplication. |
This is fantastic, thank you! I've now updated the std PR with the generated bindings. The imports are fine as they are. |
A targeted solution to manage some minor discrepancies between the
windows-sys
definitions and those required by the Rust Standard Library. Ideally we can reduce and eventually eliminate these differences over time, particularly onceraw-dylib
is ubiquitous.rust-lang/rust#110152