Skip to content

Commit

Permalink
NEW: BuildLinux.sh add parallel count limit
Browse files Browse the repository at this point in the history
JIRA:no

Detecting the free memory(GB)/2.5 set to the number of parallels

Change-Id: I171807071af9819e2a3aad0e27355d95975dbaa0
(cherry picked from commit 898ccf372931c09ae653cbb004a66223d5662817)
  • Loading branch information
MackBambu authored and lanewei120 committed Jul 17, 2024
1 parent fe35939 commit ce360ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_bambu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion BuildLinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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"
;;
Expand Down Expand Up @@ -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..."
Expand Down

0 comments on commit ce360ce

Please sign in to comment.