diff --git a/Cargo.lock b/Cargo.lock index a2ccc39..f31f447 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1927,6 +1927,7 @@ dependencies = [ name = "icepick" version = "0.1.0" dependencies = [ + "bincode", "chrono", "clap", "icepick-module", @@ -1940,6 +1941,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "smex", "thiserror 2.0.11", "toml 0.8.19", ] diff --git a/crates/icepick/Cargo.toml b/crates/icepick/Cargo.toml index 204f1ba..1ad0bc4 100644 --- a/crates/icepick/Cargo.toml +++ b/crates/icepick/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +bincode = "1.3.3" chrono = { version = "0.4.39", default-features = false, features = ["now", "serde", "std"] } clap = { version = "4.5.20", features = ["cargo", "derive", "string"] } icepick-module = { version = "0.1.0", path = "../icepick-module" } @@ -17,9 +18,12 @@ miniquorum = { version = "0.1.0", path = "../miniquorum", default-features = fal serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["arbitrary_precision"] } serde_yaml = "0.9.34" +smex = { version = "0.1.0", registry = "distrust" } thiserror = "2.0.3" toml = "0.8.19" [build-dependencies] +bincode = "1.3.3" icepick-workflow = { version = "0.1.0", path = "../icepick-workflow" } serde_yaml = "0.9.34" +smex = { version = "0.1.0", registry = "distrust" } diff --git a/crates/icepick/build.rs b/crates/icepick/build.rs index 50c1471..d508a9b 100644 --- a/crates/icepick/build.rs +++ b/crates/icepick/build.rs @@ -1,5 +1,7 @@ use icepick_workflow::Workflow; use std::{collections::HashMap, path::{PathBuf, Path}}; +use smex; +use bincode; fn env_var(var: &'static str) -> String { println!("cargo::rerun-if-env-changed={var}"); @@ -10,19 +12,8 @@ fn track_path(path: &Path) { println!("cargo::rerun-if-changed={}", path.to_str().unwrap()); } -fn out_dir() -> PathBuf { - // example: [("OUT_DIR", "/tmp/cargo-target/debug/build/wat-c321129a1ce97284/out")] - // this gives us: /tmp/cargo-target/debug - let out_dir = env_var("OUT_DIR"); - let mut out_dir_path = PathBuf::from(out_dir); - out_dir_path.pop(); - out_dir_path.pop(); - out_dir_path.pop(); - out_dir_path -} - fn main() { - let out_dir = out_dir(); + let out_dir = env_var("OUT_DIR"); let crate_dir = env_var("CARGO_MANIFEST_DIR"); let workflows_dir = PathBuf::from(crate_dir).join("workflows"); track_path(&workflows_dir); @@ -55,7 +46,8 @@ fn main() { workflows, ); } - let out_path = out_dir.join("workflows.yaml"); - let out_file = std::fs::File::create(&out_path).unwrap(); - serde_yaml::to_writer(out_file, &workflows_by_module).unwrap(); + let out_path = PathBuf::from(out_dir).join("workflows.hex"); + let result = bincode::serialize(&workflows_by_module).unwrap(); + let hexed = smex::encode(&result); + std::fs::write(out_path, hexed).unwrap(); } diff --git a/crates/icepick/src/cli/mod.rs b/crates/icepick/src/cli/mod.rs index f45b548..f029535 100644 --- a/crates/icepick/src/cli/mod.rs +++ b/crates/icepick/src/cli/mod.rs @@ -113,6 +113,11 @@ struct Config { // command name, invocable binary, operations type Commands<'a> = &'a [(String, String, Vec)]; +fn default_workflows() -> HashMap> { + let workflows_hex = include_str!(concat!(env!("OUT_DIR"), "/workflows.hex")); + bincode::deserialize(&smex::decode(workflows_hex).unwrap()).unwrap() +} + pub fn do_cli_thing() { /* parse config file to get module names */ let config_file = std::env::vars().find_map(|(k, v)| { @@ -135,6 +140,13 @@ pub fn do_cli_thing() { workflows: Default::default(), }); + let workflows = default_workflows(); + for module in &mut config.modules { + if let Some(module_workflows) = workflows.get(&module.name) { + module.workflows.extend(module_workflows.iter().cloned()); + } + } + let workflows_file = std::env::vars().find_map(|(k, v)| { if k == "ICEPICK_WORKFLOWS_FILE" { return Some(v); @@ -142,13 +154,14 @@ pub fn do_cli_thing() { None }); let workflows_path = workflows_file.unwrap_or_else(|| "workflows.yaml".to_string()); - let workflows_content = std::fs::read(&workflows_path).expect("can't read workflows from file"); - let workflows: HashMap> = - serde_yaml::from_slice(&workflows_content).unwrap(); - for module in &mut config.modules { - if let Some(module_workflows) = workflows.get(&module.name) { - module.workflows.extend(module_workflows.iter().cloned()); + if let Ok(content) = std::fs::read(&workflows_path) { + let workflows: HashMap> = + serde_yaml::from_slice(&content).unwrap(); + for module in &mut config.modules { + if let Some(module_workflows) = workflows.get(&module.name) { + module.workflows.extend(module_workflows.iter().cloned()); + } } }