-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
93 lines (81 loc) · 2.9 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
import os
import subprocess
import shutil
import platform
class BuildPyCommand(build_py):
"""Modified build command to compile C library."""
def __build_c_library(self):
this_dir = os.path.dirname(__file__)
c_dir = os.path.normpath(os.path.join(this_dir, "..", "c"))
# building C library
subprocess.call(["cargo", "clean"], cwd=c_dir)
if platform.system() == "Darwin":
print("x86_64-apple-darwin compilation")
subprocess.call(
["cargo", "build", "--target=x86_64-apple-darwin", "--release"],
cwd=c_dir,
)
print("aarch64-apple-darwin compilation")
subprocess.call(
["cargo", "build", "--target=aarch64-apple-darwin", "--release"],
cwd=c_dir,
)
subprocess.call(
[
"lipo",
"-create",
os.path.join(
c_dir,
"target",
"aarch64-apple-darwin",
"release",
"libwkw.dylib",
),
os.path.join(
c_dir,
"target",
"x86_64-apple-darwin",
"release",
"libwkw.dylib",
),
"-output",
os.path.join(c_dir, "target", "release", "libwkw.dylib"),
],
cwd=c_dir,
)
else:
subprocess.call(["cargo", "build", "--release"], cwd=c_dir)
lib_name_platform = {
"Linux": "libwkw.so",
"Windows": "wkw.dll",
"Darwin": "libwkw.dylib",
}
lib_name = lib_name_platform[platform.system()]
lib_file = os.path.join(c_dir, "target", "release", lib_name)
header_file = os.path.join(c_dir, "include", "wkw.h")
# copying to lib dir
lib_dir = os.path.join(this_dir, "wkw", "lib")
if os.path.exists(lib_dir):
shutil.rmtree(lib_dir)
os.makedirs(lib_dir)
shutil.copy(lib_file, os.path.join(lib_dir, lib_name))
shutil.copy(header_file, os.path.join(lib_dir, "wkw.h"))
def run(self):
self.__build_c_library()
build_py.run(self)
setup(
name="wkw",
use_scm_version={"root": ".."},
setup_requires=["setuptools_scm"],
author="Alessandro Motta",
author_email="alessandro.motta@brain.mpg.de",
url="https://github.com/scalableminds/webknossos-wrap",
long_description_content_type="text/markdown",
packages=find_packages(),
include_package_data=True,
license="MIT",
install_requires=["cffi", "numpy>=1.15"],
cmdclass={"build_py": BuildPyCommand},
)