-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
88 lines (76 loc) · 2.45 KB
/
setup.py
File metadata and controls
88 lines (76 loc) · 2.45 KB
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
import os
import sys
import sysconfig
from distutils.ccompiler import get_default_compiler
import numpy as np
from Cython.Build import cythonize
from setuptools import Extension, setup
from setupext import check_for_openmp
if check_for_openmp():
omp_args = ["-fopenmp"]
else:
omp_args = None
cpp11_args = ["-std=c++11" if get_default_compiler() != "msvc" else "/std:c++11"]
if os.name == "nt":
std_libs = []
else:
std_libs = ["m"]
# restrict LIMITED_API usage:
# - require an env var EWAH_BOOL_UTILS_LIMITED_API=1
# - compiling with Python 3.10 doesn't work (as of Cython 3.1.1)
# - LIMITED_API is not compatible with free-threading (as of CPython 3.14)
USE_PY_LIMITED_API = (
os.environ.get("EWAH_BOOL_UTILS_LIMITED_API") == "1"
and sys.version_info >= (3, 11)
and not sysconfig.get_config_var("Py_GIL_DISABLED")
)
ABI3_TARGET_VERSION = "".join(str(_) for _ in sys.version_info[:2])
ABI3_TARGET_HEX = hex(sys.hexversion & 0xFFFF00F0)
define_macros = [
("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION"),
# keep in sync with runtime requirements (pyproject.toml)
("NPY_TARGET_VERSION", "NPY_1_19_API_VERSION"),
]
if USE_PY_LIMITED_API:
define_macros.append(("Py_LIMITED_API", ABI3_TARGET_HEX))
extensions = [
Extension(
"ewah_bool_utils.ewah_bool_wrap",
["ewah_bool_utils/ewah_bool_wrap.pyx"],
define_macros=define_macros,
include_dirs=["ewah_bool_utils", "ewah_bool_utils/cpp", np.get_include()],
language="c++",
extra_compile_args=cpp11_args,
py_limited_api=USE_PY_LIMITED_API,
),
Extension(
"ewah_bool_utils.morton_utils",
["ewah_bool_utils/morton_utils.pyx"],
define_macros=define_macros,
extra_compile_args=omp_args,
extra_link_args=omp_args,
libraries=std_libs,
include_dirs=[np.get_include()],
py_limited_api=USE_PY_LIMITED_API,
),
Extension(
"ewah_bool_utils._testing",
["ewah_bool_utils/_testing.pyx"],
include_dirs=["ewah_bool_utils", "ewah_bool_utils/cpp", np.get_include()],
define_macros=define_macros,
extra_compile_args=["-O3"],
language="c++",
py_limited_api=USE_PY_LIMITED_API,
),
]
if USE_PY_LIMITED_API:
options = {"bdist_wheel": {"py_limited_api": f"cp{ABI3_TARGET_VERSION}"}}
else:
options = {}
setup(
ext_modules=cythonize(
extensions,
compiler_directives={"language_level": 3},
),
options=options,
)