From 15b34fcfc8cfe0b042b93244ee0276106d2a3f8b Mon Sep 17 00:00:00 2001
From: Russel Arbore <russel.jma@gmail.com>
Date: Mon, 3 Feb 2025 09:52:45 -0600
Subject: [PATCH] persist tmp dir if clang/nvcc fail

---
 juno_scheduler/src/pm.rs | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/juno_scheduler/src/pm.rs b/juno_scheduler/src/pm.rs
index 9c818707..20a3dba8 100644
--- a/juno_scheduler/src/pm.rs
+++ b/juno_scheduler/src/pm.rs
@@ -780,8 +780,15 @@ impl PassManager {
             .stdin(Stdio::piped())
             .stdout(Stdio::piped())
             .spawn()
-            .expect("Error running clang. Is it installed?");
-        assert!(clang_process.wait().unwrap().success());
+            .expect("PANIC: Error running clang. Is it installed?");
+        if clang_process
+            .wait()
+            .map(|status| !status.success())
+            .unwrap_or(false)
+        {
+            let path = tmp_dir.into_path();
+            panic!("PANIC: Clang failed to compile the LLVM IR module. Persisting temporary directory ({}).", path.display());
+        }
 
         let mut ar_args = vec!["crus", &output_archive, &llvm_object];
 
@@ -806,8 +813,15 @@ impl PassManager {
                 .arg(&cuda_object)
                 .arg(&cuda_path)
                 .spawn()
-                .expect("Error running nvcc. Is it installed?");
-            assert!(nvcc_process.wait().unwrap().success());
+                .expect("PANIC: Error running NVCC. Is it installed?");
+            if nvcc_process
+                .wait()
+                .map(|status| !status.success())
+                .unwrap_or(false)
+            {
+                let path = tmp_dir.into_path();
+                panic!("PANIC: NVCC failed to compile the CUDA module. Persisting temporary directory ({}).", path.display());
+            }
 
             ar_args.push(&cuda_object);
         }
@@ -816,7 +830,17 @@ impl PassManager {
             .args(&ar_args)
             .spawn()
             .expect("Error running ar. Is it installed?");
-        assert!(ar_process.wait().unwrap().success());
+        if ar_process
+            .wait()
+            .map(|status| !status.success())
+            .unwrap_or(false)
+        {
+            let path = tmp_dir.into_path();
+            panic!(
+                "PANIC: Ar failed to create a static library. Persisting temporary directory ({}).",
+                path.display()
+            );
+        }
 
         // Write the Rust runtime into a file.
         let output_rt = format!("{}/rt_{}.hrt", output_dir, module_name);
-- 
GitLab