Skip to content

Commit

Permalink
maint: add CI jobs to build and test a Windows wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbenjamin committed Dec 6, 2022
1 parent 4f73923 commit dfa430a
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 1 deletion.
55 changes: 55 additions & 0 deletions .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,58 @@ jobs:
- run: venv/bin/pip install -U pip
- run: venv/bin/pip install --find-links wheelhouse python_flint
- run: venv/bin/python test/test.py

build_windows:
#
# Test experimental Windows support. These wheels do not yet work due to
#
# https://github.com/fredrik-johansson/python-flint/issues/10
#
# This job tests that building the wheel is possible with mingw-w64 under msys2.
#
name: Build Windows wheel
runs-on: windows-2019

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: msys2/setup-msys2@v2
with:
msystem: mingw64

- run: python -c 'import sys; print(sys.executable)'

- run: msys2 -c 'uname -a'

- run: msys2 -c 'bin/build_mingw64_wheel.sh'
env:
# This is where setup-python puts Python. We want the MSVC-built
# Python rather than an MSYS2 Python.
PYTHONDIR: '/c/hostedtoolcache/windows/Python/3.10.8/x64'

- uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl

test_windows:
#
# For now this job is expected to fail.
#
needs: build_windows
name: Test Windows wheel
runs-on: windows-2019

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: actions/download-artifact@v3
with:
name: artifact
path: wheelhouse
- run: python -m pip install -U pip
- run: pip install --find-links wheelhouse python_flint
- run: python test/test.py
84 changes: 84 additions & 0 deletions bin/build_mingw64_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash
#
# make_wheels.sh
#
# Build relocatable Windows wheel for python_flint using the mingw-w64
# toolchain in the MSYS2 enironment.
#
# - First install Python
#
# https://www.python.org/ftp/python/3.10.8/python-3.10.8-amd64.exe
#
# - Then checkout the code:
#
# $ git clone https://github.com/fredrik-johansson/python-flint/issues/1
#
# - Then install msys2
#
# https://repo.msys2.org/distrib/x86_64/msys2-x86_64-20221028.exe
#
# - Then open msys2, cd into the checked out repo. Make sure setup.py says
#
# libraries = ["arb", "flint", "mpfr", "gmp"]
#
# - Set the environment variable to the directory containing the installed
# Python that we want to build a wheel for i.e. the one installed from
# python.org. If python was on PATH then it would be
#
# PYTHONDIR=`dirname $(which python)`
#
# - Then run this script.

set -o errexit

#
# In CI this environment variable needs to be set to the directory containing
# the python.org installation of Python. If Python is installed in msys2 then
# it is also necesary to set this environment variable so that it picks up the
# right installation of Python i.e. the one that we want to build a wheel for.
#
if [[ -z "$PYTHONDIR" ]]; then
PYTHONDIR=`dirname $(which python)`
fi
PYTHON=$PYTHONDIR/python

WHEELNAME=python_flint-0.3.0-cp310-cp310-win_amd64.whl

$PYTHON -c 'print("hello world")'

echo $PYTHONDIR
ls $PYTHONDIR
ls $PYTHONDIR/libs

# Install the mingw-w64 toolchain
pacman -S --noconfirm mingw-w64-x86_64-gcc m4 make mingw-w64-x86_64-tools-git

# This takes ~1hr
bin/build_dependencies_unix.sh

# Add the libpython310.a file to Python installation
cd $PYTHONDIR
gendef python310.dll
dlltool --dllname python310.dll --def python310.def --output-lib libpython310.a
mv libpython310.a libs
cd -

# Make a virtual environment to install the build dependencies
$PYTHON -m venv .local/venv
source .local/venv/Scripts/activate
pip install numpy cython wheel delvewheel

# Build the wheel
C_INCLUDE_PATH=.local/include/ LIBRARY_PATH=.local/lib/ python setup.py build_ext -cmingw32 -f bdist_wheel

# Make the wheel relocatable
delvewheel repair dist/python_flint-0.3.0-cp310-cp310-win_amd64.whl \
--add-path .local/bin:.local/lib/ \
'--no-mangle=libflint-17.dll;libarb-2.dll;libgmp-10.dll;libmpfr-6.dll;libgcc_s_seh-1.dll'

# Make a virtual enironment to test the wheel
#
# $PYTHON -m venv test_env
# source test_env/Scripts/activate
# pip install wheelhouse/$WHEELNAME
# python -c 'import flint; print(flint.fmpz(2) + 2)' # 2 + 2 = 4?
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from distutils.sysconfig import get_config_vars

if sys.platform == 'win32':
libraries = ["arb", "flint", "mpir", "mpfr", "pthreads"]
libraries = ["arb", "flint", "mpfr", "gmp"]
else:
libraries = ["arb", "flint"]
(opt,) = get_config_vars('OPT')
Expand Down

0 comments on commit dfa430a

Please sign in to comment.