Skip to content

Commit 1e3648b

Browse files
committed
Report codegen timings for binary crates
This is done by enabling `--emit metadata` for binary crates too despite them not actually supporting crate metadata. Rustc will produce a harmless empty metadata file, but also report exactly when codegen starts just like currently happens for rlibs.
1 parent e6827ee commit 1e3648b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,16 @@ fn build_base_args(
850850

851851
if unit.mode.is_check() {
852852
cmd.arg("--emit=dep-info,metadata");
853-
} else if !unit.requires_upstream_objects() {
853+
} else {
854854
// Always produce metadata files for rlib outputs. Metadata may be used
855855
// in this session for a pipelined compilation, or it may be used in a
856856
// future Cargo session as part of a pipelined compile.
857+
// Also include metadata for outputs that need to be linked and thus
858+
// can't be pipelined as this will cause rustc to report when codegen
859+
// starts even when the crate type doesn't actually support metadata
860+
// files. This allows measuring how long codegen takes, which will be
861+
// included in the report produced if `--timings` is passed.
857862
cmd.arg("--emit=dep-info,metadata,link");
858-
} else {
859-
cmd.arg("--emit=dep-info,link");
860863
}
861864

862865
let prefer_dynamic = (unit.target.for_host() && !unit.target.is_custom_build())

tests/testsuite/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn test_profile() {
667667
[RUNNING] `rustc --crate-name bar [..]crate-type lib[..]
668668
[COMPILING] foo [..]
669669
[RUNNING] `rustc --crate-name foo [..]--crate-type lib --emit=dep-info,metadata,link -C linker-plugin-lto[..]
670-
[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,link -C lto=thin [..]--test[..]
670+
[RUNNING] `rustc --crate-name foo [..]--emit=dep-info,metadata,link -C lto=thin [..]--test[..]
671671
[FINISHED] [..]
672672
[RUNNING] [..]
673673
[DOCTEST] foo

0 commit comments

Comments
 (0)