microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.1k stars 473 forks source link

Simplify how extension code for `windows` crate works #3110

Closed sivadeilra closed 2 weeks ago

sivadeilra commented 2 weeks ago

This reduces the complexity between windows-bindgen and windows. This makes it much easier to write "extension" code for the windows crate, by reducing the number of places in the code you need to touch.

This also removes the need to run cargo run -p tool_bindings whenever you touch the extension code for the windows crate. You don't need to update the bindings if you're just working on the extensions. Instead, you just edit extension code, like normal Rust code.

The extension code has moved from .../bindgen/src/rust/extensions to windows/src/extensions. This puts the code much closer to the code that it extends. Also, the extension code is now just a normal set of Rust modules. This makes the language service (Rust Analyzer) work more naturally; refactoring and go-to-definition and such simply work, rather than pointing to source files that were generated by bindgen.

Since the extension code is now just normal Rust modules, I had to add a handful of use crate::Foo::Bar::BAZ; imports to each extension source file. This seems like a good thing; more signs that this is just normal code.

I've staged the changes in a set of commits. You can see how each piece of extension logic was moved, or you can view all the changes as a single set. The last commit applies rustfmt to the extension code. This wasn't happening before, since those files were not part of any module tree, so cargo fmt overlooked them.