armbian_build/lib/functions/configuration/compilation-config.sh
Andrei Aldea 370bedb42d
Some checks are pending
Forked Helper / 📢 Run repository dispatch on fork (push) Waiting to run
Announce PR merge to Discord / announcepush (push) Waiting to run
Scorecards Security Scan / Scorecards analysis (push) Waiting to run
Add option for number of threads used by build system (#8346)
* Add option for number of threads used by build system

Attempt to fix https://github.com/armbian/build/issues/6907

* Add CPUTHREADS to replace USEALLTHREADS

Defaults to 150% as was always the case, otherwise allow user to override number of threads.
2025-07-13 09:33:48 +02:00

48 lines
1.8 KiB
Bash

#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
function prepare_compilation_vars() {
# moved from config: rpardini: ccache belongs in compilation, not config. I think.
if [[ $USE_CCACHE == yes || ${PRIVATE_CCACHE} == yes ]]; then
display_alert "using CCACHE" "USE_CCACHE or PRIVATE_CCACHE is set to yes" "warn"
CCACHE=ccache
export PATH="/usr/lib/ccache:$PATH" # this actually needs export'ing
# private ccache directory to avoid permission issues when using build script with "sudo"
# see https://ccache.samba.org/manual.html#_sharing_a_cache for alternative solution
[[ $PRIVATE_CCACHE == yes ]] && export CCACHE_DIR=$SRC/cache/ccache # actual export
else
CCACHE=""
fi
# moved from config: this does not belong in configuration. it's a compilation thing.
# optimize build time with 100% CPU usage
CPUS=$(grep -c 'processor' /proc/cpuinfo)
# Default to 150% of CPUs to maximize compilation speed
CTHREADS="-j$((CPUS + CPUS / 2))"
# If CPUTHREADS is defined and a valid positive integer allow user to override CTHREADS
# This is useful for limiting Armbian build to a specific number of threads, e.g. for build servers
if [[ "$CPUTHREADS" =~ ^[1-9][0-9]*$ ]]; then
CTHREADS="-j$CPUTHREADS"
echo "Using user-defined thread count: $CTHREADS"
fi
call_extension_method "post_determine_cthreads" "config_post_determine_cthreads" <<- 'POST_DETERMINE_CTHREADS'
*give config a chance modify CTHREADS programatically. A build server may work better with hyperthreads-1 for example.*
Called early, before any compilation work starts.
POST_DETERMINE_CTHREADS
# readonly, global
declare -g -r CTHREADS="${CTHREADS}"
return 0
}