Skip to content

Line buffer compiler messages when possible #32486

Closed
@alexcrichton

Description

@alexcrichton

Cargo has long since been plagued with an issue like rust-lang/cargo#1198 where it executes the compiler in parallel but this can cause colors to get corrupted on the command line. The fundamental bug here is that Cargo is running rustc concurrently, but that's more of a feature than a bug, so let's try to explore other options!

One possible route to take was that we should line buffer as much as possible. With line buffering we can ensure that output may be interleaved, but it at least won't have corrupted colors. We could even go as far as to buffering entire diagnostics (which may span multiple lines).

The snag here is that this doesn't work on native Windows terminals. The way colors work there is that it's a property of the terminal itself, rather than encoded in the output stream. On Unix (and in mintty I believe) the colors are encoded in the output stream, and can hence be buffered.

So it sounds like a great way to approach this might be:

  • First, let's buffer all diagnostic messages if colors aren't enabled (where stdout is flushed after each message).
  • If we're on a native Windows terminal, we just do what we do today. Colors are better than no colors, even if sometimes they're broken due to concurrency.
  • Otherwise, colorization works by encoding into the output stream, so we can buffer entire messages (like the first bullet) with the colors, and then emit it all at once.

This should immediately improve the situation on Unix (and even add colors to MinGW). This unfortunately won't help the concurrent native Windows console experience, but there's not really much we can do there, but at least it remains status quo!

cc @Stebalien - current maintainer of term
cc @brson - from our discussion on IRC

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions