-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup.py
115 lines (97 loc) Β· 3.72 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import sys
import platform
from glob import glob
from setuptools import setup
from setuptools import find_packages
from setuptools import Extension
from distutils.dir_util import copy_tree
from distutils.file_util import copy_file
try:
from Cython.Build import cythonize
except ImportError:
print("Warning: Cython is not installed", file=sys.stderr)
# Falling back to simpler build
cythonize = lambda x: x
aimrocks_extra_compile_args = [
'-std=c++11',
'-O3',
'-Wall',
'-Wextra',
'-Wconversion',
'-fno-strict-aliasing',
'-fno-rtti',
'-fPIC',
]
aimrocks_extra_link_args = []
if platform.system() == 'Darwin':
aimrocks_extra_compile_args += ['-mmacosx-version-min=10.7', '-stdlib=libc++']
aimrocks_extra_link_args += ["-Wl,-rpath,@loader_path"]
else:
aimrocks_extra_link_args += ["-Wl,-rpath,$ORIGIN"]
third_party_install_dir = os.environ.get('AIM_DEP_DIR', '/usr/local')
# By default aimrocks is only linked to rocksdb.
third_party_deps = ['rocksdb']
# `AIMROCKS_LINK_LIBS` can be used to link against additional libraries.
if os.environ.get("AIMROCKS_LINK_LIBS") is not None:
third_party_deps += os.environ.get("AIMROCKS_LINK_LIBS", "").split(",")
third_party_lib_dir = os.path.join(third_party_install_dir, 'lib')
# We define a local include directory to store all the required public headers.
# The third party headers are copied into this directory to enable binding with
# the precompiled aimrocks binaries without third-party dependencies.
local_include_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'src/aimrocks/include')
)
local_lib_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), 'src/aimrocks')
)
if os.environ.get("AIMROCKS_EMBED_ROCKSDB", "1") == "1":
third_party_libs = glob(os.path.join(third_party_lib_dir, 'librocksdb.*'))
print('third party libs detected:', third_party_libs)
for source in third_party_libs:
print('copying third party lib', source, local_lib_dir)
copy_file(source, local_lib_dir)
third_party_headers = [os.path.join(third_party_install_dir, 'include/rocksdb')]
for source in third_party_headers:
basename = os.path.basename(source)
destination = os.path.join(local_include_dir, basename)
copy_tree(source, destination,
preserve_symlinks=False, update=True)
# `include_dirs` is used to specify the include directories for the extension.
# It contains the aimrocks local headers and the rocksdb ones.
include_dirs = [os.path.join(third_party_install_dir, 'include/'), local_include_dir]
exts = [
Extension(
'aimrocks.lib_rocksdb',
['src/aimrocks/lib_rocksdb.pyx'],
extra_compile_args=aimrocks_extra_compile_args,
extra_link_args=aimrocks_extra_link_args,
language='c++',
include_dirs=include_dirs,
library_dirs=[third_party_lib_dir],
libraries=third_party_deps,
)
]
setup(
name="aimrocks",
version='0.5.2',
description='RocksDB wrapper implemented in Cython.',
setup_requires=['setuptools>=25', 'Cython>=3.0.0a9'],
packages=find_packages('./src'),
package_dir={'': 'src'},
package_data={'aimrocks': ['src/*']},
ext_modules=cythonize(exts),
include_package_data=True,
zip_safe=False,
classifiers=[
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
],
)