Skip to content

Commit 8b3c2c4

Browse files
committed
🐛 fix: msvc flag
1 parent 82b3f8e commit 8b3c2c4

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

build.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from functools import partial
12
from typing import Any
23

34
from Cython.Build import cythonize
@@ -9,16 +10,41 @@
910
"demo.core",
1011
sources=["lib/core.pyx", "lib/libcore.cpp"],
1112
language="c++",
12-
extra_compile_args=["-std=c++17"],
13-
extra_link_args=["-std=c++17"],
1413
),
1514
]
1615

1716

17+
class BuildExt(build_ext):
18+
19+
compiler_flags = {
20+
"msvc": "/std:{std}",
21+
"unix": "-std={std}",
22+
}
23+
24+
def __init__(self, *args: Any, std: str = "", **kwargs: Any):
25+
self.std = std
26+
super().__init__(*args, **kwargs)
27+
28+
def build_extensions(self):
29+
if self.std:
30+
std_options = [self.compiler_flags[self.compiler.compiler_type].format(std=self.std)]
31+
else:
32+
std_options = []
33+
34+
for ext in self.extensions:
35+
ext.extra_compile_args += std_options
36+
ext.extra_link_args += std_options
37+
38+
super().build_extensions()
39+
40+
41+
Cpp20BuildExt = partial(BuildExt, std="c++20")
42+
43+
1844
def build(setup_kwargs: dict[str, Any]):
1945
setup_kwargs.update(
2046
{
2147
"ext_modules": cythonize(ext_modules),
22-
"cmdclass": {"build_ext": build_ext},
48+
"cmdclass": {"build_ext": Cpp20BuildExt},
2349
}
2450
)

0 commit comments

Comments
 (0)