cubecl_runtime/config/
cache.rs1#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
3pub enum CacheConfig {
4 #[serde(rename = "local")]
6 Local,
7
8 #[default]
10 #[serde(rename = "target")]
11 Target,
12
13 #[serde(rename = "global")]
15 Global,
16
17 #[serde(rename = "file")]
19 File(std::path::PathBuf),
20}
21
22impl CacheConfig {
23 pub fn root(&self) -> std::path::PathBuf {
25 match self {
26 Self::Local => std::env::current_dir().unwrap(),
27 Self::Target => {
28 let dir_original = std::env::current_dir().unwrap();
29 let mut dir = dir_original.clone();
30
31 loop {
33 if let Ok(true) = std::fs::exists(dir.join("Cargo.toml")) {
34 return dir.join("target");
35 }
36
37 if !dir.pop() {
38 break;
39 }
40 }
41
42 dir_original.join("target")
43 }
44 Self::Global => dirs::config_local_dir().unwrap(),
45 Self::File(path_buf) => path_buf.clone(),
46 }
47 }
48}