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

Bug: windows-bindgen should recursively emit items #2407

Closed
Jake-Shadle opened this issue Mar 30, 2023 · 2 comments · Fixed by #2416
Closed

Bug: windows-bindgen should recursively emit items #2407

Jake-Shadle opened this issue Mar 30, 2023 · 2 comments · Fixed by #2416
Labels
enhancement New feature or request

Comments

@Jake-Shadle
Copy link
Contributor

Jake-Shadle commented Mar 30, 2023

Which crate is this about?

other (please share in the comments)

Crate version

0.47.0

Summary

The new windows_bindgen::standalone function added in #2396 requires one to list the full namespaced name of the item one wants to generate bindings for, which is fine. However, I was surprised to find that items are not emitted recursively, but rather that every item needs to be listed individually to be bound.

For example, the user wants to emit bindings for SetConsoleTextAttribute

pub fn SetConsoleTextAttribute(
        hconsoleoutput: HANDLE,
        wattributes: CONSOLE_CHARACTER_ATTRIBUTES,
) -> BOOL;

But now they also need to add HANDLE, CONSOLE_CHARACTER_ATTRIBUTES, and BOOL to emit all the items necessary for the binding to typecheck, which gets incredibly tedious

Toolchain version/configuration

Default host: x86_64-unknown-linux-gnu
rustup home:  /home/jake/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-2022-08-29-x86_64-unknown-linux-gnu
nightly-2022-10-01-x86_64-unknown-linux-gnu
nightly-2022-10-29-x86_64-unknown-linux-gnu
nightly-2022-12-18-x86_64-unknown-linux-gnu
nightly-2023-01-30-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.65.0-x86_64-unknown-linux-gnu
1.66.0-x86_64-unknown-linux-gnu
1.66.1-x86_64-unknown-linux-gnu
1.67.0-x86_64-unknown-linux-gnu
1.68.0-x86_64-unknown-linux-gnu

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
wasm32-unknown-unknown
x86_64-pc-windows-msvc
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.68.2 (9eb3afe9e 2023-03-27)

Reproducible example

fn generate_bindings() {
    let apis = [
        "Windows.Win32.System.Console.SetConsoleTextAttribute",
    ];

    let bindings = windows_bindgen::standalone(&apis);
    std::fs::write("src/windows_term/bindings.rs", bindings).expect("failed to generate bindings");
}

Crate manifest

[package]
name = "console"

[dev-dependencies]
windows-bindgen = "0.47"

Expected behavior

I expected the SetConsoleTextAttribute function to be emitted, as well as the type for HANDLE, CONSOLE_CHARACTER_ATTRIBUTES, and BOOL.

Actual behavior

Only the binding for the function was emitted, meaning the user must additionally specify each of the individual items used by (in this case) the function, but I assume it applies to other things like structs/unions etc.

Additional comments

No response

@Jake-Shadle Jake-Shadle added the bug Something isn't working label Mar 30, 2023
@kennykerr kennykerr added enhancement New feature or request and removed bug Something isn't working labels Mar 30, 2023
@kennykerr
Copy link
Collaborator

Yes, I thought this might be handy but wasn't sure how much of an issue it would be - thanks for confirming - will add this!

@kennykerr
Copy link
Collaborator

Here's the fix for this: #2416

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

Successfully merging a pull request may close this issue.

2 participants