From 0d656de98b524a8a20b66e23c08841df4f7e119d Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Thu, 13 Nov 2025 00:09:44 -0500 Subject: [PATCH] feat(cli): update zig bindings with `version` command --- crates/cli/src/version.rs | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/crates/cli/src/version.rs b/crates/cli/src/version.rs index 9406b58c..757306c7 100644 --- a/crates/cli/src/version.rs +++ b/crates/cli/src/version.rs @@ -135,6 +135,7 @@ impl Version { push_err(self.update_makefile(is_multigrammar)); push_err(self.update_cmakelists_txt()); push_err(self.update_pyproject_toml()); + push_err(self.update_zig_zon()); if errors.is_empty() { Ok(()) @@ -352,4 +353,44 @@ impl Version { Ok(()) } + + fn update_zig_zon(&self) -> Result<(), UpdateError> { + let zig_zon_path = self.current_dir.join("build.zig.zon"); + if !zig_zon_path.exists() { + return Ok(()); + } + + self.update_file_with(&zig_zon_path, |content| { + let zig_version_prefix = ".version ="; + content + .lines() + .map(|line| { + if line + .trim_start_matches(|c: char| c.is_ascii_whitespace()) + .starts_with(zig_version_prefix) + { + let prefix_index = + line.find(zig_version_prefix).unwrap() + zig_version_prefix.len(); + let start_quote = + line[prefix_index..].find('"').unwrap() + prefix_index + 1; + let end_quote = + line[start_quote + 1..].find('"').unwrap() + start_quote + 1; + + format!( + "{}{}{}", + &line[..start_quote], + self.version.as_ref().unwrap(), + &line[end_quote..] + ) + } else { + line.to_string() + } + }) + .collect::>() + .join("\n") + + "\n" + })?; + + Ok(()) + } }