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
use std::path::PathBuf;

pub fn detect_corelib() -> PathBuf {
    if let Ok(cargo_dir) = std::env::var("CARGO_MANIFEST_DIR") {
        // This is the directory of Cargo.toml of the current crate.
        // This is used for developement of the compiler.
        let mut dir = PathBuf::from(cargo_dir);
        dir.pop();
        dir.push("corelib");
        if dir.exists() {
            return dir;
        }
        dir.pop();
        dir.pop();
        dir.push("corelib");
        if dir.exists() {
            return dir;
        }
    }
    if let Ok(mut dir) = std::env::current_exe() {
        dir.pop();
        dir.pop();
        dir.push("corelib");
        if dir.exists() {
            return dir;
        }
        dir.pop();
        dir.pop();
        dir.push("corelib");
        if dir.exists() {
            return dir;
        }
    }
    panic!("Corelib not found.")
}