diff --git a/ort-sys/src/internal/dirs.rs b/ort-sys/src/internal/dirs.rs index 462f675..ba5a7fd 100644 --- a/ort-sys/src/internal/dirs.rs +++ b/ort-sys/src/internal/dirs.rs @@ -2,6 +2,8 @@ #![allow(unused)] +use std::path::PathBuf; + pub const PYKE_ROOT: &str = "ort.pyke.io"; #[cfg(all(target_os = "windows", target_arch = "x86"))] @@ -95,7 +97,7 @@ mod windows { } #[cfg(target_os = "windows")] #[must_use] -pub fn cache_dir() -> Option { +fn cache_dir_default() -> Option { self::windows::known_folder_local_app_data().map(|h| h.join(PYKE_ROOT)) } @@ -174,7 +176,7 @@ mod unix { #[cfg(target_os = "linux")] #[must_use] -pub fn cache_dir() -> Option { +fn cache_dir_default() -> Option { std::env::var_os("XDG_CACHE_HOME") .and_then(self::unix::is_absolute_path) .or_else(|| self::unix::home_dir().map(|h| h.join(".cache").join(PYKE_ROOT))) @@ -182,6 +184,10 @@ pub fn cache_dir() -> Option { #[cfg(target_os = "macos")] #[must_use] -pub fn cache_dir() -> Option { +fn cache_dir_default() -> Option { self::unix::home_dir().map(|h| h.join("Library/Caches").join(PYKE_ROOT)) } + +pub fn cache_dir() -> Option { + std::env::var_os("ORT_CACHE_DIR").map(PathBuf::from).or_else(cache_dir_default) +}