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 @@ -125,6 +125,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
39 changes: 39 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use cfg_aliases::cfg_aliases;

fn main() {
cfg_aliases! {
// All remote cache backends
any_cache_remote: {
any(
feature = "azure",
feature = "gcs",
feature = "gha",
feature = "memcached",
feature = "redis",
feature = "s3",
feature = "webdav",
feature = "oss",
feature = "cos"
)
},
// 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"
)
},
// 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 @@ -30,17 +30,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 @@ -135,51 +125,21 @@ 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>>,
}

#[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>>) -> Self {
Self { operator, basedirs }
}
}

/// 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 @@ -283,17 +243,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 @@ -493,17 +443,7 @@ pub fn storage_from_config(
config: &Config,
pool: &tokio::runtime::Handle,
) -> Result<Arc<dyn Storage>> {
#[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 @@ -39,15 +39,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
20 changes: 10 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::util::normalize_win_path;
use directories::ProjectDirs;
use fs::File;
use fs_err as fs;
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
use serde::ser::Serializer;
use serde::{
Deserialize, Serialize,
Expand Down Expand Up @@ -128,10 +128,10 @@ pub fn parse_size(val: &str) -> Option<u64> {
u64::from_str(val).ok().map(|size| size * multiplier)
}

#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct HTTPUrl(reqwest::Url);
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
impl Serialize for HTTPUrl {
fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error>
where
Expand All @@ -140,7 +140,7 @@ impl Serialize for HTTPUrl {
serializer.serialize_str(self.0.as_str())
}
}
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
impl<'a> Deserialize<'a> for HTTPUrl {
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>
where
Expand All @@ -152,7 +152,7 @@ impl<'a> Deserialize<'a> for HTTPUrl {
Ok(HTTPUrl(url))
}
}
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
fn parse_http_url(url: &str) -> Result<reqwest::Url> {
use std::net::SocketAddr;
let url = if let Ok(sa) = url.parse::<SocketAddr>() {
Expand All @@ -170,7 +170,7 @@ fn parse_http_url(url: &str) -> Result<reqwest::Url> {
}
Ok(url)
}
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
impl HTTPUrl {
pub fn from_url(u: reqwest::Url) -> Self {
HTTPUrl(u)
Expand Down Expand Up @@ -621,9 +621,9 @@ impl Default for DistAuth {
#[serde(deny_unknown_fields)]
pub struct DistConfig {
pub auth: DistAuth,
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
pub scheduler_url: Option<HTTPUrl>,
#[cfg(not(any(feature = "dist-client", feature = "dist-server")))]
#[cfg(not(any_dist))]
pub scheduler_url: Option<String>,
pub cache_dir: PathBuf,
pub toolchains: Vec<DistToolchainConfig>,
Expand Down Expand Up @@ -2204,13 +2204,13 @@ key_prefix = "cosprefix"
auth: DistAuth::Token {
token: "secrettoken".to_owned()
},
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
scheduler_url: Some(
parse_http_url("http://1.2.3.4:10600")
.map(|url| { HTTPUrl::from_url(url) })
.expect("Scheduler url must be valid url str")
),
#[cfg(not(any(feature = "dist-client", feature = "dist-server")))]
#[cfg(not(any_dist))]
scheduler_url: Some("http://1.2.3.4:10600".to_owned()),
cache_dir: PathBuf::from("/home/user/.cache/sccache-dist-client"),
toolchains: vec![],
Expand Down
6 changes: 3 additions & 3 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ use std::sync::Mutex;

use crate::errors::*;

#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
mod cache;
#[cfg(feature = "dist-client")]
pub mod client_auth;
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
pub mod http;
#[cfg(test)]
mod test;

#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any_dist)]
pub use crate::dist::cache::TcCache;

// TODO: paths (particularly outputs, which are accessed by an unsandboxed program)
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ pub fn daemonize() -> Result<()> {
/// ---
///
/// More details could be found at https://github.com/mozilla/sccache/pull/1563
#[cfg(any(feature = "dist-server", feature = "dist-client"))]
#[cfg(any_dist)]
pub fn new_reqwest_blocking_client() -> reqwest::blocking::Client {
reqwest::blocking::Client::builder()
.pool_max_idle_per_host(0)
Expand Down
Loading