2015-11-01 17:00:43 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from setuptools import setup, Extension
|
|
|
|
from setuptools.command.build_ext import build_ext
|
|
|
|
|
|
|
|
|
|
|
|
LIBUV_DIR = os.path.join(os.path.dirname(__file__), 'vendor', 'libuv')
|
|
|
|
|
|
|
|
|
|
|
|
class libuv_build_ext(build_ext):
|
|
|
|
def build_libuv(self):
|
|
|
|
cflags = '-fPIC'
|
|
|
|
env = os.environ.copy()
|
|
|
|
|
|
|
|
env['CFLAGS'] = ('-fPIC ' +
|
2015-11-06 22:01:13 +00:00
|
|
|
env.get('CFLAGS', '-O2') +
|
2015-11-01 17:00:43 +00:00
|
|
|
' ' +
|
|
|
|
env.get('ARCHFLAGS', ''))
|
|
|
|
|
|
|
|
subprocess.run(['sh', 'autogen.sh'], cwd=LIBUV_DIR, env=env)
|
|
|
|
subprocess.run(['./configure'], cwd=LIBUV_DIR, env=env)
|
|
|
|
subprocess.run(['make', '-j4'], cwd=LIBUV_DIR, env=env)
|
|
|
|
|
|
|
|
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')
|
|
|
|
|
2015-11-11 05:25:37 +00:00
|
|
|
self.extensions[-1].extra_objects.extend([libuv_lib])
|
2015-11-01 17:00:43 +00:00
|
|
|
self.compiler.add_include_dir(os.path.join(LIBUV_DIR, 'include'))
|
|
|
|
|
|
|
|
if sys.platform.startswith('linux'):
|
|
|
|
self.compiler.add_library('rt')
|
|
|
|
elif sys.platform.startswith('freebsd'):
|
|
|
|
self.compiler.add_library('kvm')
|
|
|
|
|
|
|
|
super().build_extensions()
|
|
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
name='uvloop',
|
|
|
|
version='0.0.1',
|
|
|
|
packages=['uvloop'],
|
|
|
|
cmdclass = {'build_ext': libuv_build_ext},
|
|
|
|
ext_modules=[
|
|
|
|
Extension(
|
2015-11-02 20:11:19 +00:00
|
|
|
"uvloop.loop",
|
2015-11-01 17:00:43 +00:00
|
|
|
sources = [
|
2015-11-02 20:11:19 +00:00
|
|
|
"uvloop/loop.c",
|
|
|
|
]
|
|
|
|
),
|
2015-11-01 17:00:43 +00:00
|
|
|
],
|
|
|
|
provides=['uvloop'],
|
|
|
|
include_package_data=True
|
|
|
|
)
|