diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs
index 95491c86766..372982dc439 100644
--- a/src/cargo/util/command_prelude.rs
+++ b/src/cargo/util/command_prelude.rs
@@ -379,6 +379,58 @@ pub trait ArgMatchesExt {
self._values_of("target")
}
+ fn get_timing_outputs(&self, config: &Config) -> CargoResult> {
+ let mut timing_outputs = Vec::new();
+ // If `--timings' flag exists, override the configured timings value.
+ if self._contains("timings") {
+ for timing_output in self._values_of("timings") {
+ for timing_output in timing_output.split(',') {
+ let timing_output = timing_output.to_ascii_lowercase();
+ let timing_output = match timing_output.as_str() {
+ "html" => {
+ config
+ .cli_unstable()
+ .fail_if_stable_opt("--timings=html", 7405)?;
+ TimingOutput::Html
+ }
+ "json" => {
+ config
+ .cli_unstable()
+ .fail_if_stable_opt("--timings=json", 7405)?;
+ TimingOutput::Json
+ }
+ s => bail!("invalid timings output specifier: `{}`", s),
+ };
+ timing_outputs.push(timing_output);
+ }
+ }
+ // If there is no timings value, the default value is used.
+ if timing_outputs.is_empty() {
+ return Ok(vec![TimingOutput::Html]);
+ }
+ } else {
+ let build_config = config.build_config()?;
+ if let Some(config_timing_outputs) = &build_config.timings {
+ for timing_output in config_timing_outputs {
+ let timing_output = timing_output.to_ascii_lowercase();
+ let timing_output = match timing_output.as_str() {
+ "html" => TimingOutput::Html,
+ "json" => {
+ config
+ .cli_unstable()
+ .fail_if_stable_opt("--timings=json", 7405)?;
+ TimingOutput::Json
+ }
+ s => bail!("invalid timings output configuration: `{}`", s),
+ };
+ timing_outputs.push(timing_output);
+ }
+ }
+ }
+
+ Ok(timing_outputs)
+ }
+
fn get_profile_name(
&self,
config: &Config,
@@ -532,33 +584,7 @@ pub trait ArgMatchesExt {
build_config.build_plan = self.flag("build-plan");
build_config.unit_graph = self.flag("unit-graph");
build_config.future_incompat_report = self.flag("future-incompat-report");
-
- if self._contains("timings") {
- for timing_output in self._values_of("timings") {
- for timing_output in timing_output.split(',') {
- let timing_output = timing_output.to_ascii_lowercase();
- let timing_output = match timing_output.as_str() {
- "html" => {
- config
- .cli_unstable()
- .fail_if_stable_opt("--timings=html", 7405)?;
- TimingOutput::Html
- }
- "json" => {
- config
- .cli_unstable()
- .fail_if_stable_opt("--timings=json", 7405)?;
- TimingOutput::Json
- }
- s => bail!("invalid timings output specifier: `{}`", s),
- };
- build_config.timing_outputs.push(timing_output);
- }
- }
- if build_config.timing_outputs.is_empty() {
- build_config.timing_outputs.push(TimingOutput::Html);
- }
- }
+ build_config.timing_outputs = self.get_timing_outputs(config)?;
if build_config.keep_going {
config
diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs
index e20004c0dcc..abf5b39ea2a 100644
--- a/src/cargo/util/config/mod.rs
+++ b/src/cargo/util/config/mod.rs
@@ -2201,6 +2201,7 @@ pub struct CargoBuildConfig {
pub rustc: Option,
pub rustdoc: Option,
pub out_dir: Option,
+ pub timings: Option>,
}
/// Configuration for `build.target`.
diff --git a/src/doc/man/generated_txt/cargo-bench.txt b/src/doc/man/generated_txt/cargo-bench.txt
index 972bed35332..8a68eb91e8f 100644
--- a/src/doc/man/generated_txt/cargo-bench.txt
+++ b/src/doc/man/generated_txt/cargo-bench.txt
@@ -235,7 +235,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-build.txt b/src/doc/man/generated_txt/cargo-build.txt
index 818dee1d92d..e708c632dff 100644
--- a/src/doc/man/generated_txt/cargo-build.txt
+++ b/src/doc/man/generated_txt/cargo-build.txt
@@ -171,7 +171,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-check.txt b/src/doc/man/generated_txt/cargo-check.txt
index 326c6588d8b..7a62901bebc 100644
--- a/src/doc/man/generated_txt/cargo-check.txt
+++ b/src/doc/man/generated_txt/cargo-check.txt
@@ -175,7 +175,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-doc.txt b/src/doc/man/generated_txt/cargo-doc.txt
index f5457629cf6..cd5d58d42ec 100644
--- a/src/doc/man/generated_txt/cargo-doc.txt
+++ b/src/doc/man/generated_txt/cargo-doc.txt
@@ -146,7 +146,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-fix.txt b/src/doc/man/generated_txt/cargo-fix.txt
index 0b5ada717b5..4687613d7b0 100644
--- a/src/doc/man/generated_txt/cargo-fix.txt
+++ b/src/doc/man/generated_txt/cargo-fix.txt
@@ -248,7 +248,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-install.txt b/src/doc/man/generated_txt/cargo-install.txt
index 6132721e7f7..cf92f7b06d4 100644
--- a/src/doc/man/generated_txt/cargo-install.txt
+++ b/src/doc/man/generated_txt/cargo-install.txt
@@ -211,7 +211,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-run.txt b/src/doc/man/generated_txt/cargo-run.txt
index 96c3feece6f..43fbc2a379a 100644
--- a/src/doc/man/generated_txt/cargo-run.txt
+++ b/src/doc/man/generated_txt/cargo-run.txt
@@ -91,7 +91,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-rustc.txt b/src/doc/man/generated_txt/cargo-rustc.txt
index aab1921bf59..3e945b92422 100644
--- a/src/doc/man/generated_txt/cargo-rustc.txt
+++ b/src/doc/man/generated_txt/cargo-rustc.txt
@@ -179,7 +179,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-rustdoc.txt b/src/doc/man/generated_txt/cargo-rustdoc.txt
index 66f16c13ace..93b2032b766 100644
--- a/src/doc/man/generated_txt/cargo-rustdoc.txt
+++ b/src/doc/man/generated_txt/cargo-rustdoc.txt
@@ -162,7 +162,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/generated_txt/cargo-test.txt b/src/doc/man/generated_txt/cargo-test.txt
index 0c66532da73..48b0d25846c 100644
--- a/src/doc/man/generated_txt/cargo-test.txt
+++ b/src/doc/man/generated_txt/cargo-test.txt
@@ -253,7 +253,10 @@ OPTIONS
comma-separated list of output formats; --timings without an
argument will default to --timings=html. Specifying an output format
(rather than the default) is unstable and requires
- -Zunstable-options. Valid output formats:
+ -Zunstable-options. May also be specified with the build.timings
+ config value
+ . Valid
+ output formats:
o html: Write a human-readable file cargo-timing.html to the
target/cargo-timings directory with a report of the compilation.
diff --git a/src/doc/man/includes/options-timings.md b/src/doc/man/includes/options-timings.md
index 963b30d4719..60f9f8f3fcb 100644
--- a/src/doc/man/includes/options-timings.md
+++ b/src/doc/man/includes/options-timings.md
@@ -3,7 +3,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma-separated list of output
formats; `--timings` without an argument will default to `--timings=html`.
Specifying an output format (rather than the default) is unstable and requires
-`-Zunstable-options`. Valid output formats:
+`-Zunstable-options`.
+May also be specified with the `build.timings` [config value](../reference/config.html).
+Valid output formats:
- `html`: Write a human-readable file `cargo-timing.html` to the
`target/cargo-timings` directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-bench.md b/src/doc/src/commands/cargo-bench.md
index 1e60016b39f..575b37ea3cf 100644
--- a/src/doc/src/commands/cargo-bench.md
+++ b/src/doc/src/commands/cargo-bench.md
@@ -281,7 +281,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-build.md b/src/doc/src/commands/cargo-build.md
index 7f6a16a6536..65f8680531e 100644
--- a/src/doc/src/commands/cargo-build.md
+++ b/src/doc/src/commands/cargo-build.md
@@ -215,7 +215,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-check.md b/src/doc/src/commands/cargo-check.md
index 967b4cb3adb..8a558b1d72a 100644
--- a/src/doc/src/commands/cargo-check.md
+++ b/src/doc/src/commands/cargo-check.md
@@ -214,7 +214,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-doc.md b/src/doc/src/commands/cargo-doc.md
index f0927484d65..b1d0b6bda3d 100644
--- a/src/doc/src/commands/cargo-doc.md
+++ b/src/doc/src/commands/cargo-doc.md
@@ -188,7 +188,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-fix.md b/src/doc/src/commands/cargo-fix.md
index d871cb10997..4c7925c5a63 100644
--- a/src/doc/src/commands/cargo-fix.md
+++ b/src/doc/src/commands/cargo-fix.md
@@ -294,7 +294,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-install.md b/src/doc/src/commands/cargo-install.md
index 68ddf93da84..38562dea158 100644
--- a/src/doc/src/commands/cargo-install.md
+++ b/src/doc/src/commands/cargo-install.md
@@ -241,7 +241,9 @@ See the the reference for more details
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-run.md b/src/doc/src/commands/cargo-run.md
index f71a769d497..21c0e917fc8 100644
--- a/src/doc/src/commands/cargo-run.md
+++ b/src/doc/src/commands/cargo-run.md
@@ -123,7 +123,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-rustc.md b/src/doc/src/commands/cargo-rustc.md
index 6fd56810021..5daaa5c9350 100644
--- a/src/doc/src/commands/cargo-rustc.md
+++ b/src/doc/src/commands/cargo-rustc.md
@@ -212,7 +212,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-rustdoc.md b/src/doc/src/commands/cargo-rustdoc.md
index 76e45bb52f3..a6f74d345df 100644
--- a/src/doc/src/commands/cargo-rustdoc.md
+++ b/src/doc/src/commands/cargo-rustdoc.md
@@ -207,7 +207,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/commands/cargo-test.md b/src/doc/src/commands/cargo-test.md
index a940ff24d56..d02b552070f 100644
--- a/src/doc/src/commands/cargo-test.md
+++ b/src/doc/src/commands/cargo-test.md
@@ -302,7 +302,9 @@ required Rust version as configured in the project's rust-version
f
information over time. Accepts an optional comma-separated list of output
formats; --timings
without an argument will default to --timings=html
.
Specifying an output format (rather than the default) is unstable and requires
--Zunstable-options
. Valid output formats:
+-Zunstable-options
.
+May also be specified with the build.timings
config value.
+Valid output formats:
html
: Write a human-readable file cargo-timing.html
to the
target/cargo-timings
directory with a report of the compilation. Also write
diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md
index c2d8e665ef9..71281938812 100644
--- a/src/doc/src/reference/config.md
+++ b/src/doc/src/reference/config.md
@@ -73,6 +73,7 @@ rustflags = ["…", "…"] # custom flags to pass to all compiler invocat
rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
incremental = true # whether or not to enable incremental compilation
dep-info-basedir = "…" # path for the base directory for targets in depfiles
+timings = ["…", "…"] # the output formats of the compile time information
[doc]
browser = "chromium" # browser to use with `cargo doc --open`,
@@ -445,6 +446,22 @@ directory.
This option is deprecated and unused. Cargo always has pipelining enabled.
+#### `build.timings`
+* Type: array of strings
+* Default: none
+* Environment: `CARGO_BUILD_TIMINGS`
+
+Output information how long each compilation takes, and track concurrency information over time. Possible values:
+
+* `html`: Write a human-readable file `cargo-timing.html` to the
+ `target/cargo-timings` directory with a report of the compilation. Also write
+ a report to the same directory with a timestamp in the filename if you want
+ to look at older runs. HTML output is suitable for human consumption only,
+ and does not provide machine-readable timing data.
+* `json` (unstable, requires `-Zunstable-options`): Emit machine-readable JSON information about timing information.
+
+Can be overridden with the `--timings` CLI option.
+
#### `[doc]`
The `[doc]` table defines options for the [`cargo doc`] command.
diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md
index fc184e3b427..50135b1cbbd 100644
--- a/src/doc/src/reference/environment-variables.md
+++ b/src/doc/src/reference/environment-variables.md
@@ -83,6 +83,7 @@ supported environment variables are:
* `CARGO_BUILD_RUSTDOCFLAGS` — Extra `rustdoc` flags, see [`build.rustdocflags`].
* `CARGO_BUILD_INCREMENTAL` — Incremental compilation, see [`build.incremental`].
* `CARGO_BUILD_DEP_INFO_BASEDIR` — Dep-info relative directory, see [`build.dep-info-basedir`].
+* `CARGO_BUILD_TIMINGS` — Compile time information output formats, see [`build.timings`].
* `CARGO_CARGO_NEW_VCS` — The default source control system with [`cargo new`], see [`cargo-new.vcs`].
* `CARGO_FUTURE_INCOMPAT_REPORT_FREQUENCY` - How often we should generate a future incompat report notification, see [`future-incompat-report.frequency`].
* `CARGO_HTTP_DEBUG` — Enables HTTP debugging, see [`http.debug`].
@@ -142,6 +143,7 @@ supported environment variables are:
[`build.rustdocflags`]: config.md#buildrustdocflags
[`build.incremental`]: config.md#buildincremental
[`build.dep-info-basedir`]: config.md#builddep-info-basedir
+[`build.timings`]: config.md#buildtimings
[`doc.browser`]: config.md#docbrowser
[`cargo-new.name`]: config.md#cargo-newname
[`cargo-new.email`]: config.md#cargo-newemail
diff --git a/src/doc/src/reference/timings.md b/src/doc/src/reference/timings.md
index 310babd04c3..ae083be322b 100644
--- a/src/doc/src/reference/timings.md
+++ b/src/doc/src/reference/timings.md
@@ -10,6 +10,13 @@ This writes an HTML report in `target/cargo-timings/cargo-timings.html`. This
also writes a copy of the report to the same directory with a timestamp in the
filename, if you want to look at older runs.
+Alternatively, you can specify it through `.cargo/config.toml`.
+
+```toml
+[build]
+timings = ["html"]
+```
+
#### Reading the graphs
There are two graphs in the output. The "unit" graph shows the duration of
diff --git a/src/etc/man/cargo-bench.1 b/src/etc/man/cargo-bench.1
index 230290583c2..877d75696b9 100644
--- a/src/etc/man/cargo-bench.1
+++ b/src/etc/man/cargo-bench.1
@@ -285,7 +285,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-build.1 b/src/etc/man/cargo-build.1
index 179446ed634..60243217f0e 100644
--- a/src/etc/man/cargo-build.1
+++ b/src/etc/man/cargo-build.1
@@ -203,7 +203,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-check.1 b/src/etc/man/cargo-check.1
index f0e68afde6e..69ef5165c24 100644
--- a/src/etc/man/cargo-check.1
+++ b/src/etc/man/cargo-check.1
@@ -205,7 +205,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-doc.1 b/src/etc/man/cargo-doc.1
index fcae4f4a7dd..b0524ecb693 100644
--- a/src/etc/man/cargo-doc.1
+++ b/src/etc/man/cargo-doc.1
@@ -172,7 +172,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-fix.1 b/src/etc/man/cargo-fix.1
index 3ae11adcffa..04020d1891d 100644
--- a/src/etc/man/cargo-fix.1
+++ b/src/etc/man/cargo-fix.1
@@ -300,7 +300,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1
index d4785c186a9..466601a31b5 100644
--- a/src/etc/man/cargo-install.1
+++ b/src/etc/man/cargo-install.1
@@ -273,7 +273,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-run.1 b/src/etc/man/cargo-run.1
index d19384d8b5a..e91fc5f6616 100644
--- a/src/etc/man/cargo-run.1
+++ b/src/etc/man/cargo-run.1
@@ -105,7 +105,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-rustc.1 b/src/etc/man/cargo-rustc.1
index a2f8fd95f98..697c29f7c5c 100644
--- a/src/etc/man/cargo-rustc.1
+++ b/src/etc/man/cargo-rustc.1
@@ -209,7 +209,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-rustdoc.1 b/src/etc/man/cargo-rustdoc.1
index 504f8850685..c03a00b24ad 100644
--- a/src/etc/man/cargo-rustdoc.1
+++ b/src/etc/man/cargo-rustdoc.1
@@ -191,7 +191,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/src/etc/man/cargo-test.1 b/src/etc/man/cargo-test.1
index ba3fa8944fe..ea399935e76 100644
--- a/src/etc/man/cargo-test.1
+++ b/src/etc/man/cargo-test.1
@@ -304,7 +304,9 @@ Output information how long each compilation takes, and track concurrency
information over time. Accepts an optional comma\-separated list of output
formats; \fB\-\-timings\fR without an argument will default to \fB\-\-timings=html\fR\&.
Specifying an output format (rather than the default) is unstable and requires
-\fB\-Zunstable\-options\fR\&. Valid output formats:
+\fB\-Zunstable\-options\fR\&.
+May also be specified with the \fBbuild.timings\fR \fIconfig value\fR \&.
+Valid output formats:
.sp
.RS 4
\h'-04'\(bu\h'+02'\fBhtml\fR: Write a human\-readable file \fBcargo\-timing.html\fR to the
diff --git a/tests/testsuite/timings.rs b/tests/testsuite/timings.rs
index 8f06ac69bc7..06dc4911c58 100644
--- a/tests/testsuite/timings.rs
+++ b/tests/testsuite/timings.rs
@@ -51,3 +51,157 @@ fn timings_works() {
p.cargo("doc --timings").run();
}
+
+const JSON_OUTPUT: &str = r#"
+{
+ "reason": "timing-info",
+ "package_id": "dep 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "target": {
+ "kind": [
+ "lib"
+ ],
+ "crate_types": [
+ "lib"
+ ],
+ "name": "dep",
+ "src_path": "[..]/dep-0.1.0/src/lib.rs",
+ "edition": "2015",
+ "doc": true,
+ "doctest": true,
+ "test": true
+ },
+ "mode": "build",
+ "duration": "{...}",
+ "rmeta_time": "{...}"
+}"#;
+
+#[cargo_test]
+fn timings_works_with_config() {
+ Package::new("dep", "0.1.0").publish();
+
+ let p = project()
+ .file(
+ ".cargo/config",
+ r#"
+ [build]
+ timings = ['json','html']
+ "#,
+ )
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ dep = "0.1"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .file("src/main.rs", "fn main() {}")
+ .file("tests/t1.rs", "")
+ .file("examples/ex1.rs", "fn main() {}")
+ .build();
+
+ p.cargo("build --all-targets -Zunstable-options")
+ .masquerade_as_nightly_cargo()
+ .with_stderr_unordered(
+ "\
+[UPDATING] [..]
+[DOWNLOADING] crates ...
+[DOWNLOADED] dep v0.1.0 [..]
+[COMPILING] dep v0.1.0
+[COMPILING] foo v0.1.0 [..]
+[FINISHED] [..]
+ Timing report saved to [..]/foo/target/cargo-timings/cargo-timing-[..].html
+",
+ )
+ .with_json_contains_unordered(JSON_OUTPUT)
+ .run();
+}
+
+#[cargo_test]
+fn timings_option_override_the_config() {
+ Package::new("dep", "0.1.0").publish();
+
+ let p = project()
+ .file(
+ ".cargo/config",
+ r#"
+ [build]
+ timings = ['json','html']
+ "#,
+ )
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ dep = "0.1"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .file("src/main.rs", "fn main() {}")
+ .file("tests/t1.rs", "")
+ .file("examples/ex1.rs", "fn main() {}")
+ .build();
+
+ p.cargo("build --all-targets --timings=json -Zunstable-options")
+ .masquerade_as_nightly_cargo()
+ .with_stderr_unordered(
+ "\
+[UPDATING] [..]
+[DOWNLOADING] crates ...
+[DOWNLOADED] dep v0.1.0 [..]
+[COMPILING] dep v0.1.0
+[COMPILING] foo v0.1.0 [..]
+[FINISHED] [..]
+",
+ )
+ .with_json_contains_unordered(JSON_OUTPUT)
+ .run();
+}
+
+#[cargo_test]
+fn invalid_timings_config() {
+ Package::new("dep", "0.1.0").publish();
+
+ let p = project()
+ .file(
+ ".cargo/config",
+ r#"
+ [build]
+ timings = ['json1','html1']
+ "#,
+ )
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+
+ [dependencies]
+ dep = "0.1"
+ "#,
+ )
+ .file("src/lib.rs", "")
+ .file("src/main.rs", "fn main() {}")
+ .file("tests/t1.rs", "")
+ .file("examples/ex1.rs", "fn main() {}")
+ .build();
+
+ p.cargo("build --all-targets")
+ .masquerade_as_nightly_cargo()
+ .with_status(101)
+ .with_stderr(
+ "\
+[ERROR] invalid timings output configuration: `json1`
+",
+ )
+ .run();
+}