Skip to content

Commit 18f20ad

Browse files
authored
Pass in -j N to cmake to speed up desktop testapp build. (#933)
* Pass in -j to cmake --build when building desktop testapps. This should speed up the desktop testapp build. * Change the default value for FLAGS.jobs to the # of cpu cores (max 4)
1 parent 69c79a1 commit 18f20ad

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/gha/build_testapps.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@
177177
"arch", "x64",
178178
"(Desktop only) Which architecture to build: x64 (all) or arm64 (Mac only).")
179179

180+
# Get the number of CPUs for the default value of FLAGS.jobs
181+
CPU_COUNT = os.cpu_count();
182+
# If CPU count couldn't be determined, default to 2.
183+
DEFAULT_CPU_COUNT = 2
184+
if CPU_COUNT is None: CPU_COUNT = DEFAULT_CPU_COUNT
185+
# Cap at 4 CPUs.
186+
MAX_CPU_COUNT = 4
187+
if CPU_COUNT > MAX_CPU_COUNT: CPU_COUNT = MAX_CPU_COUNT
188+
189+
flags.DEFINE_integer(
190+
"jobs", CPU_COUNT,
191+
"(Desktop only) If > 0, pass in -j <number> to make CMake parallelize the"
192+
" build. Defaults to the system's CPU count (max %s)." % MAX_CPU_COUNT)
193+
180194
flags.DEFINE_multi_string(
181195
"cmake_flag", None,
182196
"Pass an additional flag to the CMake configure step."
@@ -458,7 +472,8 @@ def _build_desktop(sdk_dir, cmake_flags):
458472
cmake_configure_cmd += ["-DCMAKE_OSX_ARCHITECTURES=%s" %
459473
("arm64" if FLAGS.arch == "arm64" else "x86_64")]
460474
_run(cmake_configure_cmd + cmake_flags)
461-
_run(["cmake", "--build", ".", "--config", "Debug"])
475+
_run(["cmake", "--build", ".", "--config", "Debug"] +
476+
["-j", str(FLAGS.jobs)] if FLAGS.jobs > 0 else [])
462477

463478

464479
def _get_desktop_compiler_flags(compiler, compiler_table):

0 commit comments

Comments
 (0)