microcad-builtin 0.5.1

Provides the built-in functionalities available in the µcad language.
Documentation
// Copyright © 2025-2026 The µcad authors <info@microcad.xyz>
// SPDX-License-Identifier: AGPL-3.0-or-later

//! Builtin directories

/// `./std/lib` (if exists) and `~/.config/microcad/lib` (if exists).
pub fn default_search_paths() -> Vec<std::path::PathBuf> {
    let mut search_paths = Vec::new();

    if let Some(global_root_dir) = global_root_dir() {
        search_paths.push(global_root_dir);
    }

    let local_dir = std::path::PathBuf::from("./crates/std/lib");
    if local_dir.exists() {
        search_paths.push(local_dir);
    }
    if let Some(root_dir) = option_env!("STDLIB_PATH") {
        search_paths.push(root_dir.into());
    }

    search_paths
}

/// Returns microcad's config dir, even if it does not exist.
///
/// On Linux, the config dir is located in `~/.config/microcad`.
pub fn config_dir() -> Option<std::path::PathBuf> {
    dirs::config_dir().map(|dir| dir.join("microcad"))
}

/// Returns global root dir, even if it does not exist.
///
/// On Linux, the root dir is located in `~/.config/microcad/lib`.
pub fn global_root_dir() -> Option<std::path::PathBuf> {
    config_dir().map(|dir| dir.join("lib"))
}