temp-commit

This commit is contained in:
Konstantin Bogdanov 2024-11-22 19:52:06 +01:00
parent ddde64300f
commit c0f66a3d0e
No known key found for this signature in database
5 changed files with 54 additions and 33 deletions

View File

@ -600,7 +600,8 @@ if (COMPILER_CACHE STREQUAL "chcache")
if (target IN_LIST chcache_targets)
continue()
endif()
add_dependencies(${target} chcache)
add_dependencies(${target} cargo-build_chcache)
endforeach()
endif()

View File

@ -24,6 +24,7 @@ elseif(COMPILER_CACHE STREQUAL "chcache")
include ("${ClickHouse_SOURCE_DIR}/contrib/corrosion/cmake/Corrosion.cmake")
corrosion_import_crate(
MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/utils/chcache/Cargo.toml
PROFILE release
LOCKED
)
set_target_properties(chcache PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/programs/)

View File

@ -170,14 +170,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chcache-rust"
version = "0.1.0"
name = "chcache"
version = "1.0.0"
dependencies = [
"blake3",
"clickhouse",
"env_logger",
"log",
"serde",
"serde_bytes",
"tokio",
"toml",
"xdg",
@ -1030,6 +1031,15 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde_bytes"
version = "0.11.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a"
dependencies = [
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.214"

View File

@ -1,6 +1,6 @@
[package]
name = "chcache-rust"
version = "0.1.0"
name = "chcache"
version = "1.0.0"
edition = "2021"
[dependencies]
@ -9,6 +9,7 @@ clickhouse = { version = "0.13.1", features = ["rustls-tls"] }
env_logger = { version = "0.11.5", default-features = false }
log = "0.4.22"
serde = { version = "1.0.210", features = ["serde_derive"] }
serde_bytes = "0.11.15"
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
toml = "0.8.19"
xdg = "2.5.2"

View File

@ -11,27 +11,46 @@ struct Config {
}
#[tokio::main]
async fn main() {
// let config_path = xdg::BaseDirectories::with_prefix("chcache")
// .unwrap()
// .place_config_file("config.toml")
// .unwrap();
//
// if !config_path.exists() {
// panic!("Config file not found at {}", config_path.display());
// }
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config_path = xdg::BaseDirectories::with_prefix("chcache")
.unwrap()
.place_config_file("config.toml")
.unwrap();
// let config = fs::read_to_string(config_path).expect("Missing config file?");
// let config: Config = toml::from_str(&config).expect("Unable to load config, is it a valid toml?");
let config: Config = Config {
hostname: std::env::var("CH_HOSTNAME").unwrap(),
user: std::env::var("CH_USER").unwrap(),
password: std::env::var("CH_PASSWORD").unwrap(),
let config: Config = match config_path.exists() {
true => {
trace!("Loading config file contents from {}", config_path.display());
let config_text = fs::read_to_string(config_path).expect("Missing config file?");
toml::from_str(&config_text).expect("Unable to load config, is it a valid toml?")
}
false => {
trace!("Config file not found at {}, trying env vars", config_path.display());
let required_env_vars = vec!["CH_HOSTNAME", "CH_USER", "CH_PASSWORD"];
for var in required_env_vars {
if std::env::var(var).is_err() {
return Err(format!(
"Please set a missing environment variable {} or place a config file at {}",
var,
config_path.display(),
).into());
}
}
Config {
hostname: std::env::var("CH_HOSTNAME").unwrap(),
user: std::env::var("CH_USER").unwrap(),
password: std::env::var("CH_PASSWORD").unwrap(),
}
}
};
env_logger::init();
compiler_cache_entrypoint(&config).await;
Ok(())
}
fn assume_base_path(args: &Vec<String>) -> String {
@ -83,18 +102,6 @@ fn assume_base_path(args: &Vec<String>) -> String {
}
fn compiler_version(compiler: String) -> String {
// let find_compiler_vars = vec![
// "CXX",
// "CC",
// ];
//
// let compiler_from_env = find_compiler_vars
// .iter()
// .map(|x| std::env::var(x))
// .find(|x| x.is_ok())
// .unwrap_or_else(|| Ok(String::from("clang")))
// .unwrap();
trace!("Using compiler: {}", compiler);
let compiler_version = std::process::Command::new(compiler)
@ -247,6 +254,7 @@ async fn load_from_clickhouse(
#[derive(Debug, clickhouse::Row, serde::Serialize, serde::Deserialize)]
struct MyRow {
#[serde(with = "serde_bytes")]
blob: Vec<u8>,
hash: String,
compiler_version: String,
@ -353,7 +361,7 @@ async fn compiler_cache_entrypoint(config: &Config) {
.args(&rest_of_args)
.output()
.unwrap();
if output.status.code().unwrap() != 0 {
if !output.status.success() {
println!("{}", String::from_utf8_lossy(&output.stdout));
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
return;