Skip to content

Commit 7888e25

Browse files
committed
fix(toolchain/distributable): refine handling of known targets with no prebuilt artifacts
1 parent 13dfe35 commit 7888e25

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ openssl = { version = "0.10", optional = true }
6666
opentelemetry = { version = "0.30", optional = true }
6767
opentelemetry-otlp = { version = "0.30", features = ["grpc-tonic"], optional = true }
6868
opentelemetry_sdk = { version = "0.30", features = ["rt-tokio"], optional = true }
69+
platforms = "3.4"
6970
pulldown-cmark = { version = "0.13", default-features = false }
7071
rand = "0.9"
7172
regex = "1"
@@ -135,7 +136,6 @@ enum-map = "2.5.0"
135136
http-body-util = "0.1.0"
136137
hyper = { version = "1.0", default-features = false, features = ["server", "http1"] }
137138
hyper-util = { version = "0.1.1", features = ["tokio"] }
138-
platforms = "3.4"
139139
proptest = "1.1.0"
140140
trycmd = "0.15.0"
141141

src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::io;
77
use std::io::Write;
88
use std::path::PathBuf;
99

10+
use platforms::Platform;
1011
use thiserror::Error as ThisError;
1112
use url::Url;
1213

@@ -125,6 +126,15 @@ pub enum RustupError {
125126
component: String,
126127
suggestion: Option<String>,
127128
},
129+
#[error(
130+
"toolchain '{desc}' has no prebuilt artifacts available for target '{platform}'\n\
131+
note: this may happen to a low-tier target as per https://doc.rust-lang.org/nightly/rustc/platform-support.html\n\
132+
note: you can find instructions on that page to build the target support from source"
133+
)]
134+
UnavailableTarget {
135+
desc: ToolchainDesc,
136+
platform: &'static Platform,
137+
},
128138
#[error("toolchain '{}' does not support target '{}'{}\n\
129139
note: you can see a list of supported targets with `rustc --print=target-list`\n\
130140
note: if you are adding support for a new target to rustc itself, see https://rustc-dev-guide.rust-lang.org/building/new-target.html", .desc, .target,

src/toolchain/distributable.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{convert::Infallible, env::consts::EXE_SUFFIX, ffi::OsStr, path::Path,
55
#[cfg(windows)]
66
use anyhow::Context;
77
use anyhow::anyhow;
8+
use platforms::Platform;
89

910
use crate::{
1011
RustupError, component_for_bin,
@@ -76,21 +77,26 @@ impl<'a> DistributableToolchain<'a> {
7677
let config = manifestation.read_config()?.unwrap_or_default();
7778
let suggestion =
7879
self.get_component_suggestion(&component, &config, &manifest, false);
80+
let desc = self.desc.clone();
7981
// Check if the target is supported.
8082
if !targ_pkg
8183
.components
8284
.iter()
8385
.any(|c| c.target() == component.target())
8486
{
87+
let target = component.target.expect("component target should be known");
88+
if let Some(platform) = Platform::find(&target) {
89+
return Err(RustupError::UnavailableTarget { desc, platform }.into());
90+
};
8591
return Err(RustupError::UnknownTarget {
86-
desc: self.desc.clone(),
87-
target: component.target.expect("component target should be known"),
92+
desc,
93+
target,
8894
suggestion,
8995
}
9096
.into());
9197
}
9298
return Err(RustupError::UnknownComponent {
93-
desc: self.desc.clone(),
99+
desc,
94100
component: component.description(&manifest),
95101
suggestion,
96102
}

tests/suite/cli_v2.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,26 @@ note: if you are adding support for a new target to rustc itself, see https://ru
15091509
.is_err();
15101510
}
15111511

1512+
#[tokio::test]
1513+
async fn add_target_unavailable() {
1514+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
1515+
cx.config
1516+
.expect(["rustup", "default", "nightly"])
1517+
.await
1518+
.is_ok();
1519+
cx.config
1520+
.expect(["rustup", "target", "add", "mipsel-sony-psp"])
1521+
.await
1522+
.with_stderr(snapbox::str![[r#"
1523+
...
1524+
error: toolchain 'nightly-[HOST_TRIPLE]' has no prebuilt artifacts available for target 'mipsel-sony-psp'
1525+
note: this may happen to a low-tier target as per https://doc.rust-lang.org/nightly/rustc/platform-support.html
1526+
note: you can find instructions on that page to build the target support from source
1527+
1528+
"#]])
1529+
.is_err();
1530+
}
1531+
15121532
#[tokio::test]
15131533
async fn add_target_v1_toolchain() {
15141534
let cx = CliTestContext::new(Scenario::SimpleV1).await;

0 commit comments

Comments
 (0)