Skip to content

Commit aa6d15d

Browse files
committed
Better error diagnostics on targets without std.
Provides a warning if a docker command fails and `rust-std` is not installed for the target. For example, for `x86_64-unknown-dragonfly`, the added output would be: ```bash [cross] warning: rust-std is not installed for x86_64-unknown-dragonfly [cross] note: you may need to build components for the std library `-Z build-std=<components>` the available components are core, std, alloc, and proc_macro if no components are provided, cargo will build all components ``` This is done solely if the command fails and if the target is a built-in, so we don't get misleading warnings for custom targets, and there is no overhead if the build succeeds.
1 parent 00c1de2 commit aa6d15d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,20 @@ impl Serialize for Target {
360360
}
361361
}
362362

363+
fn warn_on_failure(target: &Target, toolchain: &str, msg_info: MessageInfo) -> Result<()> {
364+
let rust_std = format!("rust-std-{target}");
365+
if target.is_builtin() && !rustup::component_is_installed(&rust_std, toolchain, msg_info)? {
366+
shell::warn(format!("rust-std is not installed for {target}"), msg_info)?;
367+
shell::note(
368+
"you may need to build components for the std library `-Z build-std=<components>`
369+
the available components are core, std, alloc, and proc_macro
370+
if no components are provided, cargo will build all components",
371+
msg_info,
372+
)?;
373+
}
374+
Ok(())
375+
}
376+
363377
pub fn run() -> Result<ExitStatus> {
364378
let target_list = rustc::target_list(Verbosity::Quiet.into())?;
365379
let args = cli::parse(&target_list)?;
@@ -524,6 +538,9 @@ pub fn run() -> Result<ExitStatus> {
524538
.subcommand
525539
.map(|sc| sc.needs_host(is_remote))
526540
.unwrap_or(false);
541+
if !status.success() {
542+
warn_on_failure(&target, &toolchain, args.msg_info)?;
543+
}
527544
if !(status.success() && needs_host) {
528545
return Ok(status);
529546
}

0 commit comments

Comments
 (0)