Skip to content

Commit c2332dc

Browse files
committed
Detect if rustc supports '--json future-incompat'
1 parent 997bf3f commit c2332dc

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct TargetInfo {
4747
pub rustdocflags: Vec<String>,
4848
/// Whether or not rustc supports the `-Csplit-debuginfo` flag.
4949
pub supports_split_debuginfo: bool,
50+
/// Whether or not rustc supports the `--json future-incompat` flag.
51+
pub supports_json_future_incompat: bool,
5052
}
5153

5254
/// Kind of each file generated by a Unit, part of `FileType`.
@@ -179,6 +181,13 @@ impl TargetInfo {
179181
)
180182
.is_ok();
181183

184+
let supports_json_future_incompat = rustc
185+
.cached_output(
186+
process.clone().arg("--json").arg("future-incompat"),
187+
extra_fingerprint,
188+
)
189+
.is_ok();
190+
182191
process.arg("--print=sysroot");
183192
process.arg("--print=cfg");
184193

@@ -253,6 +262,7 @@ impl TargetInfo {
253262
)?,
254263
cfg,
255264
supports_split_debuginfo,
265+
supports_json_future_incompat,
256266
})
257267
}
258268

src/cargo/core/compiler/mod.rs

Lines changed: 18 additions & 6 deletions
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, false);
644+
add_error_format_and_color(cx, &mut rustdoc, unit, false);
645645
add_allow_features(cx, &mut rustdoc);
646646

647647
if let Some(args) = cx.bcx.extra_args_for(unit) {
@@ -790,17 +790,29 @@ 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(cx: &Context<'_, '_>, cmd: &mut ProcessBuilder, pipelined: bool) {
793+
fn add_error_format_and_color(
794+
cx: &Context<'_, '_>,
795+
cmd: &mut ProcessBuilder,
796+
unit: &Unit,
797+
pipelined: bool,
798+
) {
794799
cmd.arg("--error-format=json");
795800
let mut json = String::from("--json=diagnostic-rendered-ansi");
796801
if pipelined {
797802
// Pipelining needs to know when rmeta files are finished. Tell rustc
798803
// to emit a message that cargo will intercept.
799804
json.push_str(",artifacts");
800805
}
801-
// Always emit a future-incompat report, so we can report
802-
// future-incompat dependencies to the user
803-
json.push_str(",future-incompat");
806+
if cx
807+
.bcx
808+
.target_data
809+
.info(unit.kind)
810+
.supports_json_future_incompat
811+
{
812+
// Emit a future-incompat report (when supported by rustc), so we can report
813+
// future-incompat dependencies to the user
814+
json.push_str(",future-incompat");
815+
}
804816

805817
match cx.bcx.build_config.message_format {
806818
MessageFormat::Short | MessageFormat::Json { short: true, .. } => {
@@ -861,7 +873,7 @@ fn build_base_args(
861873
edition.cmd_edition_arg(cmd);
862874

863875
add_path_args(bcx.ws, unit, cmd);
864-
add_error_format_and_color(cx, cmd, cx.rmeta_required(unit));
876+
add_error_format_and_color(cx, cmd, unit, cx.rmeta_required(unit));
865877
add_allow_features(cx, cmd);
866878

867879
let mut contains_dy_lib = false;

0 commit comments

Comments
 (0)