Repository navigation
feat(diagnostics): colorize native diagnostics behind one helper - #151
Merged
Merged
Conversation
…d#144) Diagnostics are now produced by `reld_core::diagnostic`, which decides once whether to color and formats every `reld: …` line. Errors are red and warnings magenta, with the colon and trailing space inside the colored span and the `reld: ` prefix plain, matching ld.lld byte for byte. Fixes the auto-detection bug: `colored` enables color when *stdout* is a terminal, but reld writes diagnostics to *stderr*. Redirecting stderr to a file from a terminal leaked escape codes into it, and redirecting only stdout dropped color from an interactive stderr. Auto mode now follows stderr, with NO_COLOR, CLICOLOR_FORCE and TERM=dumb honored; an explicit flag outranks all of them, and the last flag wins. Host terminal mechanics live behind the new `platforms::term` facade, so the #137 boundary still holds. Windows switches ENABLE_VIRTUAL_TERMINAL_PROCESSING on the *stderr* console handle (colored's helper targets stdout and ignores failures), reports MSYS2/Cygwin ptys as ANSI-capable since GetConsoleMode fails on them, and reports a console too old to accept the flag as plain so reld never writes raw escapes to it. Because the flags are applied by an argv pre-scan in `Args::new`, a diagnostic raised while parsing a later argument is colored as asked, which was impossible before. The routing log (`reld: engine=…`) keeps its exact text: ci/linker_modes.py and ci/consumer_acceptance.py parse it. Adds `windows-sys` as a direct reld-core dependency for the console calls, approved by the repository owner in reld#144 under the #88 policy, with the baseline updated. The version was already resolved through `colored`, so no new crate enters the graph. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #144.
Summary
Native diagnostics are now colorized. Every
reld: …line goes through the newreld_core::diagnostichelper, which decides once whether to color and formats the line. Errors are red and warnings magenta, with the colon and trailing space inside the colored span and thereld:prefix plain, matchingld.lldbyte for byte:The auto-detection bug this fixes
coloredturns color on when stdout is a terminal, but reld writes diagnostics to stderr. Both directions were wrong, and both are fixed:reld … 2>err.logfrom a terminalAuto mode now follows stderr and honors
NO_COLOR,CLICOLOR_FORCEandTERM=dumb. An explicit flag outranks the environment, and the last flag wins, as inld.lld.Platform helper
Host terminal mechanics sit behind a new
platforms::termfacade, so the #137 boundary still holds (no hostcfgoutsideplatforms/).prepare_stderr_for_ansihandles the three Windows cases:ENABLE_VIRTUAL_TERMINAL_PROCESSINGon the stderr handle.colored::control::set_virtual_terminalcould not be used: it targets the stdout handle, ignores API failures and always returnsOk, so it does the wrong thing whenever stdout is redirected.GetConsoleModefails on these named pipes, but they render ANSI themselves, so they report as ANSI.Unix, macOS, illumos, other unix and WASI just check whether stderr is a terminal.
Other changes
Args::new, so a diagnostic raised while parsing a later argument is colored as asked. That was impossible before.--color-diagnostics[=always|never|auto]/--no-color-diagnosticsstay native and never route to lld. The invalid-value error text is unchanged.colored's override, so the symbol-info printer follows it too.reld: engine=…) keeps its exact text, becauseci/linker_modes.pyandci/consumer_acceptance.pyparse it. The bridge signal message and the DHAT dump failure now go through the helper.windows-sysas a direct reld-core dependency for the console calls, approved by the repository owner in feat(diagnostics): add colorized diagnostics to the native engine #144 under the ci: reject unapproved Rust dependency additions #88 policy, withci/dependency-baseline.jsonupdated in the same change. The version was already resolved throughcolored, soCargo.lockgrows by one line and no new crate enters the graph.Validation (local, Linux host)
reld-core, 209 passed) cover the decision table (choice × environment × terminal), byte-exact rendering for error/warning/note with color on and off, flag-value parsing, and the argv pre-scan (both dash forms, last-flag-wins, invalid value ignored there).crates/reld/tests/color_diagnostics.rs(6 tests) runs the real binary with stderr piped: plain by default, forced color, explicit disable,NO_COLOR/CLICOLOR_FORCE, the magenta warning path, and argument errors honoring the flag.=alwayscolored through a pipe;--no-color-diagnosticsandNO_COLORplain on a tty;CLICOLOR_FORCEcolored through a pipe.cargo fmt --check,cargo clippy --workspace --all-targets -D warnings, the host-platform Dylint (default and--no-default-features),ci/check_dependencies.pyandci/tests(258 passed) are all green.x86_64-pc-windows-msvc(covers the new console code),aarch64-apple-darwin, FreeBSD, illumos, Android and WASI.proc-macro2's build script before reaching reld. CI's Phase 1 windows-msvc job covers it.🤖 Generated with Claude Code