Skip to content

Commit 827a4bd

Browse files
Fix build on Windows
1 parent b68b17d commit 827a4bd

File tree

2 files changed

+18
-30
lines changed

2 files changed

+18
-30
lines changed

.github/workflows/python-app.yml

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ jobs:
6565
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
6666
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
6767
- name: Build libmixin.a
68+
if: ${{ matrix.os == 'windows-2019' }}
69+
working-directory: src/mixin
70+
shell: pwsh
71+
run: |
72+
choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
73+
go build -o mixin.dll -buildmode=c-shared
74+
copy mixin.dll ../../pysrc/mixin.dll
75+
gendef mixin.dll
76+
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"
77+
- name: Build libmixin.a
78+
if: ${{ matrix.os != 'windows-2019' }}
6879
working-directory: src/mixin
6980
run: |
7081
go build -o libmixin.a -buildmode=c-archive

setup.py

+7-30
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
from setuptools import find_packages, setup, Extension
66
from Cython.Build import cythonize
77

8-
os.environ["CC"] = "clang"
9-
os.environ["CXX"] = "clang++"
8+
dir_name = os.path.dirname(os.path.realpath(__file__))
9+
10+
if not platform.system() == 'Windows':
11+
os.environ["CC"] = "clang"
12+
os.environ["CXX"] = "clang++"
1013

1114
# Require pytest-runner only when running tests
1215
pytest_runner = (['pytest-runner>=2.0,<3dev']
@@ -26,33 +29,6 @@
2629
version = platform.python_version_tuple()
2730
version = '%s.%s' % (version[0], version[1])
2831

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-
5632
ext_modules = [
5733
Extension(
5834
'pymixin._mixin',
@@ -64,7 +40,8 @@ def check_modification():
6440
],
6541
language='c++',
6642
extra_compile_args=['-std=c++17'],
67-
extra_link_args=['-L./src/mixin', '-lmixin'],
43+
library_dirs=[os.path.join(dir_name, 'src/mixin')],
44+
libraries = ['mixin']
6845
)
6946
]
7047

0 commit comments

Comments
 (0)