feat(build): support env var IDF_PY_BUILD_JOBS for ninja jobs

This commit is contained in:
Fu Hanxi
2026-04-15 13:24:16 +02:00
parent f15406fe33
commit 2aee18d827
4 changed files with 34 additions and 1 deletions
+4
View File
@@ -19,6 +19,10 @@ variables:
# Common parameters for the 'make' during CI tests
MAKEFLAGS: "-j5 --no-keep-going"
# By default, CI build jobs request and limit 4 CPU cores and 4 GB of memory
# https://github.com/ninja-build/ninja/blob/def9560a0b6d755936e615ce443a0aec45c39bdb/src/ninja.cc#L262
# cpu_cores + 2
IDF_PY_BUILD_JOBS: "6"
# GitLab-CI environment
# Thanks to pack-objects cache, clone strategy should behave faster than fetch
+8
View File
@@ -77,6 +77,14 @@ In the above list, the ``cmake`` command configures the project and generates bu
It's not necessary to run ``cmake`` more than once. After the first build, you only need to run ``ninja`` each time. ``ninja`` will automatically re-invoke ``cmake`` if the project needs reconfiguration.
When using ``idf.py`` with the Ninja generator, you can cap the number of parallel build jobs by setting the ``IDF_PY_BUILD_JOBS`` environment variable. For example:
.. code-block:: bash
IDF_PY_BUILD_JOBS=6 idf.py build
If you invoke CMake, ``ninja``, or ``make`` directly instead of ``idf.py``, use their native options or environment variables to control parallelism.
If using CMake with ``ninja`` or ``make``, there are also targets for more of the ``idf.py`` sub-commands. For example, running ``make menuconfig`` or ``ninja menuconfig`` in the build directory will work the same as ``idf.py menuconfig``.
.. note::
+8
View File
@@ -77,6 +77,14 @@ idf.py
没有必要多次运行 ``cmake``。第一次构建后,往后每次只需运行 ``ninja`` 即可。如果项目需要重新配置,``ninja`` 会自动重新调用 ``cmake``
使用 Ninja 生成器配合 ``idf.py`` 时,可以通过设置环境变量 ``IDF_PY_BUILD_JOBS`` 来限制并行构建任务数。例如:
.. code-block:: bash
IDF_PY_BUILD_JOBS=6 idf.py build
如果不是通过 ``idf.py``,而是直接调用 CMake、``ninja````make``,则请使用它们各自原生的并行控制选项或环境变量。
若在 CMake 中使用 ``ninja````make``,则多数 ``idf.py`` 子命令也会有其对应的目标,例如在构建目录下运行 ``make menuconfig````ninja menuconfig`` 与运行 ``idf.py menuconfig`` 是相同的。
.. note::
+14 -1
View File
@@ -592,7 +592,20 @@ def run_target(
if env is None:
env = {}
generator_cmd = GENERATORS[args.generator]['command']
generator_cmd = list(GENERATORS[args.generator]['command'])
if args.generator == 'Ninja':
parallel_level = os.environ.get('IDF_PY_BUILD_JOBS')
if parallel_level:
try:
jobs = int(parallel_level)
except ValueError as e:
raise FatalError('Environment variable IDF_PY_BUILD_JOBS must be a positive integer') from e
if jobs <= 0:
raise FatalError('Environment variable IDF_PY_BUILD_JOBS must be a positive integer')
generator_cmd += ['-j', str(jobs)]
if args.verbose:
generator_cmd += [GENERATORS[args.generator]['verbose_flag']]