-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
94 lines (82 loc) · 3.02 KB
/
Copy pathsetup.py
File metadata and controls
94 lines (82 loc) · 3.02 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
89
90
91
92
93
94
"""Setup script for building Cython extensions with liburing."""
import os
import sys
import platform
from setuptools import setup
from Cython.Build import cythonize
from setuptools.extension import Extension
def get_extensions():
"""Build list of Cython extensions."""
# Check if we're on Linux (io_uring is Linux-only)
if sys.platform != "linux":
print("WARNING: io_uring is only available on Linux.")
print("Building stub module for development/documentation purposes.")
# Return empty list on non-Linux platforms
# The package will still install but the Cython extension won't be built
return []
def make_compile_args():
"""Return a conservative set of arch-aware compile flags.
- Default to `-O3` and `-mtune=generic` for portability.
- Prefer an explicit arch target instead of `-march=native`.
- Allow overrides via `AIO_URING_EXTRA_CFLAGS` or the `CFLAGS` env var.
"""
arch = platform.machine().lower()
flags = ["-O3"]
if arch in ("x86_64", "amd64"):
flags += ["-march=x86-64", "-mtune=generic"]
elif arch in ("aarch64", "arm64"):
flags += ["-march=armv8-a", "-mtune=generic"]
else:
flags += ["-mtune=generic"]
# Environment override (user-specified)
env_flags = os.environ.get("AIO_URING_EXTRA_CFLAGS") or os.environ.get("CFLAGS")
if env_flags:
# Basic split; users should quote values correctly in CI or envs
flags += env_flags.split()
return flags
_extra_compile_args = make_compile_args()
extensions = [
Extension(
"aio_uring.core.fast_future",
sources=["src/aio_uring/core/fast_future.pyx"],
include_dirs=["src/aio_uring/core"],
language="c++",
extra_compile_args=_extra_compile_args,
),
Extension(
"aio_uring.core.op_context",
sources=["src/aio_uring/core/op_context.pyx"],
include_dirs=["src/aio_uring/core"],
language="c++",
extra_compile_args=_extra_compile_args,
),
Extension(
"aio_uring.core.uring_file",
sources=["src/aio_uring/core/uring_file.pyx"],
include_dirs=["src/aio_uring/core"],
language="c++",
extra_compile_args=_extra_compile_args,
),
Extension(
"aio_uring.core.UringProactor",
sources=["src/aio_uring/core/UringProactor.pyx"],
include_dirs=["src/aio_uring/core"],
libraries=["uring"],
language="c++",
extra_compile_args=_extra_compile_args,
extra_link_args=["-luring"],
),
]
return cythonize(
extensions,
compiler_directives={
"language_level": "3",
"boundscheck": False,
"wraparound": False,
"cdivision": True,
"initializedcheck": False,
},
)
setup(
ext_modules=get_extensions(),
)