-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildext.py
81 lines (52 loc) · 1.48 KB
/
buildext.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
"""
Building Python extension modules via pybind11
The script can be used from Poetry pyproject.toml:
[tool.poetry]
build = "buildext.py"
...
poetry install
Or directly via distutils 'build' command:
python buildext.py build
python buildext.py build --debug # for debug symbols
"""
import sys
from pathlib import Path
import shutil
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
from distutils.core import Distribution
MODULE_NAME = '_rtspm'
ROOT_PATH = Path(__name__).parent
SOURCE_DIR = ROOT_PATH / 'src'
SOURCES = sorted(map(str, SOURCE_DIR.glob('*.cpp')))
DEFINE_MACROS = []
if sys.platform == 'win32':
DEFINE_MACROS.append(
('SPM_WIN32', None),
)
ext_modules = [
Pybind11Extension(MODULE_NAME, SOURCES, define_macros=DEFINE_MACROS),
]
def build(setup_kwargs: dict):
setup_kwargs.update({
"ext_modules": ext_modules,
"cmdclass": {"build_ext": build_ext}
})
def copy_lib_files(dist: Distribution):
build_cmd = dist.get_command_obj('build')
lib_dir = ROOT_PATH / build_cmd.build_lib
for fpath in lib_dir.iterdir():
shutil.copy2(fpath, ROOT_PATH)
def main():
"""Minimal setup to build pybind11 extension modules with debug symbols
Usage::
python buildext.py build --debug
"""
setup_kwargs = {
'name': MODULE_NAME,
}
build(setup_kwargs)
dist = setup(**setup_kwargs)
copy_lib_files(dist)
if __name__ == '__main__':
main()