|
| 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? |
0 commit comments