feat(cli): update zig bindings with version command

This commit is contained in:
Will Lillis 2025-11-13 00:09:44 -05:00
parent b095968dff
commit 0d656de98b

View file

@ -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::<Vec<_>>()
.join("\n")
+ "\n"
})?;
Ok(())
}
}