Skip to content

Commit

Permalink
Fix build on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
learnforpractice committed Jun 26, 2023
1 parent b68b17d commit 827a4bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 30 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/python-app.yml
Expand Up @@ -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
Expand Down
37 changes: 7 additions & 30 deletions setup.py
Expand Up @@ -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']
Expand All @@ -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',
Expand All @@ -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']
)
]

Expand Down

0 comments on commit 827a4bd

Please sign in to comment.