From 5139ed7ba339664527fce4a5b21d95e3cc51be71 Mon Sep 17 00:00:00 2001 From: Sapphire Date: Thu, 29 May 2025 01:17:20 -0500 Subject: [PATCH] fix(builders/basalt): limit to at most 6 build processes The Basalt build is quite memory hungry, causing people's systems to lock up and trigger the OOM killer during build. --- src/builders/build_basalt.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/builders/build_basalt.rs b/src/builders/build_basalt.rs index 0d8130f..b2a55bd 100644 --- a/src/builders/build_basalt.rs +++ b/src/builders/build_basalt.rs @@ -5,7 +5,10 @@ use crate::{ ui::job_worker::job::WorkerJob, util::file_utils::rm_rf, }; -use std::collections::{HashMap, VecDeque}; +use std::{ + collections::{HashMap, VecDeque}, + num::NonZero, +}; pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque { let mut jobs = VecDeque::::new(); @@ -40,10 +43,23 @@ pub fn get_build_basalt_jobs(profile: &Profile, clean_build: bool) -> VecDeque = HashMap::new(); for (k, v) in [ - ("CMAKE_BUILD_TYPE", "RelWithDebInfo"), - ("BUILD_TESTS", "off"), + // The basalt build uses a lot of RAM, so we have to limit the number of + // build processes to not starve the system of memory + // Limit to 6 build processes at most + ( + "CMAKE_BUILD_PARALLEL_LEVEL", + std::cmp::min( + 6, + std::thread::available_parallelism() + .map(NonZero::get) + .unwrap_or(2), + ) + .to_string(), + ), + ("CMAKE_BUILD_TYPE", "RelWithDebInfo".into()), + ("BUILD_TESTS", "off".into()), ] { - cmake_env.insert(k.to_string(), v.to_string()); + cmake_env.insert(k.to_string(), v); } cmake_env }),