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