-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_extension.py
46 lines (38 loc) · 1.54 KB
/
build_extension.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
from typing import Any, Dict
from setuptools import Extension
from setuptools.command.build_ext import build_ext
from setuptools.errors import CompileError
extension = Extension(
name="bico._core",
sources=[
"bico/_core.cpp",
"bico/point/pointcentroid.cpp",
"bico/point/squaredl2metric.cpp",
"bico/point/point.cpp",
"bico/point/realspaceprovider.cpp",
"bico/point/l2metric.cpp",
],
include_dirs=["bico"],
)
# Thank you https://github.com/dstein64/kmeans1d!
class BuildExt(build_ext):
"""A custom build extension for adding -stdlib arguments for clang++."""
def build_extensions(self) -> None:
# '-std=c++11' is added to `extra_compile_args` so the code can compile
# with clang++. This works across compilers (ignored by MSVC).
for extension in self.extensions:
extension.extra_compile_args.append("-std=c++11")
try:
build_ext.build_extensions(self)
except CompileError:
# Workaround Issue #2.
# '-stdlib=libc++' is added to `extra_compile_args` and `extra_link_args`
# so the code can compile on macOS with Anaconda.
for extension in self.extensions:
extension.extra_compile_args.append("-stdlib=libc++")
extension.extra_link_args.append("-stdlib=libc++")
build_ext.build_extensions(self)
def build(setup_kwargs: Dict[str, Any]) -> None:
setup_kwargs.update(
{"ext_modules": [extension], "cmdclass": {"build_ext": BuildExt}}
)