Skip to content

Commit

Permalink
ci: skip formatting when rustfmt not present
Browse files Browse the repository at this point in the history
Though it is likely that `rustfmt` is present in a Rust environment,
some CI tasks do not have this tool installed. To handle this case
(plus the chance that other Wasmtime builds are similar), this change
skips formatting with a `stderr` warning when `rustfmt` fails.
  • Loading branch information
abrown committed Jan 24, 2025
1 parent 9bc10ec commit d209114
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cranelift/assembler-x64/meta/src/lib.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ pub mod dsl;
mod generate;
pub mod instructions;

use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;

@@ -47,16 +46,16 @@ fn generate<P: AsRef<Path>>(
generator(fmt, &instructions::list());
fmt.write(file).unwrap();
if format_rust {
rustfmt(file).unwrap();
rustfmt(file);
}
file.to_path_buf()
}

/// Use the installed `rustfmt` binary to format the generated code.
fn rustfmt(file: &Path) -> io::Result<()> {
let status = Command::new("rustfmt").arg(file).status()?;
/// Use the installed `rustfmt` binary to format the generated code; if it
/// fails, skip formatting with a warning.
fn rustfmt(file: &Path) {
let status = Command::new("rustfmt").arg(file).status().unwrap();
if !status.success() {
return Err(io::Error::new(io::ErrorKind::Other, format!("`rustfmt` exited with status {status}")));
eprintln!("`rustfmt` exited with a non-zero status; skipping formatting of generated files");
}
Ok(())
}

0 comments on commit d209114

Please sign in to comment.