Skip to content

[WIP] Adding a configuration option to specify rustc version #229

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

Closed
wants to merge 1 commit into from
Closed
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
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();
}