-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maint: build+test wheels for Windows in CI
1 parent
edf6be7
commit 8000775
Showing
9 changed files
with
305 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ __pycache__ | |
MANIFEST | ||
.eggs | ||
.local | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/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)` | ||
# PYTHONVER=3.10 | ||
# | ||
# - 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 | ||
VER="${PYTHONVER//./}" | ||
|
||
WHEELNAME=python_flint-0.3.0-cp$VER-cp$VER-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 ~30mins | ||
#bin/build_dependencies_unix.sh | ||
|
||
# Add the libpython$VER.a file to Python installation | ||
cd $PYTHONDIR | ||
gendef python$VER.dll | ||
dlltool --dllname python$VER.dll --def python$VER.def --output-lib libpython$VER.a | ||
mv libpython$VER.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 psutil | ||
|
||
# Pass this flag to setup.py | ||
export PYTHON_FLINT_MINGW64_TMP=true | ||
|
||
# Build the wheel | ||
C_INCLUDE_PATH=.local/include/ LIBRARY_PATH=.local/lib/ python setup.py build_ext -cmingw32 -f bdist_wheel | ||
|
||
# delvewheel requires DLLs created by mingw64 to be stripped | ||
# | ||
# https://github.com/scipy/scipy/blob/main/tools/wheels/repair_windows.sh | ||
strip .local/bin/*.dll .local/lib/*.dll | ||
|
||
# Unpack the wheel and strip the .pyd DLL inside | ||
cd dist | ||
wheel unpack $WHEELNAME | ||
rm $WHEELNAME | ||
strip python_flint-*/flint/*.pyd | ||
wheel pack python_flint-* | ||
cd .. | ||
|
||
# Make the wheel relocatable | ||
delvewheel repair dist/python_flint-0.3.0-cp$VER-cp$VER-win_amd64.whl \ | ||
--add-path .local/bin:.local/lib/ | ||
|
||
# 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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
rem | ||
rem This bat file can be used to test cibuildwheel locally on Windows. The | ||
rem cibw_*_windows.sh files have lines to set the PATH for working locally but | ||
rem those are commented out because they are not needed in CI. To use this | ||
rem script | ||
rem | ||
rem 1. Uncomment those lines | ||
rem 2. > pip install cibuildwheel | ||
rem 3. > bin\cibw.bat | ||
rem | ||
rem The variables defined below should match those that are set in CI except | ||
rem that C:\msys64\usr\bin\bash should just be msys2 -c in CI. | ||
rem | ||
rem It is also worth commenting out the line to build GMP etc after you have | ||
rem built those once because that is by far the slowest step. | ||
rem | ||
|
||
rem | ||
rem If this script is run repeatedly then it would fail because of any leftover | ||
rem wheels from a previous run so we delete them here. | ||
rem | ||
del /q wheelhouse\* | ||
|
||
set CIBW_BUILD=cp39-* cp310-* cp311-* | ||
set CIBW_SKIP=*-win32 *-manylinux_i686 *-musllinux_* | ||
set CIBW_BEFORE_ALL_WINDOWS=C:\msys64\usr\bin\bash bin/cibw_before_build_windows.sh | ||
set CIBW_BEFORE_BUILD_WINDOWS=C:\msys64\usr\bin\bash bin/cibw_prepare_python_windows.sh | ||
set CIBW_ENVIRONMENT=PYTHON_FLINT_MINGW64=true | ||
set CIBW_REPAIR_WHEEL_COMMAND_WINDOWS=bin\repair_mingw_wheel.bat {dest_dir} {wheel} | ||
set CIBW_TEST_COMMAND=python -c "import flint; print(str(flint.fmpz(2)))" | ||
|
||
cibuildwheel --platform windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
|
||
# Uncomment this to run cibuildwheel locally on Windows: | ||
# export PATH=$PATH:/c/msys64/usr/bin:/c/msys64/mingw64/bin | ||
|
||
# | ||
# Make a setup.cfg to specify compiling with mingw64 (even though it says | ||
# mingw32...) | ||
# | ||
echo '[build]' > setup.cfg | ||
echo 'compiler = mingw32' >> setup.cfg | ||
cat setup.cfg | ||
|
||
# Install the mingw-w64 toolchain | ||
pacman -S --noconfirm mingw-w64-x86_64-gcc m4 make mingw-w64-x86_64-tools-git | ||
|
||
# This takes ~30mins | ||
bin/build_dependencies_unix.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
|
||
# Uncomment this to run cibuildwheel locally on Windows: | ||
# export PATH=$PATH:/c/msys64/usr/bin:/c/msys64/mingw64/bin | ||
|
||
# VER should be set be e.g. 310 for Python 3.10 | ||
VER=`python -c 'import sys; print("%s%s" % sys.version_info[:2])'` | ||
echo VER=${VER} | ||
|
||
################################################### | ||
# Find parent Python installation from the venv # | ||
################################################### | ||
|
||
which python | ||
PYTHONBIN=`dirname $(which python)` | ||
PYTHONDIR=`dirname $PYTHONBIN` | ||
cfgfile=$PYTHONDIR/pyvenv.cfg | ||
homeline=`grep home $cfgfile` | ||
homepath=${homeline#*=} | ||
|
||
echo --------------------------------------------------- | ||
echo $homepath | ||
echo --------------------------------------------------- | ||
|
||
################################################### | ||
# Find pythonXX.dll and make a .a library # | ||
################################################### | ||
|
||
cd $homepath | ||
gendef python${VER}.dll | ||
dlltool --dllname python${VER}.dll \ | ||
--def python${VER}.def \ | ||
--output-lib libpython${VER}.a | ||
|
||
mv libpython${VER}.a libs | ||
|
||
################################################### | ||
# Install build dependencies # | ||
################################################### | ||
|
||
pip install Cython numpy delvewheel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
rem | ||
rem This batch file serves the purpose of taking Windows style path arguments, | ||
rem converting them to environment variables and calling msys2. This is needed | ||
rem because otherwise in CI msys2 -c will mangle the paths turning e.g. C:\a\b | ||
rem into C:ab. | ||
rem | ||
|
||
set tempfile=tmpfile.deleteme | ||
set WHEELHOUSE=%1 | ||
set WHEELNAME=%2 | ||
|
||
msys2 -c bin/repair_mingw_wheel.sh | ||
rem C:\msys64\usr\bin\bash bin/repair_mingw_wheel.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# | ||
# Repair Windows wheels. See e.g.: | ||
# | ||
# https://github.com/scipy/scipy/blob/main/tools/wheels/repair_windows.sh | ||
|
||
set -o errexit | ||
|
||
# Uncomment this to run cibuildwheel locally on Windows: | ||
# export PATH=$PATH:/c/msys64/usr/bin:/c/msys64/mingw64/bin | ||
|
||
# We cannot use ordinary command line arguments in CI because msys2 -c mangles | ||
# them. Instead we have a batch file to receive the arguments and convert them | ||
# into environment variables before calling this script. When running locally | ||
# this script could be run directly giving the parameters as command line | ||
# arguments instead. | ||
|
||
if [[ -z "${WHEELHOUSE}" ]]; then | ||
WHEELNAME=$1 | ||
fi | ||
if [[ -z "${WHEELNAME}" ]]; then | ||
WHEELHOUSE=$2 | ||
fi | ||
|
||
echo WHEELHOUSE=$WHEELHOUSE | ||
echo WHEELNAME=$WHEELNAME | ||
|
||
wheeldir=$(dirname $WHEELNAME) | ||
echo $wheeldir | ||
|
||
# delvewheel requires DLLs created by mingw64 to be stripped. This strips the | ||
# DLLs for GMP etc that will have been build previously. | ||
strip .local/bin/*.dll .local/lib/*.dll | ||
|
||
# Make sure to leave the wheel in the same directory | ||
wheeldir=$(dirname $WHEELNAME) | ||
pushd $wheeldir | ||
# Unpack the wheel and strip any .pyd DLLs inside | ||
wheel unpack $WHEELNAME | ||
rm $WHEELNAME | ||
strip python_flint-*/flint/*.pyd | ||
wheel pack python_flint-* | ||
popd | ||
|
||
# Make the wheel relocatable. This will fail with an error message about | ||
# --no-mangle if strip has not been applied to all mingw64-created .dll and | ||
# .pyd files that are needed for the wheel. | ||
delvewheel repair $WHEELNAME \ | ||
-w $WHEELHOUSE \ | ||
--add-path .local/bin:.local/lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters