-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
59 lines (43 loc) · 1.32 KB
/
build.py
File metadata and controls
59 lines (43 loc) · 1.32 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
51
52
53
54
55
56
57
58
59
from __future__ import annotations
from typing import Any
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
ext_modules = [
Extension(
"c_api_example.spam",
sources=["csrc/spam.c"],
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()
class C11BuildExt(BuildExt):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, std="c11", **kwargs)
def build(setup_kwargs: dict[str, Any]):
setup_kwargs.update(
{
"ext_modules": ext_modules,
"cmdclass": {"build_ext": C11BuildExt},
}
)
if __name__ == "__main__":
from setuptools import setup
setup_kwargs = {}
build(setup_kwargs)
setup(**setup_kwargs)