Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ rouille = { version = "3.6", optional = true, default-features = false, features
syslog = { version = "7", optional = true }
version-compare = { version = "0.1.1", optional = true }

[build-dependencies]
cfg_aliases = "0.2.1"

[dev-dependencies]
assert_cmd = "2.0.13"
cc = "1.0"
Expand Down
33 changes: 33 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use cfg_aliases::cfg_aliases;

fn main() {
cfg_aliases! {
// HTTP-based remote cache backends (excludes memcached and redis)
any_http_remote: {
any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
)
},
// All remote cache backends
any_cache_remote: {
any(
any_http_remote,
feature = "memcached",
feature = "redis"
)
},
// Distributed compilation features
any_dist: {
any(
feature = "dist-client",
feature = "dist-server"
)
},
}
}
72 changes: 6 additions & 66 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ use crate::cache::oss::OSSCache;
use crate::cache::redis::RedisCache;
#[cfg(feature = "s3")]
use crate::cache::s3::S3Cache;
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
use crate::cache::utils::normalize_key;
#[cfg(feature = "webdav")]
use crate::cache::webdav::WebdavCache;
Expand Down Expand Up @@ -175,34 +165,14 @@ pub trait Storage: Send + Sync {
}

/// Wrapper for opendal::Operator that adds basedirs support
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
pub struct RemoteStorage {
operator: opendal::Operator,
basedirs: Vec<Vec<u8>>,
rw_mode: CacheMode,
}

#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
impl RemoteStorage {
pub fn new(operator: opendal::Operator, basedirs: Vec<Vec<u8>>, rw_mode: CacheMode) -> Self {
Self {
Expand All @@ -214,17 +184,7 @@ impl RemoteStorage {
}

/// Implement storage for operator.
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
#[async_trait]
impl Storage for RemoteStorage {
async fn get(&self, key: &str) -> Result<Cache> {
Expand Down Expand Up @@ -380,17 +340,7 @@ impl Storage for RemoteStorage {

/// Build a single cache storage from CacheType
/// Helper function used by storage_from_config for both single and multi-level caches
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
pub fn build_single_cache(
cache_type: &CacheType,
basedirs: &[Vec<u8>],
Expand Down Expand Up @@ -601,17 +551,7 @@ pub fn storage_from_config(
}

// Single cache or fallback to disk (backward compatible path)
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
if let Some(cache_type) = &config.cache {
debug!("Configuring single cache from CacheType");
return build_single_cache(cache_type, &config.basedirs, pool);
Expand Down
10 changes: 1 addition & 9 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,7 @@ pub(crate) mod utils;
#[cfg(feature = "webdav")]
pub mod webdav;

#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_http_remote)]
pub(crate) mod http_client;

pub use crate::cache::cache::*;
Expand Down
142 changes: 16 additions & 126 deletions src/cache/multilevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,11 @@ use std::time::{Duration, Instant};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};

#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
use crate::cache::build_single_cache;
use crate::cache::disk::DiskCache;
use crate::cache::{Cache, CacheMode, CacheWrite, Storage};
use crate::compiler::PreprocessorCacheEntry;
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
use crate::config::CacheType;
use crate::config::{Config, PreprocessorCacheModeConfig, WriteErrorPolicy};
use crate::errors::*;

Expand Down Expand Up @@ -445,113 +423,25 @@ impl MultiLevelStorage {
trace!("Added disk cache level");
} else {
// Build remote cache - get the appropriate CacheType
#[cfg(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
))]
#[cfg(any_cache_remote)]
{
let cache_type = match level_name.to_lowercase().as_str() {
#[cfg(feature = "s3")]
"s3" => config.cache_configs.s3.clone().map(CacheType::S3),
#[cfg(not(feature = "s3"))]
"s3" => return Err(anyhow!("Cache level 's3' requires the 's3' feature")),
#[cfg(feature = "redis")]
"redis" => config.cache_configs.redis.clone().map(CacheType::Redis),
#[cfg(not(feature = "redis"))]
"redis" => {
return Err(anyhow!(
"Cache level 'redis' requires the 'redis' feature"
));
}
#[cfg(feature = "memcached")]
"memcached" => config
.cache_configs
.memcached
.clone()
.map(CacheType::Memcached),
#[cfg(not(feature = "memcached"))]
"memcached" => {
return Err(anyhow!(
"Cache level 'memcached' requires the 'memcached' feature"
));
}
#[cfg(feature = "gcs")]
"gcs" => config.cache_configs.gcs.clone().map(CacheType::GCS),
#[cfg(not(feature = "gcs"))]
"gcs" => {
return Err(anyhow!("Cache level 'gcs' requires the 'gcs' feature"));
}
#[cfg(feature = "gha")]
"gha" => config.cache_configs.gha.clone().map(CacheType::GHA),
#[cfg(not(feature = "gha"))]
"gha" => {
return Err(anyhow!("Cache level 'gha' requires the 'gha' feature"));
}
#[cfg(feature = "azure")]
"azure" => config.cache_configs.azure.clone().map(CacheType::Azure),
#[cfg(not(feature = "azure"))]
"azure" => {
return Err(anyhow!(
"Cache level 'azure' requires the 'azure' feature"
));
}
#[cfg(feature = "webdav")]
"webdav" => config.cache_configs.webdav.clone().map(CacheType::Webdav),
#[cfg(not(feature = "webdav"))]
"webdav" => {
return Err(anyhow!(
"Cache level 'webdav' requires the 'webdav' feature"
));
}
#[cfg(feature = "oss")]
"oss" => config.cache_configs.oss.clone().map(CacheType::OSS),
#[cfg(not(feature = "oss"))]
"oss" => {
return Err(anyhow!("Cache level 'oss' requires the 'oss' feature"));
}
#[cfg(feature = "cos")]
"cos" => config.cache_configs.cos.clone().map(CacheType::COS),
#[cfg(not(feature = "cos"))]
"cos" => {
return Err(anyhow!("Cache level 'cos' requires the 'cos' feature"));
}
_ => {
return Err(anyhow!("Unknown cache level: '{}'", level_name));
}
};

if let Some(cache_type) = cache_type {
let storage = build_single_cache(&cache_type, &config.basedirs, pool)
.with_context(|| {
format!("Failed to build cache for level '{}'", level_name)
})?;
storages.push(storage);
trace!("Added cache level: {}", level_name);
} else {
return Err(anyhow!(
let level_lower = level_name.to_lowercase();
let (_display_name, cache_type) =
config.cache_configs.cache_type_by_name(&level_lower)?;
let cache_type = cache_type.ok_or_else(|| {
anyhow!(
"Cache level '{}' specified in SCCACHE_MULTILEVEL_CHAIN but not configured (missing environment variables)",
level_name
));
}
)
})?;
let storage = build_single_cache(&cache_type, &config.basedirs, pool)
.with_context(|| {
format!("Failed to build cache for level '{}'", level_name)
})?;
storages.push(storage);
trace!("Added cache level: {}", level_name);
}
#[cfg(not(any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
)))]
#[cfg(not(any_cache_remote))]
{
return Err(anyhow!(
"Cache level '{}' requires a backend feature to be enabled (e.g., --features redis,s3)",
Expand Down
Loading
Loading