Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit 4bb5300

Browse files
committed
Convert version-grabbing to rust
1 parent 274a984 commit 4bb5300

File tree

3 files changed

+50
-16
lines changed

3 files changed

+50
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "core"
33
version = "1.0.0"
4-
authors = ["Ben Harris <mail@bharr.is>", "Matt Ickstadt <matt@icky.pw>"]
4+
authors = ["Ben Harris <mail@bharr.is>", "Matt Ickstadt <matt@icky.pw>", "Matt Coffin <mcoffin13@gmail.com>"]
55
build = "./build.rs"
66

77
[lib]

build.rs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
1-
use std::process::Command;
2-
3-
fn main() {
4-
// Shell out to perform the build. In the future, the logic
5-
// to grab libcore could be done in rust in order to support
6-
// platforms without a posix shell
7-
Command::new("sh").arg("./build.sh").status().unwrap_or_else(|e| {
8-
panic!("failed to execute process: {}", e)
9-
});
10-
}
1+
use std::process::Command;
2+
use std::env;
3+
use std::fs;
4+
use std::io;
5+
use std::path::Path;
6+
7+
const RUST_DIR: &'static str = "./rust";
8+
9+
fn ensure_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
10+
let path = path.as_ref();
11+
match fs::read_dir(path) {
12+
Ok(..) => Ok(()),
13+
Err(..) => fs::create_dir(path),
14+
}
15+
}
16+
17+
fn main() {
18+
// Ensure the rust directory exists
19+
if let Err(e) = ensure_dir(RUST_DIR) {
20+
panic!(e);
21+
}
22+
23+
// cd to the rust directory
24+
if let Err(e) = env::set_current_dir(RUST_DIR) {
25+
panic!(e);
26+
}
27+
28+
// Run rustc to get the version
29+
let rustc_output = Command::new("rustc").arg("--version")
30+
.output().unwrap_or_else(|e| {
31+
panic!("failed to execute rustc: {}", e);
32+
});
33+
let output_bytes: &[u8] = rustc_output.stdout.as_ref();
34+
let version = match std::str::from_utf8(output_bytes) {
35+
Ok(s) => s.split(" ").nth(2).expect("rustc gave invalid version format"),
36+
Err(e) => panic!(e),
37+
}.trim_left_matches("(");
38+
39+
// Shell out to perform the build. In the future, the logic
40+
// to grab libcore could be done in rust in order to support
41+
// platforms without a posix shell
42+
Command::new("sh")
43+
.arg("../build.sh")
44+
.env("DOWNLOAD_LINK",
45+
format!("https://github.com/rust-lang/rust/tarball/{}", version))
46+
.status().unwrap_or_else(|e| {
47+
panic!("failed to execute process: {}", e);
48+
});
49+
}

build.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
#!/bin/sh
2-
mkdir -p rust
3-
cd rust
4-
5-
DOWNLOAD_LINK="https://github.com/rust-lang/rust/tarball/`rustc --version|awk '{sub(/\\(/, "", $3); print $3}'`"
6-
72
which wget >/dev/null 2>/dev/null
83
if [ $? -eq 0 ]; then
94
wget -q -O rust.tar.gz "$DOWNLOAD_LINK"

0 commit comments

Comments
 (0)