diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 2230ae9..af45ab6 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -65,6 +65,17 @@ jobs: # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Build libmixin.a + if: ${{ matrix.os == 'windows-2019' }} + working-directory: src/mixin + shell: pwsh + run: | + choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64" + go build -o mixin.dll -buildmode=c-shared + copy mixin.dll ../../pysrc/mixin.dll + gendef mixin.dll + cmd /c "`"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat`" && lib /def:mixin.def /machine:x64 /out:mixin.lib" + - name: Build libmixin.a + if: ${{ matrix.os != 'windows-2019' }} working-directory: src/mixin run: | go build -o libmixin.a -buildmode=c-archive diff --git a/setup.py b/setup.py index 4d92cec..a1066e1 100644 --- a/setup.py +++ b/setup.py @@ -5,8 +5,11 @@ from setuptools import find_packages, setup, Extension from Cython.Build import cythonize -os.environ["CC"] = "clang" -os.environ["CXX"] = "clang++" +dir_name = os.path.dirname(os.path.realpath(__file__)) + +if not platform.system() == 'Windows': + os.environ["CC"] = "clang" + os.environ["CXX"] = "clang++" # Require pytest-runner only when running tests pytest_runner = (['pytest-runner>=2.0,<3dev'] @@ -26,33 +29,6 @@ version = platform.python_version_tuple() version = '%s.%s' % (version[0], version[1]) -dir_name = os.path.dirname(os.path.realpath(__file__)) - -root_path = os.path.join(dir_name, 'src/mixin') -def check_modification(): - lib_name = os.path.join(root_path, 'libmixin.a') - if not os.path.exists(lib_name): - return True - modify_time = os.path.getmtime(lib_name) - for root, dirs, files in os.walk(root_path): - for f in files: - if f[-3:] == '.go': - f = os.path.join(root, f) - file_time = os.path.getmtime(f) - if modify_time < file_time: - return True - return False - -r = check_modification() -if r: - print('mixin lib need to rebuild.') - os.system(f'touch {root_path}/main.go') - -if platform.system() == 'Windows': - 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') -else: - os.system('cd ./src/mixin;go build -o libmixin.a -buildmode=c-archive') - ext_modules = [ Extension( 'pymixin._mixin', @@ -64,7 +40,8 @@ def check_modification(): ], language='c++', extra_compile_args=['-std=c++17'], - extra_link_args=['-L./src/mixin', '-lmixin'], + library_dirs=[os.path.join(dir_name, 'src/mixin')], + libraries = ['mixin'] ) ]