mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 11:03:11 +00:00
feat(build): support env var IDF_PY_BUILD_JOBS for ninja jobs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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::
|
||||
|
||||
@@ -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::
|
||||
|
||||
@@ -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']]
|
||||
|
||||
Reference in New Issue
Block a user