From 7a2dd61a7c5215f34d31d24e4104198d409ab81b Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Sat, 29 Aug 2026 04:22:28 -0400 Subject: [PATCH] fix(xtask): preserve format padding when updating Cargo.toml files --- crates/xtask/src/bump.rs | 5 ++++- crates/xtask/src/upgrade_wasmtime.rs | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/crates/xtask/src/bump.rs b/crates/xtask/src/bump.rs index 25257614f..5a19d7cff 100644 --- a/crates/xtask/src/bump.rs +++ b/crates/xtask/src/bump.rs @@ -285,7 +285,10 @@ fn update_zig(next_version: &Version) -> Result<()> { fn fetch_workspace_version() -> Result { std::fs::read_to_string("Cargo.toml")? .lines() - .find(|line| line.starts_with("version = ")) + .find(|line| { + line.split_once('=') + .is_some_and(|(key, _)| key.trim() == "version") + }) .and_then(|line| { line.split_terminator('"') .next_back() diff --git a/crates/xtask/src/upgrade_wasmtime.rs b/crates/xtask/src/upgrade_wasmtime.rs index da3eb1353..43d84b467 100644 --- a/crates/xtask/src/upgrade_wasmtime.rs +++ b/crates/xtask/src/upgrade_wasmtime.rs @@ -9,15 +9,28 @@ const WASMTIME_RELEASE_URL: &str = "https://github.com/bytecodealliance/wasmtime fn update_cargo(version: &Version) -> Result<()> { let file = std::fs::read_to_string("lib/Cargo.toml")?; - let mut old_lines = file.lines(); - let mut new_lines = Vec::with_capacity(old_lines.size_hint().0); + let mut in_wasmtime_dependency = false; + let mut updated = false; + let mut new_lines = Vec::with_capacity(file.lines().size_hint().0); - while let Some(line) = old_lines.next() { - new_lines.push(line.to_string()); - if line == "[dependencies.wasmtime-c-api]" { - let _ = old_lines.next(); - new_lines.push(format!("version = \"{version}\"")); + for line in file.lines() { + if line.starts_with('[') { + in_wasmtime_dependency = line == "[dependencies.wasmtime-c-api]"; } + + if in_wasmtime_dependency + && let Some((key, _)) = line.split_once('=') + && key.trim() == "version" + { + new_lines.push(format!("{key}= \"{version}\"")); + updated = true; + } else { + new_lines.push(line.to_string()); + } + } + + if !updated { + anyhow::bail!("Failed to find wasmtime-c-api version in lib/Cargo.toml"); } std::fs::write("lib/Cargo.toml", new_lines.join("\n") + "\n")?;