Skip to content

Commit 424588b

Browse files
committed
Use ninja build system
1 parent 1e5afe2 commit 424588b

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=64", "cmake>=3.16"]
2+
requires = ["setuptools>=64", "cmake>=3.16", "ninja"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

setup.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
from setuptools import setup, Extension
77
from setuptools.command.build_ext import build_ext
88

9-
PLAT_TO_CMAKE = {
10-
"win32": "Win32",
11-
"win-amd64": "x64",
12-
"win-arm32": "ARM",
13-
"win-arm64": "ARM64",
14-
}
15-
169

1710
class CMakeExtension(Extension):
1811
def __init__(self, name: str, sourcedir: str = "") -> None:
@@ -30,26 +23,23 @@ def build_extension(self, ext: CMakeExtension) -> None:
3023
cmake_args = [
3124
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}",
3225
f"-DPython_EXECUTABLE={sys.executable}",
26+
f"-DCMAKE_BUILD_TYPE=Release",
3327
]
3428

3529
build_args = ["--config", "Release"]
3630

37-
if sys.platform == "win32":
38-
# MSVC: set architecture and output directory per-config
39-
single_config = any(
40-
x in cmake_generator for x in ("NMake", "Ninja")
41-
)
42-
contains_arch = any(
43-
x in cmake_generator for x in ("ARM", "Win64")
44-
)
45-
if not single_config and not contains_arch:
46-
cmake_args += ["-A", PLAT_TO_CMAKE[self.plat_name]]
47-
if not single_config:
31+
# On Windows, use Ninja if no generator is specified to avoid
32+
# Visual Studio multi-config generator issues with pybind11
33+
if sys.platform == "win32" and not cmake_generator:
34+
try:
35+
import ninja
36+
ninja_executable_path = Path(ninja.BIN_DIR) / "ninja"
4837
cmake_args += [
49-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE={extdir}{os.sep}",
38+
"-GNinja",
39+
f"-DCMAKE_MAKE_PROGRAM:FILEPATH={ninja_executable_path}",
5040
]
51-
else:
52-
cmake_args += ["-DCMAKE_BUILD_TYPE=Release"]
41+
except ImportError:
42+
pass
5343

5444
if "CMAKE_BUILD_PARALLEL_LEVEL" not in os.environ:
5545
if hasattr(self, "parallel") and self.parallel:

0 commit comments

Comments
 (0)