forked from sourmash-bio/sourmash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
69 lines (54 loc) · 1.81 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
import os
import sys
from setuptools import setup
DEBUG_BUILD = os.environ.get("SOURMASH_DEBUG") == "1"
NO_BUILD = os.environ.get("NO_BUILD") == "1"
def find_dylib_no_build(name, paths):
to_find = None
if sys.platform == 'darwin':
to_find = f'lib{name}.dylib'
elif sys.platform == 'win32':
to_find = f'{name}.dll'
else:
to_find = f'lib{name}.so'
for path in paths.split(":"):
for filename in os.listdir(path):
if filename == to_find:
return os.path.join(path, filename)
raise LookupError('dylib %r not found' % name)
def find_dylib(build, target):
cargo_target = os.environ.get("CARGO_BUILD_TARGET")
if cargo_target:
in_path = "target/%s/%s" % (cargo_target, target)
else:
in_path = "target/%s" % target
return build.find_dylib("sourmash", in_path=in_path)
def build_native(spec):
cmd = ["cargo", "build",
"--manifest-path", "src/core/Cargo.toml",
# "--features", "parallel",
"--lib"]
target = "debug"
if not DEBUG_BUILD:
cmd.append("--release")
target = "release"
if NO_BUILD:
dylib = lambda: find_dylib_no_build("sourmash", os.environ["DYLD_LIBRARY_PATH"])
header_filename = lambda: "include/sourmash.h"
else:
build = spec.add_external_build(cmd=cmd, path=".")
dylib = lambda: find_dylib(build, target)
header_filename=lambda: build.find_header("sourmash.h", in_path="include")
rtld_flags = ["NOW"]
if sys.platform == "darwin":
rtld_flags.append("NODELETE")
spec.add_cffi_module(
module_path="sourmash._lowlevel",
dylib=dylib,
header_filename=header_filename,
rtld_flags=rtld_flags,
)
setup(
milksnake_tasks=[build_native],
package_dir={"": "src"},
)