Summary
This RFC proposes to add a COLOR
environment variable to tell build scripts to pass on the colour options.
Motivation
Currently, crates like cc-rs
pipes the output into a buffer, which is not a terminal. This will disable the C compilers from outputting coloured messages. This message is dumped upon error, but without colours it may be harder to figure out what’s going on.
Explanation
A COLOR
environment variable is passed during runtime of build scripts, just like others documented here. Cargo determines whether we should have colours or not by its own mechanism (currently it uses termcolor
plus accepting CLI options). The possible values for COLOR
are only two: always
and never
.
Then, the build script or a downstream crate reads this environment variable, and passes the corresponding to the compiler, for instance -fdiagnostics-color
option to gcc/clang.
Alternatives
- Passing arguments to the build scripts: this sound more Unix-ish but argument parsing is normally hard.
- A few alternatives for the environment variable name:
TERMCOLOR
,CARGO_COLOR
. - We can also use 0/1 for the possible values.
Unresolved questions
Does this need a RFC?