-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
67 lines (58 loc) · 2.11 KB
/
setup.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.build_py import build_py as _build_py
import os
import shutil
import subprocess
import sys
class build_ext(_build_ext):
def build_extension(self, ext):
def run(command):
subprocess.check_call(command, cwd='xorsat/m4ri')
run(['autoreconf', '--install'])
run(['./configure'])
run(['make'])
super().build_extension(ext)
class build_py(_build_py):
def run(self):
self.run_command('build_ext')
return super().run()
def check_binary(name, command):
try:
subprocess.check_call(command)
except OSError:
print(f'Missing build dependency {name!r}, please install it first!',
file=sys.stderr)
sys.exit(1)
if __name__ == '__main__':
# Clean the build folder that setuptools creates before every run, or else it causes
# weird issues.
shutil.rmtree('build', ignore_errors=True)
check_binary('autoreconf', ['autoreconf', '--version'])
check_binary('make', ['make', '--version'])
# Make sure the m4ri submodule is loaded in advance
subprocess.check_call(['git', 'submodule', 'update', '--init', '--recursive'])
setup(
name='xorsat',
author='Lyndon Ho',
author_email='[email protected]',
description='efficient XOR-SAT solver',
version='0.1.0',
packages=find_packages(),
package_data={'xorsat': ['m4ri/.libs/*.so']},
ext_modules=[
Extension(
name='xorsat._xorsat',
sources=['xorsat/_xorsatmodule.c'],
extra_compile_args=['-O3', '-march=native'],
include_dirs=['xorsat/m4ri'],
libraries=['m4ri'],
library_dirs=['xorsat/m4ri/.libs'],
extra_link_args=['-Wl,-rpath=$ORIGIN/m4ri/.libs'],
),
],
cmdclass={
'build_ext': build_ext,
'build_py': build_py,
},
)