0.18.x: WASAPI build fails on Windows when the separate windows-core dep resolves to a different minor than windows
Summary
On Windows, cpal 0.18.0 and 0.18.1 (crates.io) can fail to compile in dependency graphs where windows-core is reachable at 0.62.x (for example, alongside Tauri). Since 0.18.0, cpal declares windows and windows-core as two separate Windows-target dependencies, both ranged >=0.61, <=0.62. cpal's own source only ever uses windows::core::... (for example, #[windows::core::implement]), and the windows crate already re-exports windows_core (pinned to 0.61.x). The separate windows-core dependency is therefore effectively redundant, and when it resolves to a different minor line than the windows crate's own windows-core, the #[implement] types stop satisfying their traits.
Error (Windows, cargo build)
error[E0277]: the trait bound `IActivateAudioInterfaceCompletionHandler: windows_core::Interface` is not satisfied
error[E0277]: the trait bound `IMMNotificationClient: windows_core::Interface` is not satisfied
note: `IActivateAudioInterfaceCompletionHandler_Impl` is a "sealed trait", because to implement it you
also need to implement `windows::windows_core::unknown::IUnknownImpl`, which is not accessible
The affected types are the #[windows::core::implement] impls in src/host/wasapi/: IActivateAudioInterfaceCompletionHandler and IMMNotificationClient.
Resolved versions
In the failing graph, the lockfile resolves cpal's two Windows dependencies to different minor lines:
cpal v0.18.1
windows v0.61.3 (re-exports windows-core 0.61.2 as windows::core)
windows-core v0.62.2 (cpal's separate direct dependency)
cpal's #[windows::core::implement] expands against the windows-core it links directly (0.62.2), while the _Impl traits it is implementing arrive via the windows crate's own windows-core (0.61.2). The two windows-core instances diverge, which is what the Interface / sealed IUnknownImpl errors above point to. That is the most likely cause from the symptom; I have not bisected the exact macro-vs-trait path.
Note on our setup
We had been pinned to an earlier master rev (reports as 0.18.0) that builds cleanly on Windows in the same tree, but that may simply be because its lockfile happens to resolve windows-core to 0.61.x. I have not confirmed the git rev's manifest differs from the published crate, so I am not claiming a manifest regression. What is clear: the separate windows-core dependency is new to the 0.18.x line (0.17.3 declared only windows), and published 0.18.0 and 0.18.1 carry identical windows / windows-core declarations.
Possible fix
Since cpal's source only references windows::core::..., the simplest fix may be to drop the separate windows-core dependency entirely and rely on the windows crate's re-export, which guarantees a single coherent windows-core. If a direct windows-core dependency is needed, constraining it to resolve in lockstep with windows (rather than an independent >=0.61, <=0.62) would prevent the divergence.
Minimal repro
A graph that pins windows to 0.61.x while leaving windows-core free should reproduce it: a crate depending on cpal 0.18.1 plus windows = "=0.61.3" (and something pulling windows-core 0.62.x), built for x86_64-pc-windows-msvc.
Happy to test a fix or pre-release on macOS, Linux, and Windows.
Thanks, will add this to an upcoming release for some quick v0.18 fixes.
I think we're gonna have to bite the bullet and pin to one specific windows and windows-core minor version (real pity that windows doesn't re-export what we need from windows-core).
Question though why we shouldn't pin to 0.62 then instead of 0.61? That's what the versions would normally float to with cpal v0.18, so shouldn't be SemVer-breaking.
Thanks so much for jumping on this, and for maintaining cpal in the first place. Really appreciate it.
Good question on 0.61 vs 0.62. For standalone cpal, 0.62 is the natural float and totally fine. The reason 0.61 is the safer anchor for downstream is our specific situation: we are in a Tauri 2.x app, and Tauri's stack (tao, wry, webview2-com) holds the windows crate at 0.61.x. So we cannot move windows up to 0.62. If cpal pinned to windows / windows-core 0.62, it would become unsatisfiable in any Tauri 2.x tree, or force a cascading windows bump on everyone downstream. Pinning to 0.61 keeps cpal usable across the current windows-rs 0.61 ecosystem that Tauri 2.x sits on, while still coexisting fine with 0.62 crates elsewhere.
That said, you know the trade-offs far better than I do. If most of the ecosystem has already moved to 0.62, that may well outweigh our case. Either way, thank you for picking this up so quickly.
That context about Tauri is helpful, thanks.
To challenge your conclusion that 0.61 may be the way to go:
- Looking at crates.io download stats, it seems like v0.62 has overtaken v0.61 even though being younger.
- To the point of becoming "unsatisfiable", like you say isn't it possible to mix & match both versions (though at the cost of significant bloat)?
- Hasn't webview2-com already moved to v0.62 - which should unblock tauri picking it up?
Appreciate you digging into this.
You're right on the resolution model, and webview2-com has indeed moved. The download-stat picture needs one split, though. I checked each point rather than assuming this time:
1. Mix and match: you're correct, "unsatisfiable" was the wrong claim. Cargo happily resolves semver-incompatible minors side by side, so a cpal pinned to 0.62 inside a Tauri 2.x tree resolves fine. The real cost is duplication when both minors end up selected for the same target (the windows stack is not small), not a failed resolution. For what it's worth, our own lockfile already carries windows-core 0.61.2 and 0.62.2 simultaneously, though a target-aware cargo tree shows the actual Windows build graph (cpal + tao + webview2-com) sitting entirely on 0.61.2 today.
2. Download stats: true for windows-core, not yet for windows. windows-core 0.62.x has overtaken 0.61.x cumulatively (~70M vs ~60M). The windows crate itself has not: 0.61.x is still well ahead (~38M vs ~11.5M for 0.62.x), though 0.62 is much younger and climbing. So I agree on ecosystem direction, but the headline "0.62 has overtaken" only holds for windows-core so far.
3. webview2-com: correct, with a timing wrinkle. webview2-com 0.39.x moved to windows ^0.62 back in March. But the latest wry (0.55.1) still requires webview2-com ^0.38 and windows ^0.61, and tao (0.35.3) is also on ^0.61. So a stock Tauri 2.x tree still resolves the webview stack to 0.61 today, even though the webview2-com side is already unblocked for a future wry/tao bump.
Updated take: what actually broke us was windows and windows-core floating to different minors, not the specific minor. Any coherent same-minor pin fixes the bug. 0.62 is the reasonable long-term anchor given where things are heading; 0.61 avoids temporary duplication for current Tauri-stack users until wry/tao catch up. Either works for us, and we're unblocked in the meantime via our lockfile pin, so I'd defer to your judgment on which side of that trade cpal wants.
One small thought for the release notes: whichever pin you choose, a line like "if you see IUnknownImpl / implement-macro type errors, check that windows and windows-core resolve to the same minor" would probably save the next person a debugging session.
Thanks again for the quick turnaround on this.
PR up at #1244. It's borderline SemVer-breaking.