mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Auto merge of #10255 - joshtriplett:unconditional-artifact-timing, r=alexcrichton
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. <!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide": https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. -->
This commit is contained in:
commit
c094313f9e
@ -641,7 +641,7 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
|
||||
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
|
||||
}
|
||||
|
||||
add_error_format_and_color(cx, &mut rustdoc, unit, false);
|
||||
add_error_format_and_color(cx, &mut rustdoc, unit);
|
||||
add_allow_features(cx, &mut rustdoc);
|
||||
|
||||
if let Some(args) = cx.bcx.extra_args_for(unit) {
|
||||
@ -790,19 +790,9 @@ fn add_allow_features(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder) {
|
||||
/// intercepting messages like rmeta artifacts, etc. rustc includes a
|
||||
/// "rendered" field in the JSON message with the message properly formatted,
|
||||
/// which Cargo will extract and display to the user.
|
||||
fn add_error_format_and_color(
|
||||
cx: &Context<'_, '_>,
|
||||
cmd: &mut ProcessBuilder,
|
||||
unit: &Unit,
|
||||
pipelined: bool,
|
||||
) {
|
||||
fn add_error_format_and_color(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, unit: &Unit) {
|
||||
cmd.arg("--error-format=json");
|
||||
let mut json = String::from("--json=diagnostic-rendered-ansi");
|
||||
if pipelined {
|
||||
// Pipelining needs to know when rmeta files are finished. Tell rustc
|
||||
// to emit a message that cargo will intercept.
|
||||
json.push_str(",artifacts");
|
||||
}
|
||||
let mut json = String::from("--json=diagnostic-rendered-ansi,artifacts");
|
||||
if cx
|
||||
.bcx
|
||||
.target_data
|
||||
@ -873,7 +863,7 @@ fn build_base_args(
|
||||
edition.cmd_edition_arg(cmd);
|
||||
|
||||
add_path_args(bcx.ws, unit, cmd);
|
||||
add_error_format_and_color(cx, cmd, unit, cx.rmeta_required(unit));
|
||||
add_error_format_and_color(cx, cmd, unit);
|
||||
add_allow_features(cx, cmd);
|
||||
|
||||
let mut contains_dy_lib = false;
|
||||
@ -1234,9 +1224,6 @@ fn envify(s: &str) -> String {
|
||||
struct OutputOptions {
|
||||
/// What format we're emitting from Cargo itself.
|
||||
format: MessageFormat,
|
||||
/// Look for JSON message that indicates .rmeta file is available for
|
||||
/// pipelined compilation.
|
||||
look_for_metadata_directive: bool,
|
||||
/// Whether or not to display messages in color.
|
||||
color: bool,
|
||||
/// Where to write the JSON messages to support playback later if the unit
|
||||
@ -1258,7 +1245,6 @@ struct OutputOptions {
|
||||
|
||||
impl OutputOptions {
|
||||
fn new(cx: &Context<'_, '_>, unit: &Unit) -> OutputOptions {
|
||||
let look_for_metadata_directive = cx.rmeta_required(unit);
|
||||
let color = cx.bcx.config.shell().err_supports_color();
|
||||
let path = cx.files().message_cache_path(unit);
|
||||
// Remove old cache, ignore ENOENT, which is the common case.
|
||||
@ -1266,7 +1252,6 @@ impl OutputOptions {
|
||||
let cache_cell = Some((path, LazyCell::new()));
|
||||
OutputOptions {
|
||||
format: cx.bcx.build_config.message_format,
|
||||
look_for_metadata_directive,
|
||||
color,
|
||||
cache_cell,
|
||||
show_diagnostics: true,
|
||||
@ -1428,27 +1413,24 @@ fn on_stderr_line_inner(
|
||||
MessageFormat::Json { ansi: true, .. } => {}
|
||||
}
|
||||
|
||||
// In some modes of execution we will execute rustc with `-Z
|
||||
// emit-artifact-notifications` to look for metadata files being produced. When this
|
||||
// happens we may be able to start subsequent compilations more quickly than
|
||||
// waiting for an entire compile to finish, possibly using more parallelism
|
||||
// available to complete a compilation session more quickly.
|
||||
// We always tell rustc to emit messages about artifacts being produced.
|
||||
// These messages feed into pipelined compilation, as well as timing
|
||||
// information.
|
||||
//
|
||||
// In these cases look for a matching directive and inform Cargo internally
|
||||
// that a metadata file has been produced.
|
||||
if options.look_for_metadata_directive {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct ArtifactNotification {
|
||||
artifact: String,
|
||||
}
|
||||
if let Ok(artifact) = serde_json::from_str::<ArtifactNotification>(compiler_message.get()) {
|
||||
log::trace!("found directive from rustc: `{}`", artifact.artifact);
|
||||
if artifact.artifact.ends_with(".rmeta") {
|
||||
log::debug!("looks like metadata finished early!");
|
||||
state.rmeta_produced();
|
||||
}
|
||||
return Ok(false);
|
||||
// Look for a matching directive and inform Cargo internally that a
|
||||
// metadata file has been produced.
|
||||
#[derive(serde::Deserialize)]
|
||||
struct ArtifactNotification {
|
||||
artifact: String,
|
||||
}
|
||||
|
||||
if let Ok(artifact) = serde_json::from_str::<ArtifactNotification>(compiler_message.get()) {
|
||||
log::trace!("found directive from rustc: `{}`", artifact.artifact);
|
||||
if artifact.artifact.ends_with(".rmeta") {
|
||||
log::debug!("looks like metadata finished early!");
|
||||
state.rmeta_produced();
|
||||
}
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@ -1519,7 +1501,6 @@ fn replay_output_cache(
|
||||
let target = target.clone();
|
||||
let mut options = OutputOptions {
|
||||
format,
|
||||
look_for_metadata_directive: true,
|
||||
color,
|
||||
cache_cell: None,
|
||||
show_diagnostics,
|
||||
|
Loading…
x
Reference in New Issue
Block a user