Skip to content

Commit 2db06c1

Browse files
authored
Merge pull request #37 from rust-lang/toolchain-ci-feature
Hide CI toolchains behind the unstable-toolchain-ci feature
2 parents 48f138e + 981b9b4 commit 2db06c1

File tree

5 files changed

+59
-17
lines changed

5 files changed

+59
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Changed
99

10+
- **BREAKING**: support for CI toolchains is now gated behind the
11+
`unstable-toolchain-ci` Cargo feature.
1012
- `winapi` is no longer required on unix; `nix` is no longer required on windows.
1113
- Relaxed lifetime restrictions of `Build::cmd` and `Build::cargo`.
1214

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ readme = "README.md"
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515

16-
[package.metadata.docs.rs]
17-
features = ["unstable"]
18-
1916
[features]
2017
unstable = []
18+
unstable-toolchain-ci = []
2119

2220
[dependencies]
2321
failure = "0.1.3"

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
//! * **unstable**: allow Rustwide to use unstable Rust and Cargo features. While this feature also
1313
//! works on Rust stable it might cause Rustwide to break, and **no stability guarantee is
1414
//! present when using it!**
15+
//! * **unstable-toolchain-ci**: allow fetching toolchains from rustc's CI artifacts storage. Support for
16+
//! them is **incomplete** (not all methods might work), and there is **no stability guarantee**
17+
//! when using them!
1518
//!
1619
//! [crater]: https://github.com/rust-lang/crater
1720
//! [docsrs]: https://github.com/rust-lang/docs.rs

src/toolchain.rs

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Tools to manage and use Rust toolchains.
22
33
use crate::cmd::{Binary, Command, Runnable};
4-
use crate::tools::{RUSTUP, RUSTUP_TOOLCHAIN_INSTALL_MASTER};
4+
use crate::tools::RUSTUP;
5+
#[cfg(feature = "unstable-toolchain-ci")]
6+
use crate::tools::RUSTUP_TOOLCHAIN_INSTALL_MASTER;
57
use crate::Workspace;
6-
use failure::{bail, Error, ResultExt};
8+
use failure::{Error, ResultExt};
79
use log::info;
810
use std::borrow::Cow;
911
use std::path::Path;
@@ -95,6 +97,8 @@ impl std::fmt::Display for RustupThing {
9597

9698
/// Metadata of a CI toolchain. See [`Toolchain`](struct.Toolchain.html) to create and get it.
9799
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash, Debug, Clone)]
100+
#[cfg(any(feature = "unstable-toolchain-ci", doc))]
101+
#[cfg_attr(docs_rs, doc(cfg(feature = "unstable-toolchain-ci")))]
98102
pub struct CiToolchain {
99103
/// Hash of the merge commit of the PR you want to download.
100104
sha: String,
@@ -103,6 +107,7 @@ pub struct CiToolchain {
103107
alt: bool,
104108
}
105109

110+
#[cfg(any(feature = "unstable-toolchain-ci", doc))]
106111
impl CiToolchain {
107112
/// Get the SHA of the git commit that produced this toolchain.
108113
pub fn sha(&self) -> &str {
@@ -149,6 +154,7 @@ impl CiToolchain {
149154
enum ToolchainInner {
150155
Dist(DistToolchain),
151156
#[serde(rename = "ci")]
157+
#[cfg(feature = "unstable-toolchain-ci")]
152158
CI(CiToolchain),
153159
}
154160

@@ -197,6 +203,8 @@ impl Toolchain {
197203
/// **There is no availability or stability guarantee for these builds!**
198204
///
199205
/// [repo]: https://github.com/rust-lang/rust
206+
#[cfg(any(feature = "unstable-toolchain-ci", doc))]
207+
#[cfg_attr(docs_rs, doc(cfg(feature = "unstable-toolchain-ci")))]
200208
pub fn ci(sha: &str, alt: bool) -> Self {
201209
Toolchain {
202210
inner: ToolchainInner::CI(CiToolchain {
@@ -207,6 +215,7 @@ impl Toolchain {
207215
}
208216

209217
/// If this toolchain is a dist toolchain, return its metadata.
218+
#[allow(irrefutable_let_patterns)]
210219
pub fn as_dist(&self) -> Option<&DistToolchain> {
211220
if let ToolchainInner::Dist(dist) = &self.inner {
212221
Some(dist)
@@ -216,6 +225,8 @@ impl Toolchain {
216225
}
217226

218227
/// If this toolchain is a CI toolchain, return its metadata.
228+
#[cfg(any(feature = "unstable-toolchain-ci", doc))]
229+
#[cfg_attr(docs_rs, doc(cfg(feature = "unstable-toolchain-ci")))]
219230
pub fn as_ci(&self) -> Option<&CiToolchain> {
220231
if let ToolchainInner::CI(ci) = &self.inner {
221232
Some(ci)
@@ -228,6 +239,7 @@ impl Toolchain {
228239
pub fn install(&self, workspace: &Workspace) -> Result<(), Error> {
229240
match &self.inner {
230241
ToolchainInner::Dist(dist) => dist.init(workspace)?,
242+
#[cfg(feature = "unstable-toolchain-ci")]
231243
ToolchainInner::CI(ci) => ci.init(workspace)?,
232244
}
233245

@@ -287,13 +299,15 @@ impl Toolchain {
287299
let thing = thing.to_string();
288300
let action = action.to_string();
289301

302+
#[cfg(feature = "unstable-toolchain-ci")]
290303
if let ToolchainInner::CI { .. } = self.inner {
291-
bail!(
304+
failure::bail!(
292305
"{} {} on CI toolchains is not supported yet",
293306
log_action_ing,
294307
thing
295308
);
296309
}
310+
297311
let toolchain_name = self.rustup_name();
298312
info!(
299313
"{} {} {} for toolchain {}",
@@ -419,7 +433,9 @@ impl Toolchain {
419433
fn rustup_name(&self) -> String {
420434
match &self.inner {
421435
ToolchainInner::Dist(dist) => dist.name.to_string(),
436+
#[cfg(feature = "unstable-toolchain-ci")]
422437
ToolchainInner::CI(ci) if ci.alt => format!("{}-alt", ci.sha),
438+
#[cfg(feature = "unstable-toolchain-ci")]
423439
ToolchainInner::CI(ci) => ci.sha.to_string(),
424440
}
425441
}
@@ -462,12 +478,15 @@ pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result<Vec<Toolch
462478
if entry.file_type()?.is_symlink() || update_hashes.join(&name).exists() {
463479
result.push(Toolchain::dist(&name));
464480
} else {
465-
let (sha, alt) = if name.ends_with("-alt") {
466-
((&name[..name.len() - 4]).to_string(), true)
467-
} else {
468-
(name, false)
469-
};
470-
result.push(Toolchain::ci(&sha, alt));
481+
#[cfg(feature = "unstable-toolchain-ci")]
482+
{
483+
let (sha, alt) = if name.ends_with("-alt") {
484+
((&name[..name.len() - 4]).to_string(), true)
485+
} else {
486+
(name, false)
487+
};
488+
result.push(Toolchain::ci(&sha, alt));
489+
}
471490
}
472491
}
473492
Ok(result)
@@ -479,12 +498,20 @@ mod tests {
479498
use failure::Error;
480499

481500
#[test]
482-
fn test_serde_repr() -> Result<(), Error> {
501+
fn test_dist_serde_repr() -> Result<(), Error> {
483502
const DIST: &str = r#"{"type": "dist", "name": "stable"}"#;
503+
504+
assert_eq!(Toolchain::dist("stable"), serde_json::from_str(DIST)?);
505+
506+
Ok(())
507+
}
508+
509+
#[test]
510+
#[cfg(feature = "unstable-toolchain-ci")]
511+
fn test_ci_serde_repr() -> Result<(), Error> {
484512
const CI_NORMAL: &str = r#"{"type": "ci", "sha": "0000000", "alt": false}"#;
485513
const CI_ALT: &str = r#"{"type": "ci", "sha": "0000000", "alt": true}"#;
486514

487-
assert_eq!(Toolchain::dist("stable"), serde_json::from_str(DIST)?);
488515
assert_eq!(
489516
Toolchain::ci("0000000", false),
490517
serde_json::from_str(CI_NORMAL)?
@@ -537,11 +564,21 @@ mod tests {
537564
)?;
538565

539566
let res = super::list_installed_toolchains(rustup_home.path())?;
540-
assert_eq!(4, res.len());
567+
568+
let mut expected_count = 0;
569+
541570
assert!(res.contains(&Toolchain::dist(DIST_NAME)));
542571
assert!(res.contains(&Toolchain::dist(LINK_NAME)));
543-
assert!(res.contains(&Toolchain::ci(CI_SHA, false)));
544-
assert!(res.contains(&Toolchain::ci(CI_SHA, true)));
572+
expected_count += 2;
573+
574+
#[cfg(feature = "unstable-toolchain-ci")]
575+
{
576+
assert!(res.contains(&Toolchain::ci(CI_SHA, false)));
577+
assert!(res.contains(&Toolchain::ci(CI_SHA, true)));
578+
expected_count += 2;
579+
}
580+
581+
assert_eq!(res.len(), expected_count);
545582

546583
Ok(())
547584
}

src/tools/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::path::PathBuf;
1111

1212
pub(crate) static RUSTUP: Rustup = Rustup;
1313

14+
#[cfg(feature = "unstable-toolchain-ci")]
1415
pub(crate) static RUSTUP_TOOLCHAIN_INSTALL_MASTER: BinaryCrate = BinaryCrate {
1516
crate_name: "rustup-toolchain-install-master",
1617
binary: "rustup-toolchain-install-master",
@@ -25,6 +26,7 @@ pub(crate) static GIT_CREDENTIAL_NULL: BinaryCrate = BinaryCrate {
2526

2627
static INSTALLABLE_TOOLS: &[&dyn Tool] = &[
2728
&RUSTUP,
29+
#[cfg(feature = "unstable-toolchain-ci")]
2830
&RUSTUP_TOOLCHAIN_INSTALL_MASTER,
2931
&GIT_CREDENTIAL_NULL,
3032
];

0 commit comments

Comments
 (0)