Skip to content

maint: build wheels for macos arm64 in Cirrus CI #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#########################################################
# Build arm64 wheels for OSX on Cirrus CI
#########################################################

cirrus_wheels_macos_arm64_task:
name: Build macOS arm64 wheels.
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-xcode:13.3.1
env:
PATH: /opt/homebrew/opt/[email protected]/bin:$PATH
CIBW_ARCHS_MACOS: arm64
install_pre_requirements_script:
- brew install [email protected]
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
- which python
- python --version
install_cibuildwheel_script:
- python -m pip install cibuildwheel==2.11.4
run_cibuildwheel_script:
- bin/cibw.sh
wheels_artifacts:
path: "wheelhouse/*"
2 changes: 1 addition & 1 deletion .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
CIBW_BEFORE_ALL_LINUX: bin/cibw_before_all_linux.sh
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx.sh
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh
CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh
CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh
CIBW_BEFORE_BUILD: pip install numpy cython delvewheel
Expand Down
44 changes: 42 additions & 2 deletions bin/build_dependencies_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ set -o errexit
# #
# Supported options: #
# #
# --gmp gmp - build based on GMP (default) #
# --gmp mpir - build based on MPIR (instead of GMP) #
# --gmp gmp - build based on GMP (default) #
# --gmp mpir - build based on MPIR (no longer works) #
# --host <HOST> - set the host (target) for GMP build #
# --patch-gmp-arm64 - apply patch to GMP for OSX arm64 #
# #
# ------------------------------------------------------------------------- #

USE_GMP=gmp
PATCH_GMP_ARM64=no

while [[ $# -gt 0 ]]
do
Expand All @@ -41,6 +44,14 @@ do
shift
shift
;;
--patch-gmp-arm64)
PATCH_GMP_ARM64=yes
shift
;;
*)
2>&1 echo "unrecognised argument:" $key
exit 1
;;
esac
done

Expand Down Expand Up @@ -74,6 +85,23 @@ if [ $USE_GMP = "gmp" ]; then
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
tar xf gmp-$GMPVER.tar.xz
cd gmp-$GMPVER

#
# See https://github.com/aleaxit/gmpy/issues/350
#
# We need to patch GMP for OSX arm64 (Apple M1) hardware. This patch is
# from the GMP repo but was applied after the release of GMP 6.2.1.
# Hopefully when a newer version of GMP is released we will not need to
# apply this patch any more.
#
if [ $PATCH_GMP_ARM64 = "yes" ]; then
echo
echo --------------------------------------------
echo " patching GMP"
echo --------------------------------------------
patch -N -Z -p0 < ../../../bin/patch-arm64.diff
fi

# Show the output of configfsf.guess
./configfsf.guess
./configure --prefix=$PREFIX\
Expand Down Expand Up @@ -109,6 +137,18 @@ else
# #
# ----------------------------------------------------------------------- #

#
# The mpir.org domain has expired and no longer hosts the source code so the
# call to curl below will fail.
# We could try to download from https://github.com/wbhart/mpir/releases.
#
# Ultimately it seems that MPIR is no longer maintained though so for now
# this remains unfixed.
#

>&2 echo "MPIR build of python_flint is no longer supported"
exit 1

curl -O http://mpir.org/mpir-$MPIRVER.tar.bz2
tar xf mpir-$MPIRVER.tar.bz2
cd mpir-$MPIRVER
Expand Down
36 changes: 36 additions & 0 deletions bin/cibw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# This script can be used to test cibuildwheel locally on OSX/Linux
#
# It is also worth commenting out the BEFORE_ALL line to build GMP etc after you have
# built those once because that is by far the slowest step.
#

rm -f wheelhouse/*

# bin/build_dependencies_unix.sh places headers and shared libraries under .local
export CIBW_ENVIRONMENT='C_INCLUDE_PATH=$(pwd)/.local/include/ LIBRARY_PATH=$(pwd)/.local/lib/ LD_LIBRARY_PATH=$(pwd)/.local/lib:$LD_LIBRARY_PATH PYTHON_FLINT_MINGW64=true'

export CIBW_BUILD='cp39-* cp310-* cp311-*'
# export CIBW_BUILD='cp311-*'
export CIBW_SKIP='*-win32 *-manylinux_i686 *-musllinux_*'

# export CIBW_ARCHS_MACOS="x86_64"
export CIBW_ARCHS_MACOS="arm64"

export CIBW_BEFORE_ALL_LINUX=bin/cibw_before_all_linux.sh
# export CIBW_BEFORE_ALL_MACOS=bin/cibw_before_all_macosx_x86_64.sh
export CIBW_BEFORE_ALL_MACOS=bin/cibw_before_all_macosx_arm64.sh
export CIBW_BEFORE_ALL_WINDOWS='C:\\msys64\\usr\\bin\\bash bin/cibw_before_all_windows.sh'

export CIBW_BEFORE_BUILD='pip install numpy cython delvewheel'
export CIBW_BEFORE_BUILD_WINDOWS='C:\\msys64\\usr\\bin\\bash bin/cibw_before_build_windows.sh'

export CIBW_REPAIR_WHEEL_COMMAND_WINDOWS='bin\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}'

# export CIBW_TEST_COMMAND="python -c 'import flint; print(str(flint.fmpz(2)))'"
export CIBW_TEST_COMMAND="python {project}/test/test.py && python {project}/test/dtest.py"

# cibuildwheel --platform linux
# cibuildwheel --platform windows
cibuildwheel --platform macos
9 changes: 9 additions & 0 deletions bin/cibw_before_all_macosx_arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

export CPPFLAGS=" --target=arm64-apple-macos11"
export LDFLAGS=" -arch arm64"

bin/build_dependencies_unix.sh\
--gmp gmp\
--host aarch64-apple-darwin\
--patch-gmp-arm64
File renamed without changes.
Loading