|
1 | 1 | import os
|
2 | 2 | import sys
|
3 | 3 | import platform
|
4 |
| -from setuptools import find_packages |
5 |
| -from skbuild import setup |
6 |
| - |
| 4 | + |
| 5 | +from setuptools import find_packages, setup, Extension |
| 6 | +from Cython.Build import cythonize |
| 7 | + |
| 8 | +os.environ["CC"] = "clang" |
| 9 | +os.environ["CXX"] = "clang++" |
| 10 | + |
7 | 11 | # Require pytest-runner only when running tests
|
8 | 12 | pytest_runner = (['pytest-runner>=2.0,<3dev']
|
9 | 13 | if any(arg in sys.argv for arg in ('pytest', 'test'))
|
|
22 | 26 | version = platform.python_version_tuple()
|
23 | 27 | version = '%s.%s' % (version[0], version[1])
|
24 | 28 |
|
| 29 | +dir_name = os.path.dirname(os.path.realpath(__file__)) |
| 30 | + |
| 31 | +root_path = os.path.join(dir_name, 'src/mixin') |
| 32 | +def check_modification(): |
| 33 | + lib_name = os.path.join(root_path, 'libmixin.a') |
| 34 | + if not os.path.exists(lib_name): |
| 35 | + return True |
| 36 | + modify_time = os.path.getmtime(lib_name) |
| 37 | + for root, dirs, files in os.walk(root_path): |
| 38 | + for f in files: |
| 39 | + if f[-3:] == '.go': |
| 40 | + f = os.path.join(root, f) |
| 41 | + file_time = os.path.getmtime(f) |
| 42 | + if modify_time < file_time: |
| 43 | + return True |
| 44 | + return False |
| 45 | + |
| 46 | +r = check_modification() |
| 47 | +if r: |
| 48 | + print('mixin lib need to rebuild.') |
| 49 | + os.system(f'touch {root_path}/main.go') |
| 50 | + |
| 51 | +if platform.system() == 'Windows': |
| 52 | + os.system('cd ./src/mixin &&go build -o mixin.dll -buildmode=c-shared && copy mixin.dll ../../pysrc/mixin.dll && gendef mixin.dll && lib /def:mixin.def /machine:x64 /out:mixin.lib') |
| 53 | +else: |
| 54 | + os.system('cd ./src/mixin;go build -o libmixin.a -buildmode=c-archive') |
| 55 | + |
| 56 | +ext_modules = [ |
| 57 | + Extension( |
| 58 | + 'pymixin._mixin', |
| 59 | + sources=[ |
| 60 | + 'src/_mixin.pyx', |
| 61 | + ], |
| 62 | + include_dirs=[ |
| 63 | + 'src/mixin', |
| 64 | + ], |
| 65 | + language='c++', |
| 66 | + extra_compile_args=['-std=c++17'], |
| 67 | + extra_link_args=['-L./src/mixin', '-lmixin'], |
| 68 | + ) |
| 69 | +] |
| 70 | + |
25 | 71 | setup(
|
26 | 72 | name="mixin-python",
|
27 | 73 | version="0.2.10",
|
|
34 | 80 | package_data={'pymixin': data},
|
35 | 81 | data_files = data_files,
|
36 | 82 | scripts=[],
|
| 83 | + ext_modules=cythonize( |
| 84 | + ext_modules, |
| 85 | + compiler_directives={'language_level': 3, }, |
| 86 | + ), |
37 | 87 | install_requires=[
|
38 | 88 | "PyJWT>=2.4.0",
|
39 | 89 | "websockets>=9.1",
|
|
0 commit comments