microsoft / windows-rs

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

`windows-bindgen` should generate `no_std` bindings by default #3335

Open mwcampbell opened 3 weeks ago

mwcampbell commented 3 weeks ago

Since the windows crate recently gained support for using no_std while still supporting alloc, it would be useful to have a complete example of an executable or DLL built this way. I read in #3047 that some low-level components, including in Windows itself, use the crate this way. I understand if this is an impractical request because all the real examples are too tightly coupled to Windows's build system or other proprietary bits.

kennykerr commented 3 weeks ago

While we can probably add/update a sample, there's not really much to illustrate here beyond adding #![no_std] to your lib.rs or main.rs and taking it for a spin. The compiler should quickly point out what you might be missing.

kennykerr commented 3 weeks ago

Actually, I attempted to port a sample to use no_std and ran into a few minor issues so I'll use this issue to track those and then make sure we have test coverage and a working sample.

kennykerr commented 3 weeks ago

Note to self: sample_direct2d is a good test case for this.

mwcampbell commented 3 weeks ago

What I had in mind for a complete no_std sample was things like setting up a panic handler, allocator (if you've actually figured out a way to use no_std with alloc in user space), and any other bits that are required for non-trivial no_std projects on Windows.

kennykerr commented 3 weeks ago

If you mean the alloc crate then you can find various examples by searching this repo. It is used for allocation support under no_std.

If you mean a custom allocator then you may want to look at https://github.com/microsoft/windows-drivers-rs for examples.