diff --git a/crates/arroyo-compiler-service/src/lib.rs b/crates/arroyo-compiler-service/src/lib.rs index 7e23fa815..9774ae680 100644 --- a/crates/arroyo-compiler-service/src/lib.rs +++ b/crates/arroyo-compiler-service/src/lib.rs @@ -168,38 +168,19 @@ impl CompileService { } } - async fn check_cc(&self) -> anyhow::Result<()> { - if binary_present("cc").await { - return Ok(()); - } - - if !bool_config(INSTALL_CLANG_ENV, false) { - let error = "UDF compilation requires clang or gcc to be available. Ensure you have a \ - working C compilation environment."; - error!("{}", error); - bail!("{}", error); - } - - info!( - "cc is not available, but required for UDF compilation. Attempting to install clang." - ); + async fn run_command(action: &str, command: &mut Command) -> anyhow::Result<()> { let output = timeout( Duration::from_secs(2 * 60), - Command::new("apt-get") - .arg("-y") - .arg("install") - .arg("clang") + command .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) .output(), ) .await - .map_err(|e| anyhow!("Timed out while installing clang for UDF compilation after {e}"))? - .map_err(|e| anyhow!("Failed to install clang via apt-get: {e}"))?; + .map_err(|e| anyhow!("Timed out while {action} for UDF compilation after {e}"))? + .map_err(|e| anyhow!("Failed while {action} via apt-get: {e}"))?; - if output.status.success() { - info!("clang successfully installed..."); - } else { + if !output.status.success() { error!( "Failed to install clang, will not be able to compile UDFs\ \n------------------------------\ @@ -215,6 +196,36 @@ impl CompileService { Ok(()) } + + async fn check_cc(&self) -> anyhow::Result<()> { + if binary_present("cc").await { + return Ok(()); + } + + if !bool_config(INSTALL_CLANG_ENV, false) { + let error = "UDF compilation requires clang or gcc to be available. Ensure you have a \ + working C compilation environment."; + error!("{}", error); + bail!("{}", error); + } + + info!( + "cc is not available, but required for UDF compilation. Attempting to install clang." + ); + + Self::run_command("updating apt", Command::new("apt-get").arg("update")).await?; + + Self::run_command( + "installing clang", + Command::new("apt-get") + .arg("-y") + .arg("install") + .arg("clang"), + ) + .await?; + + Ok(()) + } } fn dylib_path(name: &str, definition: &str) -> String {