Skip to content

Use windows-bindgen to replace windows-sys with generated bindings? #119

Open

Description

@djc

windows-sys is a large crate (a 2.4M download) with considerable churn. The windows-rs org also provides a windows-bindgen API that crates can use to generate their own bindings for the part of the API that they need, which trades some downstream complexity for maintenance complexity (although the latter is pretty limited in my experience). See nushell/nu-ansi-term#71 for an example.

Would you be open to something like this for errno? It seems like a good fit to me.

Activity

  1. sunfishcode commented on Oct 9, 2025

    @sunfishcode
    Collaborator

    rust-errno here is extremely small, but imagining what this would look like if many more crates did a similar thing, my concern would be that end users would have less visibility and control over what versions of the bindings their dependencies are using.

    Imagine there is a security bug in the windows bindings some day. These are unsafe FFI bindings so UB is possible. With windows-sys, then the maintainers would fix it and send notifications, and people can check if they're affected and update, just like any other library. If there are many libraries using windows-bindgen generated bindings, what does the process look like? The example in your link uses a dev-dependency, the windows-bindgen documentation says to use a build-dependency, and perhaps other projects do other things, and the process of figuring out what versions of the bindings one is using looks non-trivial. And once you've identified which dependencies are affected, you have to ask their maintainers to update them before you can update.

    I'm curious if anyone has looked into using windows-bindgen to generate general-purpose subsets of windows-sys. Perhaps a subset for "features that correspond to things in libc on Unix". Or "features used by widely-used Rust crates". It seems likely that such a library could be much smaller than windows-sys, and then perhaps could make sense for rust-errno and many other things to depend on.

  2. Jake-Shadle commented on Apr 27, 2026

    @Jake-Shadle

    I've opened #123 that just uses inline bindings with no external dependency whatsoever, this crate's needs are extremely simple (3 functions and 2 constants), it only took a couple of minutes to type them out and test them (though FWIW wine seems to use a different Incorrect function. message for the error code used in the check_description test which is kind of annoying).

    The bindings are incredibly simple and are easy to inspect and looking at the history of the windows.rs file, the usage of them has not meaningfully changed since they were introduced so the likelihood of there being churn is not high IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions