From e95cb76d6c3e1c3d9072fe01b4e744ac378561fc Mon Sep 17 00:00:00 2001 From: Shubham Patil Date: Mon, 12 Jan 2026 10:20:40 +0530 Subject: [PATCH] install.sh: platform agnostics usage to get number of processing units apparantly nproc is not Darwin native, so added a fallback for the nproc for darwin and posix platforms and even if this fails it falls back to 1. Fixes https://github.com/espressif/esp-matter/issues/1651 --- install.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 3860c74c6..2b0cd5136 100755 --- a/install.sh +++ b/install.sh @@ -9,7 +9,7 @@ print_help() { echo " --no-bootstrap Disable sourcing connectedhomeip's scripts/bootstrap.sh," echo " This can be helpful if there's already present connectedhomeip setup" echo " --build-python Build Python environment for running Python test scripts" - echo " --ninja-jobs Number of jobs to use for ninja (default: $(nproc))" + echo " --ninja-jobs Number of jobs to use for ninja (default: $(get_nproc))" echo " This is used to build the host tools." echo " This can be helpful in case of slow build machines/docker containers," echo " or to speed up the build process on faster machines." @@ -21,11 +21,21 @@ echo_log() { echo "" } +# Get the number of available processing units to optimize build performance +# It tries nproc -> getconf -> sysctl and defaults to 1 if all fail assuming +# a single processing unit is available. +get_nproc() { + nproc 2>/dev/null \ + || getconf _NPROCESSORS_ONLN 2>/dev/null \ + || sysctl -n hw.ncpu 2>/dev/null \ + || echo 1 +} + # Parse command-line arguments NO_HOST_TOOL=false NO_BOOTSTRAP=false BUILD_PYTHON=false -NINJA_JOBS=$(nproc) +NINJA_JOBS=$(get_nproc) while [[ "$#" -gt 0 ]]; do case $1 in @@ -39,7 +49,7 @@ while [[ "$#" -gt 0 ]]; do BUILD_PYTHON=true ;; --ninja-jobs) - NINJA_JOBS=${2:-$(nproc)} + NINJA_JOBS=${2:-$(get_nproc)} shift ;; --help)