Skip to content

Commit d44b280

Browse files
committed
Build and test windows wheels
Closes aleaxit#468
1 parent 712b3f0 commit d44b280

6 files changed

+84
-11
lines changed

.github/workflows/build_wheels.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,39 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
os: [ubuntu-22.04, macos-12, macos-14]
11+
os: [ubuntu-22.04, macos-12, macos-14, windows-2022]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- if: runner.os == 'macOS'
1515
run: brew install pipx
16+
- uses: msys2/setup-msys2@v2
17+
name: Setup msys2
18+
with:
19+
install: >-
20+
mingw-w64-ucrt-x86_64-gcc
21+
autotools
22+
msystem: ucrt64
23+
path-type: inherit
24+
if: ${{ matrix.os == 'windows-2022' }}
1625
- name: Build wheels
1726
uses: pypa/[email protected]
1827
env:
1928
CIBW_PRERELEASE_PYTHONS: True
20-
CIBW_SKIP: pp*
21-
CIBW_BEFORE_BUILD: bash scripts/cibw_before_all.sh
29+
CIBW_SKIP: pp* *-win32
30+
CIBW_BEFORE_ALL: bash scripts/cibw_before_all.sh
31+
CIBW_BEFORE_ALL_WINDOWS: >
32+
msys2 -c scripts/cibw_before_all.sh &&
33+
scripts\cibw_before_all_windows.bat
34+
CIBW_BEFORE_BUILD_WINDOWS: pip install delvewheel
2235
CIBW_TEST_EXTRAS: tests
2336
CIBW_TEST_SKIP: cp38-macosx_arm64
2437
CIBW_TEST_COMMAND: >
2538
pytest {package}/test/ &&
2639
python {package}/test_cython/runtests.py
2740
CIBW_REPAIR_WHEEL_COMMAND: >
2841
bash scripts/cibw_repair_wheel_command.sh {dest_dir} {wheel}
42+
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: >
43+
scripts\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}
2944
- uses: actions/upload-artifact@v4
3045
with:
3146
name: wheels-${{ matrix.os }}

scripts/cibw_before_all_windows.bat

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo on
2+
cd .local\bin
3+
set "PATH=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.38.33130\bin\HostX86\x64\"
4+
call D:\a\gmpy\gmpy\scripts\dll2lib.bat 64 libgmp-10.dll
5+
call D:\a\gmpy\gmpy\scripts\dll2lib.bat 64 libmpfr-6.dll
6+
call D:\a\gmpy\gmpy\scripts\dll2lib.bat 64 libmpc-3.dll
7+
ren libgmp-10.lib gmp.lib
8+
ren libmpfr-6.lib mpfr.lib
9+
ren libmpc-3.lib mpc.lib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set WHEELHOUSE=%1
2+
set WHEELNAME=%2
3+
4+
msys2 -c scripts/cibw_repair_wheel_command_windows.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e -x
4+
5+
wheel=$WHEELNAME
6+
dest_dir=$WHEELHOUSE
7+
8+
delvewheel repair ${wheel} -w ${dest_dir} --add-path .local/bin --no-mangle-all
9+
10+
cp .local/bin/{gmp,mpfr,mpc}.lib ${dest_dir}
11+
(cd ${dest_dir}; wheel unpack --dest . gmpy2-*.whl; mv *.lib gmpy2-*/gmpy2.libs; wheel pack gmpy2-*[0-9]; rm -rf gmpy2-*[0-9])

scripts/dll2lib.bat

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
echo "dll2lib"
2+
@echo off
3+
4+
REM From https://github.com/GBillotey/Fractalshades/blob/master/win_build/dll2lib.bat
5+
6+
REM Usage: dll2lib [32|64] some-file.dll
7+
REM
8+
REM Generates some-file.lib from some-file.dll, making an intermediate
9+
REM some-file.def from the results of dumpbin /exports some-file.dll.
10+
REM
11+
REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt.
12+
REM
13+
REM Script inspired by http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll
14+
REM See also https://gist.github.com/Trass3r/8d0232a66b098530d07b0e48df6ad5ef
15+
16+
SETLOCAL
17+
if "%1"=="32" (set machine=x86) else (set machine=x64)
18+
cd %~p2
19+
set dll_file=%~f2
20+
set dll_file_no_ext=%~n2
21+
set exports_file=%dll_file_no_ext%-exports.txt
22+
set def_file=%dll_file_no_ext%.def
23+
set lib_file=%dll_file_no_ext%.lib
24+
set lib_name=%dll_file_no_ext%
25+
26+
dumpbin /exports %dll_file% > %exports_file%
27+
28+
echo LIBRARY %lib_name% > %def_file%
29+
echo EXPORTS >> %def_file%
30+
for /f "skip=19 tokens=1,4" %%A in (%exports_file%) do if NOT "%%B" == "" (echo %%B @%%A >> %def_file%)
31+
32+
lib /def:%def_file% /out:%lib_file% /machine:%machine%
33+
34+
REM Clean up temporary intermediate files
35+
del %exports_file% %def_file% %dll_file_no_ext%.exp

test_cython/setup_cython.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
library_dirs = sys.path + [gmpy2_packagedir]
1010
libnames = ['mpc','mpfr','gmp']
1111

12-
if platform.system() != 'Windows':
13-
bundled_libs = gmpy2_packagedir+'/../gmpy2.libs/'
14-
if os.path.isdir(bundled_libs):
15-
library_dirs += [bundled_libs]
16-
if platform.system() == 'Linux':
17-
libnames = [':' + d for d in os.listdir(bundled_libs)]
18-
else:
19-
libnames = [':' + bundled_libs + d for d in os.listdir(bundled_libs)]
12+
bundled_libs = os.path.join(gmpy2_packagedir, '..', 'gmpy2.libs')
13+
if os.path.isdir(bundled_libs):
14+
library_dirs += [bundled_libs]
15+
if platform.system() == 'Linux':
16+
libnames = [':' + d for d in os.listdir(bundled_libs)]
17+
elif platform.system() == 'Darwin':
18+
libnames = [':' + bundled_libs + d for d in os.listdir(bundled_libs)]
2019

2120

2221
extensions = [

0 commit comments

Comments
 (0)