-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
50 lines (37 loc) · 1.16 KB
/
build.py
File metadata and controls
50 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from functools import partial
from typing import Any
from Cython.Build import cythonize
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
ext_modules = [
Extension(
"demo.core",
sources=["lib/core.pyx", "lib/libcore.cpp"],
language="c++",
),
]
class BuildExt(build_ext):
compiler_flags = {
"msvc": "/std:{std}",
"unix": "-std={std}",
}
def __init__(self, *args: Any, std: str = "", **kwargs: Any):
self.std = std
super().__init__(*args, **kwargs)
def build_extensions(self):
if self.std:
std_options = [self.compiler_flags[self.compiler.compiler_type].format(std=self.std)]
else:
std_options = []
for ext in self.extensions:
ext.extra_compile_args += std_options
ext.extra_link_args += std_options
super().build_extensions()
Cpp20BuildExt = partial(BuildExt, std="c++20")
def build(setup_kwargs: dict[str, Any]):
setup_kwargs.update(
{
"ext_modules": cythonize(ext_modules),
"cmdclass": {"build_ext": Cpp20BuildExt},
}
)