Repository navigation
Conversation
Replace the windows dependency with windows-core 0.100 and bindings generated by windows-bindgen 0.100 into src/bindings/generated.rs. GUIDs that the default metadata has no value for are defined by hand in src/bindings/mod.rs. - Raise the MSRV to 1.95, required by windows-core 0.100. - Add Device::as_raw/from_raw and AudioClient::as_raw/from_raw, taking and returning plain COM interface pointers. - Handle::as_handle returns a RawHandle. - Export the AUDCLNT_E_* and AUDCLNT_S_* codes, E_INVALIDARG, E_NOINTERFACE and E_POINTER as HRESULT. - get_audio_effects returns AudioEffect, set_category and set_option take StreamCategory and StreamOption, and the conversions to the raw Windows values are crate private. - Call GetChannelsPeakValues through the vtable, since the generated wrapper only has room for a single value.
The record_application example now finds the main process of the application with a PowerShell query, and takes the executable name as an optional argument. The old lookup could pick the parent of the main process, explorer.exe for instance, instead of the main process itself. simplelog is used without its termcolor feature, since only SimpleLogger is used. With both changes no build pulls in the windows or windows-sys crates.
The MSRV bump to 1.95 lets clippy suggest a let chain here.
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues and missing activation coverage remain unresolved.
4 open findings
What changed in this PR
Replaces the windows dependency with windows-core 0.100 and checked-in generated bindings, updating raw APIs, tests, examples, documentation, CI, and MSRV.
Changes:
- Adds filtered binding generation and generated Windows bindings.
- Migrates WASAPI code and tests to
windows-core. - Raises MSRV to Rust 1.95 and updates raw-pointer APIs.
Outstanding findings include two critical issues in PowerShell escaping and ReleaseBuffer, one moderate activation-coverage gap, and two documentation nits.
| File | Reviewed change |
|---|---|
tools/bindings/src/main.rs |
Binding generator |
tools/bindings/filters.txt |
Binding symbol filter |
tools/bindings/Cargo.toml |
Generator dependencies |
tests/public_api.rs |
Raw-pointer validation tests |
tests/device/support.rs |
HRESULT helper migration |
tests/device/raw.rs |
Raw-pointer and handle tests |
tests/device/main.rs |
Test module updates |
tests/device/errors.rs |
Error test migration |
tests/device/capability.rs |
Capability test migration |
tests/device/audioclient23.rs |
Client test migration |
tests/device/activation.rs |
Removed obsolete activation tests |
src/waveformat.rs |
Wave-format binding migration |
src/lib.rs |
Binding module registration |
src/events.rs |
Callback binding migration |
src/errors.rs |
Exported HRESULT constants |
src/dataranges.rs |
Kernel-streaming migration |
src/capabilities.rs |
Capability binding updates |
src/bindings/mod.rs |
Manual GUID definitions |
src/bindings/generated.rs |
Generated bindings |
src/api.rs |
Core API migration and raw accessors |
README.md |
API and MSRV documentation |
examples/record_application.rs |
PowerShell-based process lookup |
examples/playnoise_exclusive.rs |
Binding import cleanup |
examples/playnoise_exclusive_poll.rs |
Binding import cleanup |
Cargo.toml |
Dependency and MSRV changes |
.gitignore |
Generator target exclusion |
.github/workflows/ci.yml |
MSRV workflow update |
🧠 Review effort: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
set_get_eventhandle wrapped the event in a Handle only after SetEventHandle succeeded, so a failure leaked the event. Also match the session state constants directly in get_state, like the other conversions do.
A name with a quote in it broke the lookup script. Also report a failing PowerShell run instead of saying the process is not running.
With sysinfo gone the examples and tests build on 1.95 too.
Both appear in the public API, in data ranges, audio effects, session callbacks, initialize_mta and the AUDCLNT_E_* codes. Without the re-export a caller needs a windows-core dependency at exactly the crate's version to name them.
read_from_device_to_deque was the only release site left with an unwrap. Also drop the stale Rust 1.88 note for record_application.
The generated wrapper only has room for one value. Add a slice taking GetChannelsPeakValuesSlice next to the other metadata fixes in src/bindings/mod.rs, and forbid the generated method in clippy.toml, so a new caller can not use it by mistake. Add a device test for get_channels_peak_values, which nothing exercised.
The tests of ActivateAudioInterfaceAsync followed by AudioClient::from_raw, and of activating IAudioEndpointVolume through Device::as_raw, went away with the windows dev-dependency. Bring them back using bindings that tools/bindings now also generates into tests/device/bindings.rs, so the tests act like a caller with bindings of its own and still no build pulls in the windows crate. raw.rs uses the same bindings instead of hand written link! declarations.
Re-export windows_core::Error as WindowsError and the PCM and float subformat GUIDs, implement AsRawHandle for Handle, and mark AudioEffect non_exhaustive.
… several instances
…o date The generator now reads its manifest directory at run time, so a stale build can no longer write into another copy of the repo.
…nding types parse takes a *const c_void and the new as_raw returns one, while from_waveformatex and as_waveformatex_ref become crate private, since callers could not name the WAVEFORMATEX type they used.
…n a failed release read_from_device released the whole packet when the slice was too short, so the frames were lost and a retry with a larger slice never saw them. It now releases zero frames, which leaves the packet for the next read, and always reports DataLengthTooShort. read_from_device_to_deque returned an error from ReleaseBuffer after the packet was already in the deque. It now takes the packet back out first, so an error means that nothing was read.
…C effect type from lib.rs as_handle already changed its return type to RawHandle, so callers have to touch it anyway, and it was identical to as_raw_handle. Its documentation moves to the trait implementation. The AUDIO_EFFECT_TYPE_ACOUSTIC_ECHO_CANCELLATION re-export joins the other binding re-exports in lib.rs.
…t by stderr Windows PowerShell writes progress records to a redirected stderr, for example when it loads a module for the first time, so a successful lookup could be reported as a failure. The script now silences progress and stops on any error, and only a failed exit status counts as a failed lookup.
The lock file pins the generator, while the formatting comes from the rustfmt on PATH. Style edition 2024 keeps that stable across rustfmt releases, so the CI check needs no pinned toolchain, but a personal rustfmt.toml can still change the output.
…ormats with WaveFormat::parse read_from_device ignored an error from the zero frame release on a short read. It now returns that error, since the packet state is unknown after it. The doc says that a retry with the same slice fails the same way, and the always true guard around the final release is gone. The short read test now waits for a packet of more than one frame, since a one frame packet gives an empty slice. get_mixformat and is_supported read the returned format themselves, and only took it as extensible when cbSize was exactly 22. They now use WaveFormat::parse, which accepts a larger cbSize. The AudioClient::from_raw example now releases the caller's reference.
…or build in CI The generator builds into tools/bindings/target, which the existing cache does not cover, so the drift check compiled windows-bindgen from scratch on every run. It gets its own cache step, so that the key shared with device-tests.yml stays the same.
…dule The default metadata gives most constants as i32, so every use cast them to the u32 or u16 that the call or field takes. A single typed_consts macro in src/bindings/mod.rs now redefines them with that type, shadowing the generated glob import, and the casts at the call sites are gone. The public AUDCLNT result codes and SPEAKER positions use the same macro, in place of their two separate re-export macros. Their public types are unchanged.
Brings in master and the 0.27.0 version bump. Ports the new session GUID and display name and icon setters to the generated bindings, and keeps GetChannelsPeakValuesSlice for the peak values fix from master.
Brings in the reapplied WaveFormat comparison and Handle Send and Sync from #82, and the rebased 0.27.0 version bump. The Handle safety comment no longer links HANDLE, which is private here.
# Conflicts: # src/api.rs
|
It looks as if the 0.101 release of the windows crates brings a lot of breaking changes. I'll wait for that to land before finishing this. |
|
I was concerned about the large MSRV bump required for this change, so I opened an issue upstream to see if that could be addressed. Thanks for the good work here. |
Port the new code from master to the generated bindings: - add StringFromIID and DEVINTERFACE_AUDIO_RENDER/CAPTURE to the filters and regenerate, for new_default_device_client - GetActivateResult returns a bare HRESULT here, so the shared activate_iaudioclient helper checks it with .ok() - new_default_device_client builds the AudioClient directly, since from_iaudioclient is replaced by from_raw on this branch - doc links to the raw interface types become plain code spans
Both are pinned to windows-rs master at c614bab27346, since 0.101 is not released yet. - The generator drops .flat(), which is now the default, and uses .full() to keep the free function wrappers that return a Result. - Most interface methods now take the output as a plain pointer and return an HRESULT. The new private helpers out() and out_interface() turn those calls back into a Result. - The _Impl callbacks return an HRESULT, and the tests call the generated callback methods with a count and a pointer. - HANDLE, REFERENCE_TIME and VARTYPE are plain aliases now, and the unions take their C tag names. - The AUDCLNT_E_ codes come as HRESULT, the AUDCLNT_S_ codes still as an i32, and WAIT_OBJECT_0 as an NTSTATUS that is retyped to u32. - GetChannelsPeakValues takes a count and a pointer, so the slice wrapper and the clippy ban on the generated method are gone.
Structs with raw pointer fields now get a zeroed Default impl instead of the derive. No other change to the generated bindings.
The generated bindings are the same as from the pinned master commit.
Move to windows-core and windows-bindgen 0.101
The runtime crates of windows-rs 0.101 need Rust 1.85, so the 1.95 that windows-core 0.100 required is no longer needed. - Split the let chain in dataranges.rs into nested ifs. - Go back to chunks_exact_mut in playsine_autorouted, since as_chunks_mut needs 1.88. Clippy only asked for it because of the 1.95 MSRV. - Run the MSRV job on 1.85 and update the README.
Lower the MSRV back to 1.85
All wrappers except Device and DeviceCollection hold objects that implement IAgileObject or marshal with the free-threaded marshaler, so they can be used from any thread. Device and DeviceCollection stay !Send, since IMMDevice and IMMDeviceCollection are neither agile nor marshalable. - The safety contracts of Device::from_raw and AudioClient::from_raw require the object, and everything it hands out, to be agile. - New device tests check that the objects are agile, and that IMMDevice is not. - A compile time check in public_api.rs for Send and Sync. - Device::as_raw no longer says that the interfaces activated from the device are tied to its apartment, which they are not.
Activates a client from a device interface path, such as the Id of a WinRT DeviceInformation, so a caller enumerating with WinRT needs no completion handler of their own. - New playsine_winrt example, which finds the device purely through WinRT. Its bindings for MediaDevice and DeviceInformation are generated by tools/bindings into examples/playsine_winrt/bindings.rs, and need windows-future and windows-collections as dev-dependencies. - Device tests for shared and exclusive streaming and the bare endpoint id error, and a test that a path with a nul is rejected. - The README interop section and the from_raw docs point to it.
Add AudioClient::from_device_path
…-sync # Conflicts: # tests/device/bindings.rs # tests/public_api.rs
- agility() returns an Agility enum instead of a string - assert_agile no longer prints, the output was never shown - Explain that device_is_not_agile is the negative control - "in the apartment" rather than "on the apartment"
Make the wrappers around agile COM objects `Send` and `Sync`


This PR drops the umbrella
windowscrate and instead useswindows-coreplus bindings generated into the crate itself, which aligns with the current recommendation from Microsoft: libraries should depend on the focused crates and generate targeted bindings (e.g. withwindows-bindgen) for the APIs they need. The umbrellawindowsandwindows-syscrates are also lagging behind, they were not published at 0.100 and remain at 0.62.x, whilewindows-coreand friends are already at 0.100.src/bindings/generated.rsfromtools/bindings/filters.txt. A few GUIDs that the metadata lacks are defined by hand insrc/bindings/mod.rs.windows-core0.100.windowstypes in the public API. Raw COM access is throughDevice::as_raw/from_rawandAudioClient::as_raw/from_raw, using plain interface pointers.WaveFormat::as_rawandWaveFormat::parsetake untyped pointers too, andHandleimplementsAsRawHandle.AUDCLNT_E_*codes plusE_INVALIDARG,E_NOINTERFACEandE_POINTERare exported for matching onWasapiError::Windows.get_audio_effectsreturnsAudioEffect, andset_category/set_optiontakeStreamCategory/StreamOption.get_channels_peak_valuescalls the vtable directly, since the generated wrapper has room for only one value.