diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index d4c229b..90ebbdb 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -3,7 +3,7 @@ on: push: branches: [main] pull_request: - + workflow_dispatch: jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index cc2b2db..8b4610f 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -3,6 +3,7 @@ on: push: branches: [main] pull_request: + workflow_dispatch: jobs: build: runs-on: macos-latest diff --git a/.github/workflows/ci-windows.yml b/.github/workflows/ci-windows.yml index 74698cc..2078abd 100644 --- a/.github/workflows/ci-windows.yml +++ b/.github/workflows/ci-windows.yml @@ -3,6 +3,7 @@ on: push: branches: [main] pull_request: + workflow_dispatch: jobs: build: runs-on: ubuntu-latest @@ -35,6 +36,14 @@ jobs: with: name: windows-installer path: concordance/win/concordance-installer.exe + - name: Build Python wheel + run: | + pip install build + MINGW_SYSROOT_BIN="/usr/i686-w64-mingw32/sys-root/mingw/bin" concordance/win/make_wheel.py + - uses: actions/upload-artifact@v4 + with: + name: windows-wheel + path: concordance/win/*.whl test: needs: build runs-on: windows-latest @@ -43,9 +52,22 @@ jobs: id: download with: name: windows-installer - - name: Install and test + - name: Install and test installer run: | - ${{steps.download.outputs.download-path}}\concordance-installer.exe /S + Start-Process -FilePath ${{steps.download.outputs.download-path}}\concordance-installer.exe -ArgumentList "/S" -NoNewWindow -Wait Start-Sleep -Seconds 5 cd "C:\Program Files (x86)\Concordance" .\concordance.exe --version + - uses: actions/download-artifact@v4 + id: downloadwheel + with: + name: windows-wheel + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + architecture: 'x86' + - name: Install and test wheel + run: | + pip install (gci ${{steps.downloadwheel.outputs.download-path}}\*.whl).FullName + python3 -c 'import libconcord; print(libconcord)' + diff --git a/concordance/win/make_wheel.py b/concordance/win/make_wheel.py new file mode 100755 index 0000000..b46c590 --- /dev/null +++ b/concordance/win/make_wheel.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +import os +import shutil +import subprocess +import tempfile +import glob + +cp = subprocess.run([ + 'mingw-ldd', + os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/.libs/libconcord-6.dll', + '--dll-lookup-dirs', + os.environ['MINGW_SYSROOT_BIN'], + os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/.libs', +], capture_output=True, check=True, text=True) +with tempfile.TemporaryDirectory() as tempdir: + subdir = os.path.join(tempdir,'libconcord') + os.mkdir(subdir) + for line in cp.stdout.splitlines(): + dll = line.split('=>')[1].strip() + if dll != 'not found': + shutil.copy2(dll, subdir) + shutil.copy2(os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/.libs/libconcord-6.dll', subdir) + shutil.copy2(os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/bindings/python/libconcord.py', subdir + '/__init__.py') + shutil.copy2(os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/bindings/python/setup.py', tempdir) + shutil.copy2(os.path.dirname(os.path.abspath(__file__)) + '/../../libconcord/bindings/python/pyproject.toml', tempdir) + + curdir = os.getcwd() + os.chdir(tempdir) + + os.environ["WIN32WHEEL"]="1" + subprocess.run([ 'python3', '-m', 'build', '-w' ]) + for file in glob.glob('dist/*.whl'): + print("Found wheel: " + file) + shutil.copy2(file, os.path.dirname(os.path.abspath(__file__))) + os.chdir(curdir) diff --git a/libconcord/bindings/python/libconcord.py b/libconcord/bindings/python/libconcord.py index e54644e..3259180 100644 --- a/libconcord/bindings/python/libconcord.py +++ b/libconcord/bindings/python/libconcord.py @@ -37,7 +37,8 @@ # Load the DLL if platform.system() == 'Windows': - _dll = cdll.LoadLibrary('libconcord.dll') + with os.add_dll_directory(os.path.dirname(__file__)): + _dll = cdll.LoadLibrary('libconcord-%i.dll' % ABI_VERSION) elif platform.system() == 'Darwin': _dll = cdll.LoadLibrary('libconcord.%i.dylib' % ABI_VERSION) else: diff --git a/libconcord/bindings/python/setup.py b/libconcord/bindings/python/setup.py index 9ded24d..468c388 100644 --- a/libconcord/bindings/python/setup.py +++ b/libconcord/bindings/python/setup.py @@ -18,10 +18,32 @@ # from setuptools import setup +import os -setup( - name='libconcord', - version='1.5', - py_modules=['libconcord'], -) +common_name='libconcord' +common_version='1.5' + +if os.environ.get("WIN32WHEEL", None) == "1": + #Win32 Wheel Option Set + setup( + name=common_name, + version=common_version, + packages=['libconcord'], + zip_safe=False, + package_data={ + '': ['*.dll'] + }, + options={ + "bdist_wheel": { + "plat_name": "win32", + }, + }, + ) +else: + #Default Option Set + setup( + name=common_name, + version=common_version, + py_modules=['libconcord'], + )