Skip to content

Hide CI toolchains behind the unstable-toolchain-ci feature #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

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

Expand Down
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ readme = "README.md"

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

[package.metadata.docs.rs]
features = ["unstable"]

[features]
unstable = []
unstable-toolchain-ci = []

[dependencies]
failure = "0.1.3"
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
//! * **unstable**: allow Rustwide to use unstable Rust and Cargo features. While this feature also
//! works on Rust stable it might cause Rustwide to break, and **no stability guarantee is
//! present when using it!**
//! * **unstable-toolchain-ci**: allow fetching toolchains from rustc's CI artifacts storage. Support for
//! them is **incomplete** (not all methods might work), and there is **no stability guarantee**
//! when using them!
//!
//! [crater]: https://github.com/rust-lang/crater
//! [docsrs]: https://github.com/rust-lang/docs.rs
Expand Down
65 changes: 51 additions & 14 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Tools to manage and use Rust toolchains.

use crate::cmd::{Binary, Command, Runnable};
use crate::tools::{RUSTUP, RUSTUP_TOOLCHAIN_INSTALL_MASTER};
use crate::tools::RUSTUP;
#[cfg(feature = "unstable-toolchain-ci")]
use crate::tools::RUSTUP_TOOLCHAIN_INSTALL_MASTER;
use crate::Workspace;
use failure::{bail, Error, ResultExt};
use failure::{Error, ResultExt};
use log::info;
use std::borrow::Cow;
use std::path::Path;
Expand Down Expand Up @@ -95,6 +97,8 @@ impl std::fmt::Display for RustupThing {

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

#[cfg(any(feature = "unstable-toolchain-ci", doc))]
impl CiToolchain {
/// Get the SHA of the git commit that produced this toolchain.
pub fn sha(&self) -> &str {
Expand Down Expand Up @@ -149,6 +154,7 @@ impl CiToolchain {
enum ToolchainInner {
Dist(DistToolchain),
#[serde(rename = "ci")]
#[cfg(feature = "unstable-toolchain-ci")]
CI(CiToolchain),
}

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

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

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

Expand Down Expand Up @@ -287,13 +299,15 @@ impl Toolchain {
let thing = thing.to_string();
let action = action.to_string();

#[cfg(feature = "unstable-toolchain-ci")]
if let ToolchainInner::CI { .. } = self.inner {
bail!(
failure::bail!(
"{} {} on CI toolchains is not supported yet",
log_action_ing,
thing
);
}

let toolchain_name = self.rustup_name();
info!(
"{} {} {} for toolchain {}",
Expand Down Expand Up @@ -419,7 +433,9 @@ impl Toolchain {
fn rustup_name(&self) -> String {
match &self.inner {
ToolchainInner::Dist(dist) => dist.name.to_string(),
#[cfg(feature = "unstable-toolchain-ci")]
ToolchainInner::CI(ci) if ci.alt => format!("{}-alt", ci.sha),
#[cfg(feature = "unstable-toolchain-ci")]
ToolchainInner::CI(ci) => ci.sha.to_string(),
}
}
Expand Down Expand Up @@ -462,12 +478,15 @@ pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result<Vec<Toolch
if entry.file_type()?.is_symlink() || update_hashes.join(&name).exists() {
result.push(Toolchain::dist(&name));
} else {
let (sha, alt) = if name.ends_with("-alt") {
((&name[..name.len() - 4]).to_string(), true)
} else {
(name, false)
};
result.push(Toolchain::ci(&sha, alt));
#[cfg(feature = "unstable-toolchain-ci")]
{
let (sha, alt) = if name.ends_with("-alt") {
((&name[..name.len() - 4]).to_string(), true)
} else {
(name, false)
};
result.push(Toolchain::ci(&sha, alt));
}
}
}
Ok(result)
Expand All @@ -479,12 +498,20 @@ mod tests {
use failure::Error;

#[test]
fn test_serde_repr() -> Result<(), Error> {
fn test_dist_serde_repr() -> Result<(), Error> {
const DIST: &str = r#"{"type": "dist", "name": "stable"}"#;

assert_eq!(Toolchain::dist("stable"), serde_json::from_str(DIST)?);

Ok(())
}

#[test]
#[cfg(feature = "unstable-toolchain-ci")]
fn test_ci_serde_repr() -> Result<(), Error> {
const CI_NORMAL: &str = r#"{"type": "ci", "sha": "0000000", "alt": false}"#;
const CI_ALT: &str = r#"{"type": "ci", "sha": "0000000", "alt": true}"#;

assert_eq!(Toolchain::dist("stable"), serde_json::from_str(DIST)?);
assert_eq!(
Toolchain::ci("0000000", false),
serde_json::from_str(CI_NORMAL)?
Expand Down Expand Up @@ -537,11 +564,21 @@ mod tests {
)?;

let res = super::list_installed_toolchains(rustup_home.path())?;
assert_eq!(4, res.len());

let mut expected_count = 0;

assert!(res.contains(&Toolchain::dist(DIST_NAME)));
assert!(res.contains(&Toolchain::dist(LINK_NAME)));
assert!(res.contains(&Toolchain::ci(CI_SHA, false)));
assert!(res.contains(&Toolchain::ci(CI_SHA, true)));
expected_count += 2;

#[cfg(feature = "unstable-toolchain-ci")]
{
assert!(res.contains(&Toolchain::ci(CI_SHA, false)));
assert!(res.contains(&Toolchain::ci(CI_SHA, true)));
expected_count += 2;
}

assert_eq!(res.len(), expected_count);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::path::PathBuf;

pub(crate) static RUSTUP: Rustup = Rustup;

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

static INSTALLABLE_TOOLS: &[&dyn Tool] = &[
&RUSTUP,
#[cfg(feature = "unstable-toolchain-ci")]
&RUSTUP_TOOLCHAIN_INSTALL_MASTER,
&GIT_CREDENTIAL_NULL,
];
Expand Down