|
| 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 | +# PYTHONVER=3.10 |
| 30 | +# |
| 31 | +# - Then run this script. |
| 32 | + |
| 33 | +set -o errexit |
| 34 | + |
| 35 | +# |
| 36 | +# In CI this environment variable needs to be set to the directory containing |
| 37 | +# the python.org installation of Python. If Python is installed in msys2 then |
| 38 | +# it is also necesary to set this environment variable so that it picks up the |
| 39 | +# right installation of Python i.e. the one that we want to build a wheel for. |
| 40 | +# |
| 41 | +if [[ -z "$PYTHONDIR" ]]; then |
| 42 | + PYTHONDIR=`dirname $(which python)` |
| 43 | +fi |
| 44 | +PYTHON=$PYTHONDIR/python |
| 45 | +VER="${PYTHONVER//./}" |
| 46 | + |
| 47 | +WHEELNAME=python_flint-0.3.0-cp$VER-cp$VER-win_amd64.whl |
| 48 | + |
| 49 | +$PYTHON -c 'print("hello world")' |
| 50 | + |
| 51 | +echo $PYTHONDIR |
| 52 | +ls $PYTHONDIR |
| 53 | +ls $PYTHONDIR/libs |
| 54 | + |
| 55 | +# Install the mingw-w64 toolchain |
| 56 | +pacman -S --noconfirm mingw-w64-x86_64-gcc m4 make mingw-w64-x86_64-tools-git |
| 57 | + |
| 58 | +# This takes ~30mins |
| 59 | +#bin/build_dependencies_unix.sh |
| 60 | + |
| 61 | +# Add the libpython$VER.a file to Python installation |
| 62 | +cd $PYTHONDIR |
| 63 | + gendef python$VER.dll |
| 64 | + dlltool --dllname python$VER.dll --def python$VER.def --output-lib libpython$VER.a |
| 65 | + mv libpython$VER.a libs |
| 66 | +cd - |
| 67 | + |
| 68 | +# Make a virtual environment to install the build dependencies |
| 69 | +$PYTHON -m venv .local/venv |
| 70 | +source .local/venv/Scripts/activate |
| 71 | +pip install numpy cython wheel delvewheel psutil |
| 72 | + |
| 73 | +# Pass this flag to setup.py |
| 74 | +export PYTHON_FLINT_MINGW64_TMP=true |
| 75 | + |
| 76 | +# Build the wheel |
| 77 | +C_INCLUDE_PATH=.local/include/ LIBRARY_PATH=.local/lib/ python setup.py build_ext -cmingw32 -f bdist_wheel |
| 78 | + |
| 79 | +# delvewheel requires DLLs created by mingw64 to be stripped |
| 80 | +# |
| 81 | +# https://github.com/scipy/scipy/blob/main/tools/wheels/repair_windows.sh |
| 82 | +strip .local/bin/*.dll .local/lib/*.dll |
| 83 | + |
| 84 | +# Unpack the wheel and strip the .pyd DLL inside |
| 85 | +cd dist |
| 86 | +wheel unpack $WHEELNAME |
| 87 | +rm $WHEELNAME |
| 88 | +strip python_flint-*/flint/*.pyd |
| 89 | +wheel pack python_flint-* |
| 90 | +cd .. |
| 91 | + |
| 92 | +# Make the wheel relocatable |
| 93 | +delvewheel repair dist/python_flint-0.3.0-cp$VER-cp$VER-win_amd64.whl \ |
| 94 | + --add-path .local/bin:.local/lib/ |
| 95 | + |
| 96 | +# Make a virtual enironment to test the wheel |
| 97 | +$PYTHON -m venv test_env |
| 98 | +source test_env/Scripts/activate |
| 99 | +pip install wheelhouse/$WHEELNAME |
| 100 | +python -c 'import flint; print(flint.fmpz(2) + 2)' # 2 + 2 = 4? |
0 commit comments