Skip to content

Commit bc56788

Browse files
committed
Auto merge of #233 - jrvidal:rustc-check, r=fmoko
feat(cli): check for rustc before doing anything Addresses #190. From the backtraces shown there, it seems like we're not able to launch `rustc` (which is odd, given that they probably compiled and installed `rustlings` 🤷‍♀️)
2 parents 9544ba1 + 36a033b commit bc56788

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use notify::{RecommendedWatcher, RecursiveMode, Watcher};
77
use std::ffi::OsStr;
88
use std::fs;
99
use std::path::Path;
10+
use std::process::{Command, Stdio};
1011
use std::sync::mpsc::channel;
1112
use std::time::Duration;
1213

@@ -56,6 +57,13 @@ fn main() {
5657
std::process::exit(1);
5758
}
5859

60+
if !rustc_exists() {
61+
println!("We cannot find `rustc`.");
62+
println!("Try running `rustc --version` to diagnose your problem.");
63+
println!("For instructions on how to install Rust, check the README.");
64+
std::process::exit(1);
65+
}
66+
5967
let toml_str = &fs::read_to_string("info.toml").unwrap();
6068
let exercises = toml::from_str::<ExerciseList>(toml_str).unwrap().exercises;
6169

@@ -134,3 +142,13 @@ fn watch(exercises: &[Exercise]) -> notify::Result<()> {
134142
}
135143
}
136144
}
145+
146+
fn rustc_exists() -> bool {
147+
Command::new("rustc")
148+
.args(&["--version"])
149+
.stdout(Stdio::null())
150+
.spawn()
151+
.and_then(|mut child| child.wait())
152+
.map(|status| status.success())
153+
.unwrap_or(false)
154+
}

0 commit comments

Comments
 (0)