Skip to content

Commit

Permalink
Add zigup step (#1030)
Browse files Browse the repository at this point in the history
* feat: add zigup step

* feat(zigup): add various configuration options

* feat(zigup): add cleanup option

* feat(zigup): multiple version support and cleanup

* refactor(zigup): remove set_default and simplify execution

* fix(zigup): always pass path args to zigup for consistent behaviour

* refactor(zigup): use shellexpand to expand tildes
  • Loading branch information
Laura7089 authored Feb 8, 2025
1 parent 4624f11 commit da270ae
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
25 changes: 25 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
43 changes: 43 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pub enum Step {
Xcodes,
Yadm,
Yarn,
Zigup,
Zvm,
}

Expand Down Expand Up @@ -461,6 +462,15 @@ pub struct JuliaConfig {
startup_file: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
pub struct Zigup {
target_versions: Option<Vec<String>>,
install_dir: Option<String>,
path_link: Option<String>,
cleanup: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
#[serde(deny_unknown_fields)]
/// Configuration file
Expand Down Expand Up @@ -530,6 +540,9 @@ pub struct ConfigFile {

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
julia: Option<JuliaConfig>,

#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
zigup: Option<Zigup>,
}

fn config_directory() -> PathBuf {
Expand Down Expand Up @@ -1667,6 +1680,36 @@ impl Config {
.and_then(|julia| julia.startup_file)
.unwrap_or(true)
}

pub fn zigup_target_versions(&self) -> Vec<String> {
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)]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", || {
Expand Down
45 changes: 45 additions & 0 deletions src/steps/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit da270ae

Please sign in to comment.