diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b08189ec..da967ccf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -466,10 +466,8 @@ jobs: grep -h -E "^self-test" "$RUNNER_TEMP/selftest.log" "$RUNNER_TEMP/selftest-audio.log" if [ "$shot_status" -ne 0 ] || [ ! -s app-linux.png ]; then echo "::error title=Screenshot failed (Linux)::exit status $shot_status"; exit 1; fi [ "$plain_status" -eq 0 ] && [ "$audio_status" -eq 0 ] - # Windows exits with code 0x87A after a run that passed (not yet - # explained, see engine/README.md), so the exit code is printed but not - # checked; a missing screenshot or self-test summary, or a failed check, - # fails the step. + # A non-zero exit code, a missing screenshot or self-test summary, or a + # failed check fails the step. - name: App — screenshot (Windows, WARP) if: runner.os == 'Windows' && steps.changes.outputs.run == 'true' timeout-minutes: 5 @@ -484,6 +482,7 @@ jobs: Get-Content shot-windows-stderr.txt "screenshot run exit code: 0x{0:X8}" -f $p.ExitCode if (-not (Test-Path app-windows.png)) { throw "no screenshot" } + if ($p.ExitCode -ne 0) { throw "the app exited with 0x{0:X8}" -f $p.ExitCode } # The full self-test under WARP takes about 30 minutes (the software # renderer is capped at two frames in flight so it no longer runs out of # memory), so pull requests skip it unless they carry the @@ -511,6 +510,7 @@ jobs: if (-not $line) { Get-Content selftest-windows-stderr.txt -Tail 30; throw "no self-test summary" } $line.Value if ($line.Groups[1].Value -ne $line.Groups[2].Value) { throw "self-test failures" } + if ($p.ExitCode -ne 0) { throw "the self-test passed but the app exited with 0x{0:X8}" -f $p.ExitCode } - name: Upload app screenshots and self-test logs if: steps.changes.outputs.run == 'true' && !cancelled() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b187e3bb..8244416f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -316,6 +316,7 @@ jobs: $p = Start-Process -FilePath (Join-Path $dir 'device-studio.exe') -ArgumentList '--state', 'reference-default', '--screenshot', $shot -NoNewWindow -Wait -PassThru "exit code: 0x{0:X8}" -f $p.ExitCode if (-not (Test-Path $shot)) { throw "the installed app did not render" } + if ($p.ExitCode -ne 0) { throw "the installed app exited with 0x{0:X8}" -f $p.ExitCode } - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: package-windows diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index 5d072a82..e24aa196 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -945,10 +945,41 @@ fn synth_test_state(device: dstudio_core::DeviceId) -> dstudio_core::Command { } fn main() { - if let Err(e) = run() { - eprintln!("device-studio: {e}"); - std::process::exit(1); - } + let code = match run() { + Ok(()) => 0, + Err(e) => { + eprintln!("device-studio: {e}"); + 1 + } + }; + exit_now(code); +} + +/// End the process with `code` once `run` has returned and everything it owns is dropped. +/// +/// On Windows a normal exit (returning from `main`, or `std::process::exit`) reported +/// 0x87A instead of our code after any run that had opened the window: something in the +/// graphics stack ends the process with its own code while its DLLs unload, with the wgpu +/// device still alive in Slint's thread-local backend. Nothing of ours is left to run at +/// that point (the project, settings and engine are closed inside `run`), so the process +/// is ended directly, which skips DLL unloading and gives the caller the real result. +#[cfg(windows)] +fn exit_now(code: i32) -> ! { + use std::io::Write; + unsafe extern "system" { + fn GetCurrentProcess() -> *mut std::ffi::c_void; + fn TerminateProcess(process: *mut std::ffi::c_void, exit_code: u32) -> i32; + } + let _ = std::io::stdout().flush(); + let _ = std::io::stderr().flush(); + // SAFETY: both calls take no pointers from us; the pseudo-handle is always valid. + unsafe { TerminateProcess(GetCurrentProcess(), code as u32) }; + std::process::exit(code) +} + +#[cfg(not(windows))] +fn exit_now(code: i32) -> ! { + std::process::exit(code) } /// AppKit adds Start Dictation, Emoji & Symbols and Enter Full Screen to any Edit and View diff --git a/engine/README.md b/engine/README.md index b6fa95ba..6c825ad7 100644 --- a/engine/README.md +++ b/engine/README.md @@ -136,9 +136,13 @@ without a GPU or audio device: on Linux under Xvfb with Mesa lavapipe (software are reported as skipped off macOS), as a required step; on Windows with WARP (DX12 software adapter) the same, also failing the job when a check fails (the full self-test runs on main, nightly and labelled pull requests that change -the app; see docs/building.md): the screenshot renders and the self-test passes, but the -process exits with code 0x87A after the run (not yet explained; macOS/Linux -exit 0), so CI prints that exit code and checks the summary line instead. +the app; see docs/building.md): the screenshot renders, the self-test passes and the +exit code is checked on all three systems. On Windows the app ends its process directly +once `run` has returned (`exit_now` in `crates/dstudio-app/src/main.rs`): with a normal +exit, any run that had opened the window reported 0x87A instead of our code. The code is +set after `main` returns, while the process unloads its DLLs, with or without audio, a +screenshot or presented frames; a run that exits before the window exists returns 0. +Seen with WARP on the hosted runner; not yet checked on a real GPU. Debug builds of the app abort at exit on every OS (pre-existing: wgpu-core's debug-only lock tracing runs in a TLS destructor when Slint's thread-local backend drops the wgpu queue), so CI uses a release build. Screenshots and logs are uploaded as artifacts.