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
use std::path::{Path, PathBuf};
pub fn detect_corelib() -> Option<PathBuf> {
macro_rules! try_path {
($base:expr, $up:expr) => {{
let mut path = $base.to_path_buf();
for _ in 0..$up {
path.pop();
}
path.push("corelib");
path.push("src");
if path.exists() {
return Some(path);
}
}};
}
if let Ok(cargo_dir) = std::env::var("CARGO_MANIFEST_DIR") {
let dir = Path::new(&cargo_dir);
try_path!(dir, 1);
try_path!(dir, 2);
}
if let Ok(dir) = std::env::current_exe() {
try_path!(&dir, 2);
try_path!(&dir, 3);
}
None
}