14 """Patches the compile() to allow enable parallel compilation of C/C++.
16 build_ext has lots of C/C++ files and normally them one by one.
17 Enabling parallel build helps a lot.
20 import distutils.ccompiler
24 BUILD_EXT_COMPILER_JOBS =
int(
25 os.environ[
'GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS'])
27 import multiprocessing
28 BUILD_EXT_COMPILER_JOBS = multiprocessing.cpu_count()
30 BUILD_EXT_COMPILER_JOBS = 1
45 macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
46 str(output_dir), macros, include_dirs, sources, depends, extra_postargs)
47 cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
49 def _compile_single_file(obj):
54 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
57 import multiprocessing.pool
58 multiprocessing.pool.ThreadPool(BUILD_EXT_COMPILER_JOBS).
map(
59 _compile_single_file, objects)
64 """Monkeypatching is dumb, but the build speed gain is worth it."""
65 if BUILD_EXT_COMPILER_JOBS > 1:
66 distutils.ccompiler.CCompiler.compile = _parallel_compile