Commit efa6c11
fix(cargo-wdk): use
Fixes #613
## Problem
When `cargo wdk build` encounters a compilation error, the error output
is hard to debug:
1. JSON wall — `--message-format=json` sends even the compiler
diagnostics as JSON to `stdout` instead of redirecting it to `stderr`.
So, compiler errors are not directly visible instead they are buried
deep in the output json. This is affecting test outputs because in case
of failures, the errors cannot be seen easily in the `json` output.
2. Redundant error content — `BuildTaskError::CargoBuild` wraps the full
`CommandError` (containing `stdout` JSON), even though the user may have
already seen the real compiler errors on `stderr` in real time.
## Fixes
The following changes fix the above problems:
1. Switch to `--message-format=json-render-diagnostics`
This option instructs cargo to render diagnostics from `rustc` directly
to `stderr` instead of putting it in the `json` output.
stdout: only machine-parseable JSON (artifacts, build-finished) — no
diagnostic messages
stderr: human-readable compiler errors and warnings, rendered by Cargo
(visible to the user in real time since stderr is inherited)
2. Omit `stdout` from `CommandError::CommandFailed` before returning
from `BuildTask`:
When cargo build fails, `BuildTask::run()` now maps the error to a new
instance of `CommandFailed` but with the `stdout` field set to
`String::new()` to avoid printing machine-readable (`json`) output on
the screen.
## Before
Running `kmdf_driver_cross_compiles_with_cli_option_successfully` test
after removing `aarch64-pc-windows-msvc` target:
<img width="947" height="572" alt="image"
src="https://github.com/user-attachments/assets/efb391d3-02e8-47fd-907e-91ffe5c1d4ba"
/>
_____
Compiler diagnostics not printed to `stderr`, instead it is buried in
the json output when `cargo wdk build` fails:
<img width="1547" height="822" alt="image"
src="https://github.com/user-attachments/assets/4a0cf5c0-a9d4-4a8c-be63-c1237d6ed835"
/>
_____
Output seen when tests fail due to compilation errors:
<img width="1936" height="1162" alt="image"
src="https://github.com/user-attachments/assets/ac4a5e53-5a95-483d-898c-0e751e790c36"
/>
## After
Running `kmdf_driver_cross_compiles_with_cli_option_successfully` test
after removing `aarch64-pc-windows-msvc` target:
<img width="1344" height="824" alt="image"
src="https://github.com/user-attachments/assets/f95f94a9-9076-46e3-a706-c07c7ca95b65"
/>
_____
Compiler diagnostics available on terminal:
<img width="1028" height="576" alt="image"
src="https://github.com/user-attachments/assets/39d6ba3f-5b6f-4fdb-bbb9-0b39c21874be"
/>
_____
Output seen when tests fail due to compilation errors:
<img width="1867" height="1231" alt="image"
src="https://github.com/user-attachments/assets/b282efcd-c748-4129-b2c1-4f5c6b297900"
/>
---------
Co-authored-by: Copilot <copilot@github.com>--message-format=json-render-diagnostics in the build command to render compiler errors instead of the plain json option (#645)1 parent 5748ea2 commit efa6c11
3 files changed
Lines changed: 68 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | | - | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
124 | 134 | | |
125 | 135 | | |
126 | 136 | | |
| |||
205 | 215 | | |
206 | 216 | | |
207 | 217 | | |
208 | | - | |
| 218 | + | |
209 | 219 | | |
210 | 220 | | |
211 | 221 | | |
| |||
266 | 276 | | |
267 | 277 | | |
268 | 278 | | |
269 | | - | |
| 279 | + | |
270 | 280 | | |
271 | 281 | | |
272 | 282 | | |
| |||
292 | 302 | | |
293 | 303 | | |
294 | 304 | | |
295 | | - | |
296 | | - | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
297 | 312 | | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
312 | 358 | | |
313 | 359 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1935 | 1935 | | |
1936 | 1936 | | |
1937 | 1937 | | |
1938 | | - | |
| 1938 | + | |
1939 | 1939 | | |
1940 | 1940 | | |
1941 | 1941 | | |
| |||
0 commit comments