cairo_lang_filesystem/
detect.rs

1use std::path::PathBuf;
2
3pub fn detect_corelib() -> Option<PathBuf> {
4    for (base, up_options) in [
5        // This is the directory of Cargo.toml of the current crate.
6        // This is used for development of the compiler.
7        (std::env::var("CARGO_MANIFEST_DIR").ok().map(PathBuf::from), 1..=2),
8        // This is the directory of the executable.
9        (std::env::current_exe().ok(), 2..=4),
10        // This is the current directory.
11        (std::env::current_dir().ok(), 0..=0),
12    ] {
13        let Some(base) = base else { continue };
14        for up in up_options {
15            let mut path = base.clone();
16            for _ in 0..up {
17                path.pop();
18            }
19            path.push("corelib");
20            path.push("src");
21            if path.exists() {
22                return Some(path);
23            }
24        }
25    }
26    None
27}