vdev/
platform.rs

1use std::{
2    env::consts::ARCH,
3    path::{Path, PathBuf},
4    sync::OnceLock,
5};
6
7use directories::ProjectDirs;
8
9pub fn canonicalize_path(path: impl AsRef<Path>) -> String {
10    let path = path.as_ref();
11    dunce::canonicalize(path)
12        .unwrap_or_else(|err| panic!("Could not canonicalize path {}: {err}", path.display()))
13        .display()
14        .to_string()
15}
16
17pub fn data_dir() -> &'static Path {
18    static DATA_DIR: OnceLock<PathBuf> = OnceLock::new();
19    DATA_DIR.get_or_init(|| {
20        ProjectDirs::from("", "vector", "vdev")
21            .expect("Could not determine the project directory")
22            .data_local_dir()
23            .to_path_buf()
24    })
25}
26
27pub fn default_target() -> String {
28    if cfg!(windows) {
29        format!("{ARCH}-pc-windows-msvc")
30    } else if cfg!(target_os = "macos") {
31        format!("{ARCH}-apple-darwin")
32    } else {
33        format!("{ARCH}-unknown-linux-gnu")
34    }
35}
36
37pub fn default_features() -> &'static str {
38    if cfg!(windows) {
39        "default-msvc"
40    } else {
41        "default"
42    }
43}