Skip to content

Enable color output in rustc when it normally would be #99

Closed

Description

@luser

@jrmuizel was testing sccache for local Rust compilation and he noted that it made rustc's errors lose their normal color formatting. This is because rustc defaults to --color auto, which checks if stdout is a tty. Since sccache sends rustc's stdout/stderr to pipes, it doesn't output in color. We could append --color always to our rustc invocations if --color isn't already present on the commandline. Ideally we'd check if the sccache client's stdout is a tty and only do so in that case. That would present an edge case where we could cache color rustc output, then someone could run another compilation and pipe the output, and we'd use the cached output with the colors, but it doesn't seem to be likely to be a big problem in practice. The only colorful output rustc produces in successful compilations is warnings, AFAIK. We could make that edge case work by stripping ANSI color codes from the output when stdout is not a tty. If we did that, then we could just unIlaterally pass --color always to rustc and strip out the color codes when they're not wanted.

Activity

  1. theduke commented on Jul 25, 2017

    @theduke

    Big plus one for this.

    You get a very noticable speedup when working on many crates, and always setting/unsetting RUSTC_WRAPPER is annoying.

  2. versusvoid commented on Nov 11, 2017

    @versusvoid

    Also --color argument mustn't trigger recompilation, so I see better approach in unconditionally passing (or overriding to) --color=always and stripping color codes when necessary.
    Analogous logic should be implemented for gcc's and clang's -fdiagnostics-color.

    For now adding rustflags = ["--color=always"] to .cargo/config mitigates the problem.

  3. added a commit that references this issue on Feb 2, 2018
    4df3ecf
  4. luser commented on Feb 2, 2018

    @luser
    ContributorAuthor

    Analogous logic should be implemented for gcc's and clang's -fdiagnostics-color.

    Just to clarify: I did not implement support for this for gcc/clang. All the pieces necessary should be there, it'd just be a matter of adding the commandline parsing and such in the code that handles C compilation.

  5. added a commit that references this issue on May 17, 2018
    5785bbe
  6. added a commit that references this issue on Dec 8, 2021
  7. added a commit that references this issue on Jan 3, 2025
    583fd1f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions