|
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 | +} |
0 commit comments