Skip to content

Commit

Permalink
Adding a configuration option to specify rustc version used
Browse files Browse the repository at this point in the history
This code is maybe not as elegant as it could be but should hopefully work? I'm
not 100% sure how the crates are built (i.e. how the working directories are
built and scoped) so I hope that `rustup` is invoked in the correct directory.

If that's not the case, then this can be changed.

Additionally I am aware that this is a **work in progress** and further changes
are required on docs.rs and the compilers part to make "hot-swapping" versions
easier. See rust-lang#225 for more details. This PR addresses rust-lang#228
  • Loading branch information
spacekookie committed Aug 18, 2018
1 parent 32102ce commit bdfb048
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/docbuilder/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ pub struct Metadata {
/// is always built on this target. You can change default target by setting this.
pub default_target: Option<String>,

/// Define the Rust version that will be used to build documentation
///
/// You can either provide a specific nightly (such as `2018-08-18`) or
/// simply `nightly` to always use the current.
///
/// Note: Depending on latest nightly can easily break your documentation!
pub rustc_version: Option<String>,

/// List of command line arguments for `rustc`.
pub rustc_args: Option<Vec<String>>,

Expand Down Expand Up @@ -90,6 +98,7 @@ impl Metadata {
fn default() -> Metadata {
Metadata {
features: None,
rustc_version: None,
all_features: false,
no_default_features: false,
default_target: None,
Expand Down Expand Up @@ -120,6 +129,10 @@ impl Metadata {
.and_then(|v| v.as_bool()).unwrap_or(metadata.all_features);
metadata.default_target = table.get("default-target")
.and_then(|v| v.as_str()).map(|v| v.to_owned());
metadata.rustc_version = table.get("rustc-version").and_then(|f| match f {
Value::String(s) => Some(s.clone()),
_ => None,
});
metadata.rustc_args = table.get("rustc-args").and_then(|f| f.as_array())
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array())
Expand Down
7 changes: 7 additions & 0 deletions src/utils/build_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use cargo::ops::{self, Packages, DefaultExecutor};
use utils::{get_current_versions, parse_rustc_version};
use error::Result;

use super::rustup;

use Metadata;


Expand Down Expand Up @@ -49,6 +51,11 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> Result

let metadata = Metadata::from_package(&pkg).map_err(|e| human(e.description()))?;

// Change rustc version if requested
if metadata.rustc_version.is_some() {
rustup::set_version(metadata.rustc_version.unwrap());
}

// This is only way to pass rustc_args to cargo.
// CompileOptions::target_rustc_args is used only for the current crate,
// and since docs.rs never runs rustc on the current crate, we assume rustc_args
Expand Down
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ mod daemon;
mod pubsubhubbub;
mod rustc_version;
mod html;
mod rustup;
14 changes: 14 additions & 0 deletions src/utils/rustup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! A wrapper around using rustup
//!

use std::process::Command;

/// Invoke rustup in a folder to `override set` a rustc version
pub fn set_version(v: String) {
Command::new("rustup")
.arg("override")
.arg("set")
.arg(v)
.output()
.unwrap();
}

0 comments on commit bdfb048

Please sign in to comment.