From a57b550dbd287ab7b99f8be31e95c9f2c44d1481 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Fri, 6 May 2022 12:56:59 -0700 Subject: [PATCH 1/2] Pass in -j to cmake --build when building desktop testapps. This should speed up the desktop testapp build. --- scripts/gha/build_testapps.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/gha/build_testapps.py b/scripts/gha/build_testapps.py index 6a3d71785d..043e55f487 100644 --- a/scripts/gha/build_testapps.py +++ b/scripts/gha/build_testapps.py @@ -177,6 +177,10 @@ "arch", "x64", "(Desktop only) Which architecture to build: x64 (all) or arm64 (Mac only).") +flags.DEFINE_integer( + "jobs", 3, + "(Desktop only) If > 0, pass in -j to CMake to parallelize build") + flags.DEFINE_multi_string( "cmake_flag", None, "Pass an additional flag to the CMake configure step." @@ -458,7 +462,8 @@ def _build_desktop(sdk_dir, cmake_flags): cmake_configure_cmd += ["-DCMAKE_OSX_ARCHITECTURES=%s" % ("arm64" if FLAGS.arch == "arm64" else "x86_64")] _run(cmake_configure_cmd + cmake_flags) - _run(["cmake", "--build", ".", "--config", "Debug"]) + _run(["cmake", "--build", ".", "--config", "Debug"] + + ["-j", "%s" % FLAGS.jobs] if FLAGS.jobs > 0 else []) def _get_desktop_compiler_flags(compiler, compiler_table): From 6f3f5823f8ab64b4afa2097fa7fa82e0ae48a30e Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Fri, 6 May 2022 13:12:57 -0700 Subject: [PATCH 2/2] Change the default value for FLAGS.jobs to the # of cpu cores (max 4) --- scripts/gha/build_testapps.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/gha/build_testapps.py b/scripts/gha/build_testapps.py index 043e55f487..e20326badb 100644 --- a/scripts/gha/build_testapps.py +++ b/scripts/gha/build_testapps.py @@ -177,9 +177,19 @@ "arch", "x64", "(Desktop only) Which architecture to build: x64 (all) or arm64 (Mac only).") +# Get the number of CPUs for the default value of FLAGS.jobs +CPU_COUNT = os.cpu_count(); +# If CPU count couldn't be determined, default to 2. +DEFAULT_CPU_COUNT = 2 +if CPU_COUNT is None: CPU_COUNT = DEFAULT_CPU_COUNT +# Cap at 4 CPUs. +MAX_CPU_COUNT = 4 +if CPU_COUNT > MAX_CPU_COUNT: CPU_COUNT = MAX_CPU_COUNT + flags.DEFINE_integer( - "jobs", 3, - "(Desktop only) If > 0, pass in -j to CMake to parallelize build") + "jobs", CPU_COUNT, + "(Desktop only) If > 0, pass in -j to make CMake parallelize the" + " build. Defaults to the system's CPU count (max %s)." % MAX_CPU_COUNT) flags.DEFINE_multi_string( "cmake_flag", None, @@ -463,7 +473,7 @@ def _build_desktop(sdk_dir, cmake_flags): ("arm64" if FLAGS.arch == "arm64" else "x86_64")] _run(cmake_configure_cmd + cmake_flags) _run(["cmake", "--build", ".", "--config", "Debug"] + - ["-j", "%s" % FLAGS.jobs] if FLAGS.jobs > 0 else []) + ["-j", str(FLAGS.jobs)] if FLAGS.jobs > 0 else []) def _get_desktop_compiler_flags(compiler, compiler_table):