diff --git a/config.example.toml b/config.example.toml index e2bb6e3c..af4d60a3 100644 --- a/config.example.toml +++ b/config.example.toml @@ -290,3 +290,28 @@ # in the startup file, which might cause the update run to fail. # (default: true) # startup_file = true + +[zigup] +# Version strings passed to zigup. +# These may be pinned versions such as "0.13.0" or branches such as "master". +# Each one will be updated in its own zigup invocation. +# (default: ["master"]) +# target_versions = ["master", "0.13.0"] + +# Specifies the directory that the zig files will be installed to. +# If defined, passed with the --install-dir command line flag. +# If not defined, zigup will use its default behaviour. +# (default: not defined) +# install_dir = "~/.zig" + +# Specifies the path of the symlink which will be set to point at the default compiler version. +# If defined, passed with the --path-link command line flag. +# If not defined, zigup will use its default behaviour. +# This is not meaningful if set_default is not enabled. +# (default: not defined) +# path_link = "~/.bin/zig" + +# If enabled, run `zigup clean` after updating all versions. +# If enabled, each updated version above will be marked with `zigup keep`. +# (default: false) +# cleanup = false diff --git a/src/config.rs b/src/config.rs index a41936ee..c722f881 100644 --- a/src/config.rs +++ b/src/config.rs @@ -171,6 +171,7 @@ pub enum Step { Xcodes, Yadm, Yarn, + Zigup, Zvm, } @@ -461,6 +462,15 @@ pub struct JuliaConfig { startup_file: Option, } +#[derive(Deserialize, Default, Debug, Merge)] +#[serde(deny_unknown_fields)] +pub struct Zigup { + target_versions: Option>, + install_dir: Option, + path_link: Option, + cleanup: Option, +} + #[derive(Deserialize, Default, Debug, Merge)] #[serde(deny_unknown_fields)] /// Configuration file @@ -530,6 +540,9 @@ pub struct ConfigFile { #[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)] julia: Option, + + #[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)] + zigup: Option, } fn config_directory() -> PathBuf { @@ -1667,6 +1680,36 @@ impl Config { .and_then(|julia| julia.startup_file) .unwrap_or(true) } + + pub fn zigup_target_versions(&self) -> Vec { + self.config_file + .zigup + .as_ref() + .and_then(|zigup| zigup.target_versions.clone()) + .unwrap_or(vec!["master".to_owned()]) + } + + pub fn zigup_install_dir(&self) -> Option<&str> { + self.config_file + .zigup + .as_ref() + .and_then(|zigup| zigup.install_dir.as_deref()) + } + + pub fn zigup_path_link(&self) -> Option<&str> { + self.config_file + .zigup + .as_ref() + .and_then(|zigup| zigup.path_link.as_deref()) + } + + pub fn zigup_cleanup(&self) -> bool { + self.config_file + .zigup + .as_ref() + .and_then(|zigup| zigup.cleanup) + .unwrap_or(false) + } } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index 70691ba7..71c449e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -441,6 +441,7 @@ fn run() -> Result<()> { runner.execute(Step::Zvm, "ZVM", || generic::run_zvm(&ctx))?; runner.execute(Step::Aqua, "aqua", || generic::run_aqua(&ctx))?; runner.execute(Step::Bun, "bun", || generic::run_bun(&ctx))?; + runner.execute(Step::Zigup, "zigup", || generic::run_zigup(&ctx))?; if should_run_powershell { runner.execute(Step::Powershell, "Powershell Modules Update", || { diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 643a3d78..f3a2ac6d 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1221,3 +1221,48 @@ pub fn run_bun(ctx: &ExecutionContext) -> Result<()> { ctx.run_type().execute(bun).arg("upgrade").status_checked() } + +pub fn run_zigup(ctx: &ExecutionContext) -> Result<()> { + let zigup = require("zigup")?; + let config = ctx.config(); + + print_separator("zigup"); + + let mut path_args = Vec::new(); + if let Some(path) = config.zigup_path_link() { + path_args.push("--path-link".to_owned()); + path_args.push(shellexpand::tilde(path).into_owned()); + } + if let Some(path) = config.zigup_install_dir() { + path_args.push("--install-dir".to_owned()); + path_args.push(shellexpand::tilde(path).into_owned()); + } + + for zig_version in config.zigup_target_versions() { + ctx.run_type() + .execute(&zigup) + .args(&path_args) + .arg("fetch") + .arg(&zig_version) + .status_checked()?; + + if config.zigup_cleanup() { + ctx.run_type() + .execute(&zigup) + .args(&path_args) + .arg("keep") + .arg(&zig_version) + .status_checked()?; + } + } + + if config.zigup_cleanup() { + ctx.run_type() + .execute(zigup) + .args(&path_args) + .arg("clean") + .status_checked()?; + } + + Ok(()) +}