Skip to content

Commit 173bfcd

Browse files
Add setup.py to build kernels
1 parent c00bf5b commit 173bfcd

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

setup.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Custom build: compile CPU kernels (make) during pip install."""
2+
3+
import subprocess
4+
import os
5+
from setuptools import setup
6+
from setuptools.command.build_py import build_py
7+
from setuptools.command.develop import develop
8+
9+
ROOT = os.path.dirname(os.path.abspath(__file__))
10+
11+
KERNEL_DIRS = [
12+
os.path.join(ROOT, "kernels", "bit_1", "cpu"),
13+
os.path.join(ROOT, "kernels", "bit_1_58", "cpu"),
14+
]
15+
16+
17+
def _build_kernels():
18+
for d in KERNEL_DIRS:
19+
if os.path.isdir(d) and os.path.isfile(os.path.join(d, "Makefile")):
20+
subprocess.check_call(["make", "-C", d])
21+
22+
23+
class BuildPyWithKernels(build_py):
24+
def run(self):
25+
_build_kernels()
26+
super().run()
27+
28+
29+
class DevelopWithKernels(develop):
30+
def run(self):
31+
_build_kernels()
32+
super().run()
33+
34+
35+
setup(
36+
cmdclass={
37+
"build_py": BuildPyWithKernels,
38+
"develop": DevelopWithKernels,
39+
},
40+
)

0 commit comments

Comments
 (0)