diff --git a/build/build/src/engine/context.rs b/build/build/src/engine/context.rs index 4eeea5b4924..5bc30e42327 100644 --- a/build/build/src/engine/context.rs +++ b/build/build/src/engine/context.rs @@ -322,10 +322,14 @@ impl RunContext { ]); } - tasks.extend(self.config.execute_benchmarks.iter().flat_map(|b| b.sbt_task())); - if !tasks.is_empty() { - let build_stuff = Sbt::concurrent_tasks(tasks); - sbt.call_arg(build_stuff).await?; + // We want benchmarks to run only after the other build tasks are done, as they are + // really CPU-heavy. + let build_command = (!tasks.is_empty()).then_some(Sbt::concurrent_tasks(tasks)); + let benchmark_tasks = self.config.execute_benchmarks.iter().flat_map(|b| b.sbt_task()); + let command_sequence = build_command.as_deref().into_iter().chain(benchmark_tasks); + let final_command = Sbt::sequential_tasks(command_sequence); + if !final_command.is_empty() { + sbt.call_arg(final_command).await?; } else { debug!("No SBT tasks to run."); } diff --git a/build/ci_utils/src/programs/sbt.rs b/build/ci_utils/src/programs/sbt.rs index c2abb236e07..7e7d5537f93 100644 --- a/build/ci_utils/src/programs/sbt.rs +++ b/build/ci_utils/src/programs/sbt.rs @@ -41,6 +41,11 @@ impl Sbt { } ret } + + /// Format a string with a command that will execute all the given tasks sequentially. + pub fn sequential_tasks<'a>(tasks: impl IntoIterator) -> String { + tasks.into_iter().collect::>().join("; ") + } } #[derive(Clone, Debug)]