From 935eaf8de3ec02bba932bf76157c878f4a960a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:12:56 +0100 Subject: [PATCH] Limit build parallelism for github runners --- .github/workflows/code_sanitizers.yml | 2 ++ ci/build.sh | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code_sanitizers.yml b/.github/workflows/code_sanitizers.yml index c82c31b280..54d2ceb9f7 100644 --- a/.github/workflows/code_sanitizers.yml +++ b/.github/workflows/code_sanitizers.yml @@ -41,6 +41,8 @@ jobs: - name: Build Tests id: build run: ci/build-tests.sh + env: + MAX_BUILD_PARALLELISM: 2 # Limit parallelism to avoid OOM during compilation - name: Core Tests if: steps.build.outcome == 'success' && (success() || failure()) diff --git a/ci/build.sh b/ci/build.sh index 4aabc4d0fb..3dfdbdf082 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -70,21 +70,29 @@ ${CMAKE_BACKTRACE:-} \ ${SRC} number_of_processors() { + local max_procs=$(nproc) case "$(uname -s)" in - Linux*) - nproc + Linux*) + max_procs=$(nproc) ;; - Darwin*) - sysctl -n hw.ncpu + Darwin*) + max_procs=$(sysctl -n hw.ncpu) ;; CYGWIN*|MINGW32*|MSYS*|MINGW*) - echo "${NUMBER_OF_PROCESSORS}" + max_procs="${NUMBER_OF_PROCESSORS}" ;; *) echo "Unknown OS" exit 1 ;; esac + + # If MAX_BUILD_PARALLELISM is set and less than the number of processors, use it instead + if [[ ! -z ${MAX_BUILD_PARALLELISM:-} ]] && [[ "$MAX_BUILD_PARALLELISM" -lt "$max_procs" ]]; then + echo "$MAX_BUILD_PARALLELISM" + else + echo "$max_procs" + fi } parallel_build_flag() {