Skip to content

Commit bdfb048

Browse files
committed
Adding a configuration option to specify rustc version used
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
1 parent 32102ce commit bdfb048

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/docbuilder/metadata.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ pub struct Metadata {
4545
/// is always built on this target. You can change default target by setting this.
4646
pub default_target: Option<String>,
4747

48+
/// Define the Rust version that will be used to build documentation
49+
///
50+
/// You can either provide a specific nightly (such as `2018-08-18`) or
51+
/// simply `nightly` to always use the current.
52+
///
53+
/// Note: Depending on latest nightly can easily break your documentation!
54+
pub rustc_version: Option<String>,
55+
4856
/// List of command line arguments for `rustc`.
4957
pub rustc_args: Option<Vec<String>>,
5058

@@ -90,6 +98,7 @@ impl Metadata {
9098
fn default() -> Metadata {
9199
Metadata {
92100
features: None,
101+
rustc_version: None,
93102
all_features: false,
94103
no_default_features: false,
95104
default_target: None,
@@ -120,6 +129,10 @@ impl Metadata {
120129
.and_then(|v| v.as_bool()).unwrap_or(metadata.all_features);
121130
metadata.default_target = table.get("default-target")
122131
.and_then(|v| v.as_str()).map(|v| v.to_owned());
132+
metadata.rustc_version = table.get("rustc-version").and_then(|f| match f {
133+
Value::String(s) => Some(s.clone()),
134+
_ => None,
135+
});
123136
metadata.rustc_args = table.get("rustc-args").and_then(|f| f.as_array())
124137
.and_then(|f| f.iter().map(|v| v.as_str().map(|v| v.to_owned())).collect());
125138
metadata.rustdoc_args = table.get("rustdoc-args").and_then(|f| f.as_array())

src/utils/build_doc.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use cargo::ops::{self, Packages, DefaultExecutor};
1515
use utils::{get_current_versions, parse_rustc_version};
1616
use error::Result;
1717

18+
use super::rustup;
19+
1820
use Metadata;
1921

2022

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

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

54+
// Change rustc version if requested
55+
if metadata.rustc_version.is_some() {
56+
rustup::set_version(metadata.rustc_version.unwrap());
57+
}
58+
5259
// This is only way to pass rustc_args to cargo.
5360
// CompileOptions::target_rustc_args is used only for the current crate,
5461
// and since docs.rs never runs rustc on the current crate, we assume rustc_args

src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ mod daemon;
1717
mod pubsubhubbub;
1818
mod rustc_version;
1919
mod html;
20+
mod rustup;

src/utils/rustup.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! A wrapper around using rustup
2+
//!
3+
4+
use std::process::Command;
5+
6+
/// Invoke rustup in a folder to `override set` a rustc version
7+
pub fn set_version(v: String) {
8+
Command::new("rustup")
9+
.arg("override")
10+
.arg("set")
11+
.arg(v)
12+
.output()
13+
.unwrap();
14+
}

0 commit comments

Comments
 (0)