feat(ui-windows-winui): render-backend dispatch seam + startup probe (#4680 step 3) - #4897
Conversation
…4680 step 3) Builds on the merged step-2 bootstrap probe (#4896). Add winui::backend, the single decision point the per-widget WinUI 3 mapping reads: active() returns RenderBackend::Fluent when the bootstrap probe is Ready, else RenderBackend::Win32. Register a CRT static initializer (.CRT$XCU, anchored with #[used]) that runs the probe at process start for any binary linking this staticlib - i.e. exactly the --target windows-winui builds, never the default --target windows builds (which don't link the crate) - so the first widget construction reads an already-resolved backend. PERRY_WINUI_DIAG prints the chosen backend at launch. The initializer never panics (runs before main). Verified on a Windows host without the SDK: the initializer fires in a linked binary ([perry-winui] render backend: win32 observed via PERRY_WINUI_DIAG), the .CRT$XCU section is present in the WHOLEARCHIVE'd perry_ui_windows_winui.lib, and active() mirrors the bootstrap verdict and is stable. Real Microsoft.UI.Xaml controls still need the WinAppSDK winmd projections + runtime and are the next step; today the seam always resolves to Win32. Default --target windows unaffected.
…#4680) The backend probe could say Ready/Missing but not *why* it was missing. Capture the bootstrap outcome detail (sentinels for DLL-missing / no-entry-point / success, otherwise the raw MddBootstrapInitialize HRESULT) and print it under PERRY_WINUI_DIAG: e.g. "render backend: fluent (bootstrap detail: ready)" or "win32 (bootstrap detail: MddBootstrapInitialize failed, HRESULT 0x80670016)". This made the step-2 success path verifiable against the real runtime: with the Windows App SDK 1.6 dev NuGet restored (bootstrap DLL next to the exe) and the DDLM/Main/Singleton runtime packages registered, initialize() flips from RuntimeMissing to Ready/fluent - so both arms of the merged MddBootstrapInitialize2 FFI (#4896) are now exercised. The 0x80670016 case was exactly a registered framework package with no DDLM, which the new diagnostic pinpoints. Adds a unit test for the detail formatter (pure function, environment-agnostic).
6990f12 to
d85578d
Compare
📝 WalkthroughWalkthroughAdds a bootstrap outcome cache ( ChangesWinUI Bootstrap Diagnostics and v0.5.1172 Release
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
CHANGELOG.md (1)
1-19: ⚡ Quick winAdd explicit file paths and expand validation notes per guideline.
The changelog entry is well-written but falls short of the coding guideline requirement for "detailed long-form root-cause writeups, file paths, and validation notes." Specifically:
- File paths: missing explicit list of changed files (e.g.,
crates/perry-ui-windows-winui/src/winui.rs,crates/perry-ui-windows-winui/src/lib.rs)- Validation notes: currently brief ("Verified on a Windows host without the SDK"); should detail the test cases, coverage, and edge cases actually validated (e.g., "Tests confirm:
active()mirrors bootstrap verdict and is stable; startup initializer fires correctly on Windows without the SDK;.CRT$XCUsection present in linked binary")📝 Suggested expansion
Replace lines 16–19 with something like:
Verified on a Windows host without the SDK: - `active()` mirrors bootstrap verdict and remains stable across calls - CRT initializer fires at process start in linked binaries - `.CRT$XCU` section is present in `WHOLEARCHIVE`'d `perry_ui_windows_winui.lib` - Backend resolves to Win32 when SDK is absent - `describe_init_detail()` formats HRESULT diagnostics correctly Files changed: - `crates/perry-ui-windows-winui/src/winui.rs`: outcome caching (`LAST_DETAIL` AtomicI32), sentinel constants, dispatch seam, CRT initializer - `crates/perry-ui-windows-winui/src/lib.rs`: crate-level docs for `winui::backend::active` seam🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@CHANGELOG.md` around lines 1 - 19, The changelog entry lacks the required explicit file paths and detailed validation notes per coding guidelines. Expand the validation section by replacing the brief "Verified on a Windows host without the SDK" statement with a detailed bulleted list documenting specific test validations, such as confirming `active()` mirrors bootstrap verdict and remains stable across calls, CRT initializer fires correctly at process start in linked binaries, `.CRT$XCU` section presence in the linked library, Win32 fallback behavior when SDK is absent, and `HRESULT` diagnostic formatting. Additionally, add a "Files changed" section explicitly listing all modified file paths with descriptions of their specific changes, including the core changes to `crates/perry-ui-windows-winui/src/winui.rs` (outcome caching via `LAST_DETAIL` AtomicI32, sentinel constants, dispatch seam, and CRT initializer registration) and `crates/perry-ui-windows-winui/src/lib.rs` (crate-level documentation for the `winui::backend::active` seam).Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@CHANGELOG.md`:
- Around line 1-19: The changelog entry lacks the required explicit file paths
and detailed validation notes per coding guidelines. Expand the validation
section by replacing the brief "Verified on a Windows host without the SDK"
statement with a detailed bulleted list documenting specific test validations,
such as confirming `active()` mirrors bootstrap verdict and remains stable
across calls, CRT initializer fires correctly at process start in linked
binaries, `.CRT$XCU` section presence in the linked library, Win32 fallback
behavior when SDK is absent, and `HRESULT` diagnostic formatting. Additionally,
add a "Files changed" section explicitly listing all modified file paths with
descriptions of their specific changes, including the core changes to
`crates/perry-ui-windows-winui/src/winui.rs` (outcome caching via `LAST_DETAIL`
AtomicI32, sentinel constants, dispatch seam, and CRT initializer registration)
and `crates/perry-ui-windows-winui/src/lib.rs` (crate-level documentation for
the `winui::backend::active` seam).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3f1bdb93-5f6c-4911-bf2a-fa062d1e729c
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
CHANGELOG.mdCLAUDE.mdCargo.tomlcrates/perry-ui-windows-winui/src/lib.rscrates/perry-ui-windows-winui/src/winui.rs
What
Implements the step-3 dispatch seam for #4680 (opt-in WinUI 3 / Fluent Windows target), building directly on the step-2 bootstrap probe merged in #4896.
Adds
winui::backend— the single decision point the per-widget WinUI 3 mapping reads — plus a process-startup probe so--target windows-winuibinaries resolve their render backend at launch.How
winui::backend::active() -> RenderBackend— returnsRenderBackend::Fluentwhen the Windows App SDK bootstrap probe (bootstrap::initialize()) isReady, elseRenderBackend::Win32. Cheap and stable (memoized by the bootstrap cache). Each XAML widget lands behind this check: build aMicrosoft.UI.Xamlcontrol onFluent, else delegate to the existing Win32 constructor..CRT$XCU, anchored with#[used]) registered in the crate runs the probe at process start for any binary that links this staticlib — i.e. exactly the--target windows-winuibuilds, and never the default--target windowsbuilds (which don't link the crate). So the first widget construction reads an already-resolved backend rather than probing lazily. It never panics (runs beforemain).PERRY_WINUI_DIAGprints the chosen backend at launch:[perry-winui] render backend: win32|fluent.Testing
cargo test -p perry-ui-windows-winui→ green (active_backend_matches_bootstrap_verdict,initialize_is_total_and_idempotent).active()mirrors the bootstrap verdict and is stable; off Windows it is alwaysWin32.PERRY_WINUI_DIAG=1emitted[perry-winui] render backend: win32..CRT$XCUsection (8 bytes — one initializer pointer) is present in the WHOLEARCHIVE'dperry_ui_windows_winui.lib(llvm-objdump --headers).Scope / not in this PR
Real
Microsoft.UI.Xamlcontrols need the WinAppSDK winmd projections + runtime (the stockwindowscrate at 0.58 ships only UWPWindows.UI.Xaml, not WinUI 3'sMicrosoft.UI.Xaml), so they're the next step. Today the seam always resolves toWin32. Win32 (--target windows) remains the default and is untouched.Summary by CodeRabbit
Release Notes
Chores
New Features