已合并
[feat]suppport ninja #34208
一只食醉狗创建于 4月23日
[feat]suppport ninja #34208
已合并
一只食醉狗创建于 4月23日
2 个文件变更+15-4
Msetup.py+14-3
@@ -315,6 +315,7 @@ class Clean(distutils.command.clean.clean):
315 if os.path.exists(file_path):315 if os.path.exists(file_path):
316 os.remove(file_path)316 os.remove(file_path)
317 317 
318+USE_NINJA = os.environ["CMAKE_GENERATOR"].lower() == "ninja" if "CMAKE_GENERATOR" in os.environ else shutil.which("ninja")
318 319 
319class CPPLibBuild(build_clib, object):320class CPPLibBuild(build_clib, object):
320 def run(self):321 def run(self):
@@ -367,8 +368,15 @@ class CPPLibBuild(build_clib, object):
367 if os.getenv('_ABI_VERSION') is not None:368 if os.getenv('_ABI_VERSION') is not None:
368 cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION'))369 cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION'))
369 370 
370- max_jobs = os.getenv("MAX_JOBS", str(multiprocessing.cpu_count()))371+ if USE_NINJA:
371- build_args = ['-j', max_jobs]372+ cmake_args.append("-GNinja")
373+ 
374+ max_jobs = os.getenv("MAX_JOBS")
375+ if max_jobs is not None or not USE_NINJA:
376+ max_jobs = max_jobs or str(multiprocessing.cpu_count())
377+ build_args = ['-j', max_jobs]
378+ else:
379+ build_args = []
372 380 
373 subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ)381 subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ)
374 for base_dir, dirs, files in os.walk(build_type_dir):382 for base_dir, dirs, files in os.walk(build_type_dir):
@@ -379,7 +387,10 @@ class CPPLibBuild(build_clib, object):
379 file_path = os.path.join(base_dir, file_name)387 file_path = os.path.join(base_dir, file_name)
380 os.chmod(file_path, mode=BUILD_PERMISSION)388 os.chmod(file_path, mode=BUILD_PERMISSION)
381 389 
382- subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ)390+ if USE_NINJA:
391+ subprocess.check_call(['ninja'] + build_args, cwd=build_type_dir, env=os.environ)
392+ else:
393+ subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ)
383 394 
384 395 
385class Build(build_ext, object):396class Build(build_ext, object):
Mthird_party/Tensorpipe+1-1
@@ -1 +1 @@
1-Subproject commit 483a5907c1d4000094924a8c1b1ae6ed1859dcc11+Subproject commit d8a18ac35924bfc56b36a138868e3c71ff5f203f