Skip to content

Commit dfa430a

Browse files
committed
maint: add CI jobs to build and test a Windows wheel
1 parent 4f73923 commit dfa430a

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

.github/workflows/buildwheel.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,58 @@ jobs:
6363
- run: venv/bin/pip install -U pip
6464
- run: venv/bin/pip install --find-links wheelhouse python_flint
6565
- run: venv/bin/python test/test.py
66+
67+
build_windows:
68+
#
69+
# Test experimental Windows support. These wheels do not yet work due to
70+
#
71+
# https://github.com/fredrik-johansson/python-flint/issues/10
72+
#
73+
# This job tests that building the wheel is possible with mingw-w64 under msys2.
74+
#
75+
name: Build Windows wheel
76+
runs-on: windows-2019
77+
78+
steps:
79+
- uses: actions/checkout@v3
80+
- uses: actions/setup-python@v4
81+
with:
82+
python-version: '3.10'
83+
- uses: msys2/setup-msys2@v2
84+
with:
85+
msystem: mingw64
86+
87+
- run: python -c 'import sys; print(sys.executable)'
88+
89+
- run: msys2 -c 'uname -a'
90+
91+
- run: msys2 -c 'bin/build_mingw64_wheel.sh'
92+
env:
93+
# This is where setup-python puts Python. We want the MSVC-built
94+
# Python rather than an MSYS2 Python.
95+
PYTHONDIR: '/c/hostedtoolcache/windows/Python/3.10.8/x64'
96+
97+
- uses: actions/upload-artifact@v3
98+
with:
99+
path: wheelhouse/*.whl
100+
101+
test_windows:
102+
#
103+
# For now this job is expected to fail.
104+
#
105+
needs: build_windows
106+
name: Test Windows wheel
107+
runs-on: windows-2019
108+
109+
steps:
110+
- uses: actions/checkout@v3
111+
- uses: actions/setup-python@v4
112+
with:
113+
python-version: '3.10'
114+
- uses: actions/download-artifact@v3
115+
with:
116+
name: artifact
117+
path: wheelhouse
118+
- run: python -m pip install -U pip
119+
- run: pip install --find-links wheelhouse python_flint
120+
- run: python test/test.py

bin/build_mingw64_wheel.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
#
3+
# make_wheels.sh
4+
#
5+
# Build relocatable Windows wheel for python_flint using the mingw-w64
6+
# toolchain in the MSYS2 enironment.
7+
#
8+
# - First install Python
9+
#
10+
# https://www.python.org/ftp/python/3.10.8/python-3.10.8-amd64.exe
11+
#
12+
# - Then checkout the code:
13+
#
14+
# $ git clone https://github.com/fredrik-johansson/python-flint/issues/1
15+
#
16+
# - Then install msys2
17+
#
18+
# https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20221028.exe
19+
#
20+
# - Then open msys2, cd into the checked out repo. Make sure setup.py says
21+
#
22+
# libraries = ["arb", "flint", "mpfr", "gmp"]
23+
#
24+
# - Set the environment variable to the directory containing the installed
25+
# Python that we want to build a wheel for i.e. the one installed from
26+
# python.org. If python was on PATH then it would be
27+
#
28+
# PYTHONDIR=`dirname $(which python)`
29+
#
30+
# - Then run this script.
31+
32+
set -o errexit
33+
34+
#
35+
# In CI this environment variable needs to be set to the directory containing
36+
# the python.org installation of Python. If Python is installed in msys2 then
37+
# it is also necesary to set this environment variable so that it picks up the
38+
# right installation of Python i.e. the one that we want to build a wheel for.
39+
#
40+
if [[ -z "$PYTHONDIR" ]]; then
41+
PYTHONDIR=`dirname $(which python)`
42+
fi
43+
PYTHON=$PYTHONDIR/python
44+
45+
WHEELNAME=python_flint-0.3.0-cp310-cp310-win_amd64.whl
46+
47+
$PYTHON -c 'print("hello world")'
48+
49+
echo $PYTHONDIR
50+
ls $PYTHONDIR
51+
ls $PYTHONDIR/libs
52+
53+
# Install the mingw-w64 toolchain
54+
pacman -S --noconfirm mingw-w64-x86_64-gcc m4 make mingw-w64-x86_64-tools-git
55+
56+
# This takes ~1hr
57+
bin/build_dependencies_unix.sh
58+
59+
# Add the libpython310.a file to Python installation
60+
cd $PYTHONDIR
61+
gendef python310.dll
62+
dlltool --dllname python310.dll --def python310.def --output-lib libpython310.a
63+
mv libpython310.a libs
64+
cd -
65+
66+
# Make a virtual environment to install the build dependencies
67+
$PYTHON -m venv .local/venv
68+
source .local/venv/Scripts/activate
69+
pip install numpy cython wheel delvewheel
70+
71+
# Build the wheel
72+
C_INCLUDE_PATH=.local/include/ LIBRARY_PATH=.local/lib/ python setup.py build_ext -cmingw32 -f bdist_wheel
73+
74+
# Make the wheel relocatable
75+
delvewheel repair dist/python_flint-0.3.0-cp310-cp310-win_amd64.whl \
76+
--add-path .local/bin:.local/lib/ \
77+
'--no-mangle=libflint-17.dll;libarb-2.dll;libgmp-10.dll;libmpfr-6.dll;libgcc_s_seh-1.dll'
78+
79+
# Make a virtual enironment to test the wheel
80+
#
81+
# $PYTHON -m venv test_env
82+
# source test_env/Scripts/activate
83+
# pip install wheelhouse/$WHEELNAME
84+
# python -c 'import flint; print(flint.fmpz(2) + 2)' # 2 + 2 = 4?

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from distutils.sysconfig import get_config_vars
1010

1111
if sys.platform == 'win32':
12-
libraries = ["arb", "flint", "mpir", "mpfr", "pthreads"]
12+
libraries = ["arb", "flint", "mpfr", "gmp"]
1313
else:
1414
libraries = ["arb", "flint"]
1515
(opt,) = get_config_vars('OPT')

0 commit comments

Comments
 (0)