Skip to content

Commit bbfd410

Browse files
authored
swift_build_support/cmake.py: parallelize default CMake build (#66212)
CMake's bootstrapping script can't infer a number of parallel build jobs from the number of CPU cores on its own, which means that it's not parallelized by default. Let's get the value of CPU cores when `build_jobs` argument is not explicitly set. `make -j` only has an effect on CMake's post-bootstrap build jobs, while a substantial amount of time was spent building code sequentially in CMake's bootstrap script without that `--parallelize` option, which is called on a line preceding the `make -j` invocation.
1 parent c464207 commit bbfd410

File tree

1 file changed

+6
-3
lines changed
  • utils/swift_build_support/swift_build_support

1 file changed

+6
-3
lines changed

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# ----------------------------------------------------------------------------
1616

1717

18+
import multiprocessing
1819
import os
1920
import platform
2021
import re
@@ -273,9 +274,11 @@ def build_cmake(self, source_root, build_root):
273274

274275
cwd = os.getcwd()
275276
os.chdir(cmake_build_dir)
276-
shell.call_without_sleeping([cmake_bootstrap, '--no-qt-gui', '--',
277-
'-DCMAKE_USE_OPENSSL=OFF'], echo=True)
278-
shell.call_without_sleeping(['make', '-j%s' % self.args.build_jobs],
277+
build_jobs = self.args.build_jobs or multiprocessing.cpu_count()
278+
shell.call_without_sleeping([cmake_bootstrap, '--no-qt-gui',
279+
'--parallel=%s' % build_jobs, '--',
280+
'-DCMAKE_USE_OPENSSL=OFF'], echo=True)
281+
shell.call_without_sleeping(['make', '-j%s' % build_jobs],
279282
echo=True)
280283
os.chdir(cwd)
281284
return os.path.join(cmake_build_dir, 'bin', 'cmake')

0 commit comments

Comments
 (0)