Skip to content

Commit d652656

Browse files
mtorromeo1st1
authored andcommitted
Allow dynamic linking to system libuv
Added build_ext option --use-system-libuv to switch between dynamic and static linking.
1 parent f2a5da5 commit d652656

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

setup.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818

1919
class libuv_build_ext(build_ext):
20+
build_ext.user_options.extend([
21+
("use-system-libuv", None,
22+
"Use the system provided libuv, instead of the bundled one")
23+
])
24+
25+
build_ext.boolean_options.extend(["use-system-libuv"])
26+
27+
def initialize_options(self):
28+
build_ext.initialize_options(self)
29+
self.use_system_libuv = 0
30+
2031
def build_libuv(self):
2132
env = os.environ.copy()
2233

@@ -35,14 +46,22 @@ def build_libuv(self):
3546
subprocess.run(['make', j_flag], cwd=LIBUV_DIR, env=env, check=True)
3647

3748
def build_extensions(self):
38-
libuv_lib = os.path.join(LIBUV_DIR, '.libs', 'libuv.a')
39-
if not os.path.exists(libuv_lib):
40-
self.build_libuv()
41-
if not os.path.exists(libuv_lib):
42-
raise RuntimeError('failed to build libuv')
43-
44-
self.extensions[-1].extra_objects.extend([libuv_lib])
45-
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))
49+
if self.use_system_libuv:
50+
self.compiler.add_library('uv')
51+
52+
if sys.platform == 'darwin' and \
53+
os.path.exists('/opt/local/include'):
54+
# Support macports on Mac OS X.
55+
self.compiler.add_include_dir('/opt/local/include')
56+
else:
57+
libuv_lib = os.path.join(LIBUV_DIR, '.libs', 'libuv.a')
58+
if not os.path.exists(libuv_lib):
59+
self.build_libuv()
60+
if not os.path.exists(libuv_lib):
61+
raise RuntimeError('failed to build libuv')
62+
63+
self.extensions[-1].extra_objects.extend([libuv_lib])
64+
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))
4665

4766
if sys.platform.startswith('linux'):
4867
self.compiler.add_library('rt')

uvloop/includes/uv.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from posix.types cimport gid_t, uid_t
44
from . cimport system
55

66

7-
cdef extern from "../vendor/libuv/include/uv.h" nogil:
7+
cdef extern from "uv.h" nogil:
88
cdef int UV_EACCES
99
cdef int UV_EAGAIN
1010
cdef int UV_EALREADY

0 commit comments

Comments
 (0)