Skip to content

Commit 70b3fde

Browse files
committed
maint: add CI jobs to build and test a Windows wheel
1 parent dc6151f commit 70b3fde

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

.github/workflows/buildwheel.yml

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

bin/build_mingw64_wheel.sh

+84
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

+1-1
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)