-
Notifications
You must be signed in to change notification settings - Fork 8
/
builder.py
36 lines (33 loc) · 1.05 KB
/
builder.py
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
import os
import platform
from setuptools.command.build_ext import build_ext
import sysconfig
class ZigBuilder(build_ext):
def build_extension(self, ext):
assert len(ext.sources) == 1
if not os.path.exists(self.build_lib):
os.makedirs(self.build_lib)
windows = platform.system() == "Windows"
self.spawn(
[
"zig",
"build-lib",
"-O",
"ReleaseFast",
"-lc",
*(["-target", "x86_64-windows-msvc"] if windows else []),
f"-femit-bin={self.get_ext_fullpath(ext.name)}",
"-fallow-shlib-undefined",
"-dynamic",
*[f"-I{d}" for d in self.include_dirs],
*(
[
f"-L{sysconfig.get_config_var('installed_base')}\Libs",
"-lpython3",
]
if windows
else []
),
ext.sources[0],
]
)