Skip to content

Commit 71d25f6

Browse files
committed
Always ask rustc for messages about artifacts, and always process them
Rather than attempt to determine which compilations require metadata and only ask rustc to emit messages about artifacts for those compilations, just unconditionally generate and process such messages for all compilations. In addition to simplifying code, this also gives us that information for timing purposes as well, even when not pipelining.
1 parent 358e79f commit 71d25f6

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

src/cargo/core/compiler/mod.rs

+20-39
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
641641
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
642642
}
643643

644-
add_error_format_and_color(cx, &mut rustdoc, unit, false);
644+
add_error_format_and_color(cx, &mut rustdoc, unit);
645645
add_allow_features(cx, &mut rustdoc);
646646

647647
if let Some(args) = cx.bcx.extra_args_for(unit) {
@@ -790,19 +790,9 @@ fn add_allow_features(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder) {
790790
/// intercepting messages like rmeta artifacts, etc. rustc includes a
791791
/// "rendered" field in the JSON message with the message properly formatted,
792792
/// which Cargo will extract and display to the user.
793-
fn add_error_format_and_color(
794-
cx: &Context<'_, '_>,
795-
cmd: &mut ProcessBuilder,
796-
unit: &Unit,
797-
pipelined: bool,
798-
) {
793+
fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, unit: &Unit) {
799794
cmd.arg("--error-format=json");
800-
let mut json = String::from("--json=diagnostic-rendered-ansi");
801-
if pipelined {
802-
// Pipelining needs to know when rmeta files are finished. Tell rustc
803-
// to emit a message that cargo will intercept.
804-
json.push_str(",artifacts");
805-
}
795+
let mut json = String::from("--json=diagnostic-rendered-ansi,artifacts");
806796
if cx
807797
.bcx
808798
.target_data
@@ -873,7 +863,7 @@ fn build_base_args(
873863
edition.cmd_edition_arg(cmd);
874864

875865
add_path_args(bcx.ws, unit, cmd);
876-
add_error_format_and_color(cx, cmd, unit, cx.rmeta_required(unit));
866+
add_error_format_and_color(cx, cmd, unit);
877867
add_allow_features(cx, cmd);
878868

879869
let mut contains_dy_lib = false;
@@ -1234,9 +1224,6 @@ fn envify(s: &str) -> String {
12341224
struct OutputOptions {
12351225
/// What format we're emitting from Cargo itself.
12361226
format: MessageFormat,
1237-
/// Look for JSON message that indicates .rmeta file is available for
1238-
/// pipelined compilation.
1239-
look_for_metadata_directive: bool,
12401227
/// Whether or not to display messages in color.
12411228
color: bool,
12421229
/// Where to write the JSON messages to support playback later if the unit
@@ -1258,15 +1245,13 @@ struct OutputOptions {
12581245

12591246
impl OutputOptions {
12601247
fn new(cx: &Context<'_, '_>, unit: &Unit) -> OutputOptions {
1261-
let look_for_metadata_directive = cx.rmeta_required(unit);
12621248
let color = cx.bcx.config.shell().err_supports_color();
12631249
let path = cx.files().message_cache_path(unit);
12641250
// Remove old cache, ignore ENOENT, which is the common case.
12651251
drop(fs::remove_file(&path));
12661252
let cache_cell = Some((path, LazyCell::new()));
12671253
OutputOptions {
12681254
format: cx.bcx.build_config.message_format,
1269-
look_for_metadata_directive,
12701255
color,
12711256
cache_cell,
12721257
show_diagnostics: true,
@@ -1428,27 +1413,24 @@ fn on_stderr_line_inner(
14281413
MessageFormat::Json { ansi: true, .. } => {}
14291414
}
14301415

1431-
// In some modes of execution we will execute rustc with `-Z
1432-
// emit-artifact-notifications` to look for metadata files being produced. When this
1433-
// happens we may be able to start subsequent compilations more quickly than
1434-
// waiting for an entire compile to finish, possibly using more parallelism
1435-
// available to complete a compilation session more quickly.
1416+
// We always tell rustc to emit messages about artifacts being produced.
1417+
// These messages feed into pipelined compilation, as well as timing
1418+
// information.
14361419
//
1437-
// In these cases look for a matching directive and inform Cargo internally
1438-
// that a metadata file has been produced.
1439-
if options.look_for_metadata_directive {
1440-
#[derive(serde::Deserialize)]
1441-
struct ArtifactNotification {
1442-
artifact: String,
1443-
}
1444-
if let Ok(artifact) = serde_json::from_str::<ArtifactNotification>(compiler_message.get()) {
1445-
log::trace!("found directive from rustc: `{}`", artifact.artifact);
1446-
if artifact.artifact.ends_with(".rmeta") {
1447-
log::debug!("looks like metadata finished early!");
1448-
state.rmeta_produced();
1449-
}
1450-
return Ok(false);
1420+
// Look for a matching directive and inform Cargo internally that a
1421+
// metadata file has been produced.
1422+
#[derive(serde::Deserialize)]
1423+
struct ArtifactNotification {
1424+
artifact: String,
1425+
}
1426+
1427+
if let Ok(artifact) = serde_json::from_str::<ArtifactNotification>(compiler_message.get()) {
1428+
log::trace!("found directive from rustc: `{}`", artifact.artifact);
1429+
if artifact.artifact.ends_with(".rmeta") {
1430+
log::debug!("looks like metadata finished early!");
1431+
state.rmeta_produced();
14511432
}
1433+
return Ok(false);
14521434
}
14531435

14541436
#[derive(serde::Deserialize)]
@@ -1519,7 +1501,6 @@ fn replay_output_cache(
15191501
let target = target.clone();
15201502
let mut options = OutputOptions {
15211503
format,
1522-
look_for_metadata_directive: true,
15231504
color,
15241505
cache_cell: None,
15251506
show_diagnostics,

0 commit comments

Comments
 (0)