17
17
18
18
19
19
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
+
20
31
def build_libuv (self ):
21
32
env = os .environ .copy ()
22
33
@@ -35,14 +46,22 @@ def build_libuv(self):
35
46
subprocess .run (['make' , j_flag ], cwd = LIBUV_DIR , env = env , check = True )
36
47
37
48
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' ))
46
65
47
66
if sys .platform .startswith ('linux' ):
48
67
self .compiler .add_library ('rt' )
0 commit comments