Skip to content

Commit

Permalink
Allow dynamic linking to system libuv
Browse files Browse the repository at this point in the history
Added build_ext option --use-system-libuv to switch between
dynamic and static linking.
  • Loading branch information
mtorromeo authored and 1st1 committed May 9, 2016
1 parent f2a5da5 commit d652656
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
35 changes: 27 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@


class libuv_build_ext(build_ext):
build_ext.user_options.extend([
("use-system-libuv", None,
"Use the system provided libuv, instead of the bundled one")
])

build_ext.boolean_options.extend(["use-system-libuv"])

def initialize_options(self):
build_ext.initialize_options(self)
self.use_system_libuv = 0

def build_libuv(self):
env = os.environ.copy()

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

def build_extensions(self):
libuv_lib = os.path.join(LIBUV_DIR, '.libs', 'libuv.a')
if not os.path.exists(libuv_lib):
self.build_libuv()
if not os.path.exists(libuv_lib):
raise RuntimeError('failed to build libuv')

self.extensions[-1].extra_objects.extend([libuv_lib])
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))
if self.use_system_libuv:
self.compiler.add_library('uv')

if sys.platform == 'darwin' and \
os.path.exists('/opt/local/include'):
# Support macports on Mac OS X.
self.compiler.add_include_dir('/opt/local/include')
else:
libuv_lib = os.path.join(LIBUV_DIR, '.libs', 'libuv.a')
if not os.path.exists(libuv_lib):
self.build_libuv()
if not os.path.exists(libuv_lib):
raise RuntimeError('failed to build libuv')

self.extensions[-1].extra_objects.extend([libuv_lib])
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))

if sys.platform.startswith('linux'):
self.compiler.add_library('rt')
Expand Down
2 changes: 1 addition & 1 deletion uvloop/includes/uv.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from posix.types cimport gid_t, uid_t
from . cimport system


cdef extern from "../vendor/libuv/include/uv.h" nogil:
cdef extern from "uv.h" nogil:
cdef int UV_EACCES
cdef int UV_EAGAIN
cdef int UV_EALREADY
Expand Down

0 comments on commit d652656

Please sign in to comment.