-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.rs
46 lines (38 loc) · 1.1 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const COMPONENTS: &[&str] = &["llvm-tools-preview", "rustc-dev"];
fn main() {
check_components();
#[cfg(docsrs)]
add_components();
}
fn check_components() {
use std::{fs::read_to_string, path::Path};
use toml::{Table, Value};
let rust_toolchain = Path::new("rust-toolchain");
if !rust_toolchain.try_exists().unwrap() {
return;
}
let contents = read_to_string(rust_toolchain).unwrap();
let table = contents.parse::<Table>().unwrap();
let array = table
.get("toolchain")
.and_then(Value::as_table)
.and_then(|table| table.get("components"))
.and_then(Value::as_array)
.unwrap();
let components = array
.iter()
.map(Value::as_str)
.collect::<Option<Vec<_>>>()
.unwrap();
assert_eq!(COMPONENTS, components);
}
#[cfg(docsrs)]
fn add_components() {
for component in COMPONENTS {
assert!(std::process::Command::new("rustup")
.args(["component", "add", component, "--toolchain", "nightly"])
.status()
.unwrap()
.success());
}
}