Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
81 lines (70 loc) · 2.2 KB
/
Copy pathsetup.py
File metadata and controls
81 lines (70 loc) · 2.2 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
import os
import sys
from setuptools import setup, Extension
from Cython.Build import cythonize
def _platform_id():
tag = os.environ.get("CIBW_BUILD", "local")
return tag.split("-", 1)[1] if "-" in tag else tag
extra_compile_args = [
"-ffunction-sections", # Enable function-level sections
"-fdata-sections", # Enable data-level sections
"-O2", # Default optimization for non-ASAN builds
]
# Avoid gc-sections when statically linking C++ libs with RTTI/vtables
extra_link_args = [
# intentionally no --gc-sections
"-lstdc++", # Link against C++ standard library
]
# Enable optional AddressSanitizer build via env var ASAN=1
if os.environ.get("ASAN") == "1":
# Favor debuggability over speed; replace -O2 with lower optimization.
extra_compile_args = [
"-ffunction-sections",
"-fdata-sections",
"-O1",
"-g",
"-fno-omit-frame-pointer",
"-fsanitize=address",
]
extra_link_args += [
"-fsanitize=address",
]
repo_root = os.path.abspath(os.path.dirname(__file__))
plat_id = _platform_id()
geos_include = os.path.join(repo_root, "vendor", "geos", plat_id, "include")
geos_lib = os.path.join(repo_root, "vendor", "geos", plat_id, "lib")
geos_c_a = os.path.join(geos_lib, "libgeos_c.a")
geos_a = os.path.join(geos_lib, "libgeos.a")
if sys.platform == "darwin":
whole_archive_flags = [
"-Wl,-force_load," + geos_c_a,
"-Wl,-force_load," + geos_a,
]
else:
whole_archive_flags = [
"-Wl,--whole-archive",
geos_c_a,
geos_a,
"-Wl,--no-whole-archive",
]
setup(
ext_modules=cythonize(
[
Extension(
"togo",
sources=["togo.pyx", "tg.c", "tgx.c"],
include_dirs=[
".", # For tg.h and tgx.h
geos_include,
],
# Link static archives as whole-archive to keep all needed RTTI/vtables
extra_compile_args=extra_compile_args,
extra_link_args=whole_archive_flags + extra_link_args,
)
]
),
# Explicitly disable auto-discovery in flat layout
packages=[],
py_modules=[],
license="MIT",
)