don't fail if rustfmt not found
authorJacob Lifshay <programmerjake@gmail.com>
Fri, 21 May 2021 02:15:15 +0000 (19:15 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Fri, 21 May 2021 02:15:15 +0000 (19:15 -0700)
Cargo.toml
build.rs

index d709c7a2fe72bbb09ea6af02e1533a5e6625a114..56ad7be042db2b4c55b8674c5331b15fd177ce2d 100644 (file)
@@ -12,7 +12,6 @@ core_simd = { version = "0.1.0", git = "https://github.com/rust-lang/stdsimd", o
 
 [build-dependencies]
 vector-math-build-helpers = { version = "=0.1.0", path = "vector-math-build-helpers" }
 
 [build-dependencies]
 vector-math-build-helpers = { version = "=0.1.0", path = "vector-math-build-helpers" }
-which = "3"
 
 [features]
 default = ["fma"]
 
 [features]
 default = ["fma"]
index 33d01bc2f4e737d07efebf2524507334cc86c7fc..d0bd64d4187ad5040c494905468e6ad563897719 100644 (file)
--- a/build.rs
+++ b/build.rs
@@ -8,23 +8,39 @@ use std::{
 use vector_math_build_helpers::make_context_types;
 
 fn format_source(source: String) -> String {
 use vector_math_build_helpers::make_context_types;
 
 fn format_source(source: String) -> String {
-    let rustfmt_path = which::which("rustfmt").unwrap();
-    let mut command = Command::new(rustfmt_path)
+    match try_format_source(&source) {
+        Ok(v) => v,
+        Err(e) => {
+            eprintln!("rustfmt failed: {}", e);
+            source
+        }
+    }
+}
+
+fn try_format_source(source: &str) -> io::Result<String> {
+    let mut command = Command::new("rustfmt")
         .stdin(Stdio::piped())
         .stdout(Stdio::piped())
         .stdin(Stdio::piped())
         .stdout(Stdio::piped())
-        .spawn()
-        .unwrap();
+        .spawn()?;
     let stdin = command.stdin.take().unwrap();
     let reader_thread = thread::spawn(move || -> io::Result<(String, Child)> {
         let mut output = String::new();
         command.stdout.take().unwrap().read_to_string(&mut output)?;
         Ok((output, command))
     });
     let stdin = command.stdin.take().unwrap();
     let reader_thread = thread::spawn(move || -> io::Result<(String, Child)> {
         let mut output = String::new();
         command.stdout.take().unwrap().read_to_string(&mut output)?;
         Ok((output, command))
     });
-    { stdin }.write_all(source.as_bytes()).unwrap();
-    let (output, mut command) = reader_thread.join().unwrap().unwrap();
-    let exit_status = command.wait().unwrap();
-    assert!(exit_status.success());
-    output
+    let write_result = { stdin }.write_all(source.as_bytes());
+    let join_result = reader_thread.join().unwrap();
+    write_result?;
+    let (output, mut command) = join_result?;
+    let exit_status = command.wait()?;
+    if exit_status.success() {
+        Ok(output)
+    } else {
+        Err(io::Error::new(
+            io::ErrorKind::Other,
+            format!("exited with status {}", exit_status),
+        ))
+    }
 }
 
 fn main() {
 }
 
 fn main() {