From ce360ce9eb176db689913bff25cd8ddbb5b3d612 Mon Sep 17 00:00:00 2001 From: Mack Date: Fri, 12 Jul 2024 15:25:33 +0800 Subject: [PATCH] NEW: BuildLinux.sh add parallel count limit JIRA:no Detecting the free memory(GB)/2.5 set to the number of parallels Change-Id: I171807071af9819e2a3aad0e27355d95975dbaa0 (cherry picked from commit 898ccf372931c09ae653cbb004a66223d5662817) --- .github/workflows/build_bambu.yml | 2 +- .github/workflows/build_deps.yml | 2 +- BuildLinux.sh | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_bambu.yml b/.github/workflows/build_bambu.yml index ba7eb0a0a..b6a63912c 100644 --- a/.github/workflows/build_bambu.yml +++ b/.github/workflows/build_bambu.yml @@ -238,7 +238,7 @@ jobs: if: inputs.os == 'ubuntu-20.04' || inputs.os == 'ubuntu-24.04' shell: bash run: | - ./BuildLinux.sh -isr + ./BuildLinux.sh -isfr mv -n ./build/BambuStudio_ubu64.AppImage ./build/Bambu_Studio_${{inputs.os}}_${{ env.ver }}.AppImage # - name: Build orca_custom_preset_tests diff --git a/.github/workflows/build_deps.yml b/.github/workflows/build_deps.yml index 7f2e00381..0ed634e21 100644 --- a/.github/workflows/build_deps.yml +++ b/.github/workflows/build_deps.yml @@ -100,7 +100,7 @@ jobs: run: | sudo ./BuildLinux.sh -ur sudo chown $USER -R ./ - ./BuildLinux.sh -dr + ./BuildLinux.sh -dfr cd deps/build tar -czvf BambuStudio_dep_${{ inputs.os }}_$(date +"%Y%m%d").tar.gz destdir diff --git a/BuildLinux.sh b/BuildLinux.sh index d3c79e106..11ea412d6 100755 --- a/BuildLinux.sh +++ b/BuildLinux.sh @@ -27,6 +27,7 @@ function check_available_memory_and_disk() { function usage() { echo "Usage: ./BuildLinux.sh [-1][-b][-c][-d][-i][-r][-s][-u]" echo " -1: limit builds to 1 core (where possible)" + echo " -f: disable safe parallel number limit(By default, the maximum number of parallels is set to free memory/2.5)" echo " -b: build in debug mode" echo " -c: force a clean build" echo " -d: build deps (optional)" @@ -40,11 +41,14 @@ function usage() { } unset name -while getopts ":1bcdghirsu" opt; do +while getopts ":1fbcdghirsu" opt; do case ${opt} in 1 ) export CMAKE_BUILD_PARALLEL_LEVEL=1 ;; + f ) + DISABLE_PARALLEL_LIMIT=1 + ;; b ) BUILD_DEBUG="1" ;; @@ -112,6 +116,19 @@ then check_available_memory_and_disk fi +if ! [[ -n "${DISABLE_PARALLEL_LIMIT}" ]] +then + FREE_MEM_GB=$(free -g -t | grep 'Mem' | rev | cut -d" " -f1 | rev) + MAX_THREADS=$(echo "scale=0; $FREE_MEM_GB / 2.5" | bc) + if [ "$MAX_THREADS" -lt 1 ]; then + export CMAKE_BUILD_PARALLEL_LEVEL=1 + else + export CMAKE_BUILD_PARALLEL_LEVEL=${MAX_THREADS} + fi + echo "System free memory: ${FREE_MEM_GB} GB" + echo "Setting CMAKE_BUILD_PARALLEL_LEVEL: ${CMAKE_BUILD_PARALLEL_LEVEL}" +fi + if [[ -n "${BUILD_DEPS}" ]] then echo "Configuring dependencies..."