Repository navigation
Description
Goal
Give reld's native (wild-derived) engine properly colorized diagnostics, matching lld's conventions. Color handling goes through one helper that behaves correctly on each platform (Windows vs everything else) and is controlled by --color-diagnostics[=always|never|auto] / --no-color-diagnostics.
Current state (main @ fcecfdb)
- Parsing: the flags are parsed (
crates/reld-core/src/args/elf.rs:1102-1120) and only flipcolored's global override. - Colored output today: only two diagnostics are colored, and neither matches lld:
error.rs:208printsreld: \e[31merror\e[0m: …. The colon is outside the colored span, and theCaused by:chain is plain.error.rs:108printswarning:in yellow; lld uses magenta.
- Always plain:
bridge.rs:406,bridge.rs:1097(engine routing log),bridge.rs:1121(bridge killed by signal) andcrates/reld/src/main.rs:29(DHAT dump failure). - Auto mode checks the wrong stream.
coloredenables color when stdout is a terminal, but reld writes diagnostics to stderr. Reproduced both ways:reld missing.o 2>err.logfrom a terminal writes escape codes intoerr.log.- With stderr on a terminal and stdout redirected, reld prints no color.
- Windows: nothing switches on ANSI rendering in the console.
colored::control::set_virtual_terminalwouldn't fix it: in colored 3.1.1 it targets the stdout handle, ignores API errors, and always returnsOk. - Early errors: diagnostics emitted before the flag is parsed ignore it.
- Tests: nothing covers color.
Reference output, captured locally:
ld.lld: ^[[0;31merror: ^[[0mcannot open nonexistent.o: No such file or directory
ld.lld: ^[[0;35mwarning: ^[[0munknown -z value: unknownzopt
reld: ^[[31merror^[[0m: Failed to open input file `nonexistent.o`
Design
1. crates/reld-core/src/diagnostic.rs: the colorization helper (same on every OS)
pub enum ColorChoice { Always, Never, Auto }
pub enum Severity { Error, Warning, Note }
pub fn set_color_choice(choice: ColorChoice); // last flag wins
pub fn render(severity: Severity, message: &str) -> String;
pub fn emit(severity: Severity, message: impl std::fmt::Display);- Deciding once: the on/off result is computed once and cached. It is also mirrored into
colored::control::set_override, so existingcoloredoutput (sym-info indiagnostics.rs) follows the same decision. - The decision is a pure function that tests can check on any OS:
should_color(choice, env, stderr_terminal). The first matching rule wins:- an explicit
always/neverflag; CLICOLOR_FORCEset and not0turns color on;NO_COLORset and non-empty turns it off;TERM=dumbturns it off;- otherwise, color when the platform helper reports that stderr can render ANSI.
- an explicit
- Styling copies lld: the
reld:prefix stays plain;error:is red andwarning:is magenta, with the colon and space inside the colored span;Caused by:lines stay plain.
2. reld_core::platforms::term: the platform helper (per #137, no OS-specific cfg outside platforms/)
pub enum StderrTerminal { NotATerminal, Ansi }
/// Probe stderr and, where the OS needs it, switch on ANSI rendering. Called at most once.
pub fn prepare_stderr_for_ansi() -> StderrTerminal;- Unix, macOS, illumos, other unix, WASI: return
Ansiifstd::io::stderr().is_terminal(), otherwiseNotATerminal. Nothing needs switching on. - Windows has three cases:
- Real console (conhost or Windows Terminal).
GetConsoleMode(STD_ERROR_HANDLE)succeeds, so callSetConsoleMode(mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING).- If that works, return
Ansi. - If it fails (a console too old for ANSI), return
NotATerminal, so reld prints plain text instead of raw escape codes. - Don't restore the old mode at exit; cargo and git don't either.
- If that works, return
- MSYS2/Cygwin/mintty terminal.
GetConsoleModefails butis_terminal()is true, and these terminals render ANSI natively, so returnAnsi. - File or pipe. Return
NotATerminal.
- Real console (conhost or Windows Terminal).
alwayson Windows still attempts case 1, so forced color renders whenever possible.
3. Wiring
- Early flag scan:
Args::newscans argv for the color flags (last one wins) before full parsing, so argument-parsing errors respect the flag. - Parser entries: the existing entries in
args/elf.rscallset_color_choice, so the flags remain native. - Default and inheritance: anything printed before a choice is set uses
Auto, and forked children inherit the decision. - Call sites to move onto
diagnostic::emit/render:error.rs:108(WarningDisplay) anderror.rs:208(report_error)bridge.rs:406,bridge.rs:1097andbridge.rs:1121(asNote)main.rs:29
Dependency approval (#88)
Approved by the repository owner (2026-09-17): reld-core may take windows-sys as a direct
[target.'cfg(windows)'.dependencies] entry, features Win32_System_Console and
Win32_Foundation, pinned to the version already resolved in Cargo.lock (0.61.2, pulled in by
colored), so no new crate enters the graph. ci/dependency-baseline.json is updated in the same
reviewed change. This approval covers no other crate.
The design above (the shared diagnostic helper plus platforms::term::prepare_stderr_for_ansi
with its three Windows cases) is also approved as specified.
Acceptance
- Table-driven unit tests for
should_colorcover choice × env × stderr terminal state, and run on all hosts. - Byte-exact
rendertests cover error, warning and note, with color on and off. - Integration test on Linux, macOS and Windows CI: with
--color-diagnostics=always, a native link error contains the colorederror:span. - Integration test: auto mode with stderr piped, and
--no-color-diagnostics, produce no ESC bytes. - An argument-parsing error honors
--no-color-diagnosticsplaced anywhere on the command line. - Every native
reld:diagnostic goes throughdiagnostic::emit/render. - Windows manual check: cmd, PowerShell, Windows Terminal and MSYS2 bash, each also with stdout redirected, show correct color and no raw escape codes.
- fmt, clippy (
-D warnings), the host-platform Dylint and the dependency-baseline check are green.
Activity
[-]route --color-diagnostics as no-op/native, never to lld (perf regression)[/-][+]native engine: real colored diagnostics for --color-diagnostics (not a no-op, never routed to lld)[/+]zackees commentedon Sep 17, 2026
Updated this issue's title and description with a new directive: add real colored diagnostics to the native engine rather than treating
--color-diagnosticsas a no-op (never routing it to lld still stands). The investigation found that auto mode keys off stdout instead of stderr, reproduced in both directions. It also found that only error and warning lines are colored today, with styling that doesn't match lld, and that no tests cover color. The previous description is superseded; it described #142's no-op/native state.[-]native engine: real colored diagnostics for --color-diagnostics (not a no-op, never routed to lld)[/-][+]feat(diagnostics): add colorized diagnostics to the native engine[/+]zackees commentedon Sep 17, 2026
Renamed and redirected: this issue is now just about adding colorized diagnostics to the native engine. The earlier no-op/routing framing is gone. The description has the design: a same-on-every-OS
diagnostichelper plus a platform helper inreld_core::platforms::termcovering the Windows console, MSYS and file/pipe cases. It also has the openwindows-sysdependency decision and the acceptance checklist.zackees commentedon Sep 17, 2026
Owner approved both the design and the direct
windows-sysdependency for reld-core (#88). Recorded in the description; implementation starting.