Skip to content

Commit

Permalink
Run apt-get update before trying to install clang (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwylde committed May 8, 2024
1 parent 8fbc498 commit 8e5e26c
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions crates/arroyo-compiler-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,38 +164,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------------------------------\
Expand All @@ -211,6 +192,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 {
Expand Down

0 comments on commit 8e5e26c

Please sign in to comment.