Skip to content

stage1 compiler emits color information during x.py build even when running with TERM=dumb #49191

Closed
@nikomatsakis

Description

@nikomatsakis

When I run x.py from inside emacs, everything works fine for the stage0 build. But errors that arise in the stage1 build always have color information. This is annoying since the emacs compilation window can't interpret ansi colors, so I get this garbage:

^[[0m^[[38;5;9m^[[1merror[E0503]^[[0m^[[0m^[[1m: cannot use `result` because it was mutably borrowed^[[0m
^[[0m   ^[[0m^[[0m^[[38;5;12m^[[1m--> ^[[0m^[[0mrustc/compiler_builtins_shim/../../libcompiler_builtins/src/float/add.rs:179:46^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m|^[[0m
^[[0m^[[38;5;12m^[[1m179^[[0m^[[0m ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m    if round_guard_sticky == 0x4 { result += result & one; }^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m                                   ^[[0m^[[0m^[[38;5;12m^[[1m----------^[[0m^[[0m^[[38;5;9m^[[1m^^^^^^^[[0m^[[0m^[[38;5;12m^[[1m------^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m                                   ^[[0m^[[0m^[[38;5;12m^[[1m|^[[0m^[[0m         ^[[0m^[[0m^[[38;5;9m^[[1m|^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m                                   ^[[0m^[[0m^[[38;5;12m^[[1m|^[[0m^[[0m         ^[[0m^[[0m^[[38;5;9m^[[1muse of borrowed `result`^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m                                   ^[[0m^[[0m^[[38;5;12m^[[1mborrow of `result` occurs here^[[0m
^[[0m    ^[[0m^[[0m^[[38;5;12m^[[1m| ^[[0m^[[0m   

It seems like the problem is this logic in rustbuild, which is a wee bit forceful:

rust/src/bootstrap/compile.rs

Lines 1004 to 1009 in a04b88d

if stderr_isatty() && build.ci_env == CiEnv::None {
// since we pass message-format=json to cargo, we need to tell the rustc
// wrapper to give us colored output if necessary. This is because we
// only want Cargo's JSON output, not rustcs.
cargo.env("RUSTC_COLOR", "1");
}

Not sure what's the best way to fix this. I'm surprised that stderr is coming up as a "tty" when running from inside the M-x compile shell in emacs, but for sure the TERM variable is dumb. Maybe we should respect that?

cc @Mark-Simulacrum

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions