Skip to content

Commit 63be308

Browse files
Merge pull request #42 from oscarbenjamin/pr_macos_arm64
maint: build wheels for macos arm64 in Cirrus CI
2 parents e08d3df + 9946621 commit 63be308

7 files changed

+630
-3
lines changed

.cirrus.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#########################################################
2+
# Build arm64 wheels for OSX on Cirrus CI
3+
#########################################################
4+
5+
cirrus_wheels_macos_arm64_task:
6+
name: Build macOS arm64 wheels.
7+
macos_instance:
8+
image: ghcr.io/cirruslabs/macos-monterey-xcode:13.3.1
9+
env:
10+
PATH: /opt/homebrew/opt/[email protected]/bin:$PATH
11+
CIBW_ARCHS_MACOS: arm64
12+
install_pre_requirements_script:
13+
- brew install [email protected]
14+
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
15+
- which python
16+
- python --version
17+
install_cibuildwheel_script:
18+
- python -m pip install cibuildwheel==2.11.4
19+
run_cibuildwheel_script:
20+
- bin/cibw.sh
21+
wheels_artifacts:
22+
path: "wheelhouse/*"

.github/workflows/buildwheel.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
4141
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
4242
CIBW_BEFORE_ALL_LINUX: bin/cibw_before_all_linux.sh
43-
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx.sh
43+
CIBW_BEFORE_ALL_MACOS: bin/cibw_before_all_macosx_x86_64.sh
4444
CIBW_BEFORE_ALL_WINDOWS: msys2 -c bin/cibw_before_all_windows.sh
4545
CIBW_BEFORE_BUILD_WINDOWS: msys2 -c bin/cibw_before_build_windows.sh
4646
CIBW_BEFORE_BUILD: pip install numpy cython delvewheel

bin/build_dependencies_unix.sh

+42-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ set -o errexit
99
# #
1010
# Supported options: #
1111
# #
12-
# --gmp gmp - build based on GMP (default) #
13-
# --gmp mpir - build based on MPIR (instead of GMP) #
12+
# --gmp gmp - build based on GMP (default) #
13+
# --gmp mpir - build based on MPIR (no longer works) #
14+
# --host <HOST> - set the host (target) for GMP build #
15+
# --patch-gmp-arm64 - apply patch to GMP for OSX arm64 #
1416
# #
1517
# ------------------------------------------------------------------------- #
1618

1719
USE_GMP=gmp
20+
PATCH_GMP_ARM64=no
1821

1922
while [[ $# -gt 0 ]]
2023
do
@@ -41,6 +44,14 @@ do
4144
shift
4245
shift
4346
;;
47+
--patch-gmp-arm64)
48+
PATCH_GMP_ARM64=yes
49+
shift
50+
;;
51+
*)
52+
2>&1 echo "unrecognised argument:" $key
53+
exit 1
54+
;;
4455
esac
4556
done
4657

@@ -74,6 +85,23 @@ if [ $USE_GMP = "gmp" ]; then
7485
curl -O https://gmplib.org/download/gmp/gmp-$GMPVER.tar.xz
7586
tar xf gmp-$GMPVER.tar.xz
7687
cd gmp-$GMPVER
88+
89+
#
90+
# See https://github.com/aleaxit/gmpy/issues/350
91+
#
92+
# We need to patch GMP for OSX arm64 (Apple M1) hardware. This patch is
93+
# from the GMP repo but was applied after the release of GMP 6.2.1.
94+
# Hopefully when a newer version of GMP is released we will not need to
95+
# apply this patch any more.
96+
#
97+
if [ $PATCH_GMP_ARM64 = "yes" ]; then
98+
echo
99+
echo --------------------------------------------
100+
echo " patching GMP"
101+
echo --------------------------------------------
102+
patch -N -Z -p0 < ../../../bin/patch-arm64.diff
103+
fi
104+
77105
# Show the output of configfsf.guess
78106
./configfsf.guess
79107
./configure --prefix=$PREFIX\
@@ -109,6 +137,18 @@ else
109137
# #
110138
# ----------------------------------------------------------------------- #
111139

140+
#
141+
# The mpir.org domain has expired and no longer hosts the source code so the
142+
# call to curl below will fail.
143+
# We could try to download from https://github.com/wbhart/mpir/releases.
144+
#
145+
# Ultimately it seems that MPIR is no longer maintained though so for now
146+
# this remains unfixed.
147+
#
148+
149+
>&2 echo "MPIR build of python_flint is no longer supported"
150+
exit 1
151+
112152
curl -O http://mpir.org/mpir-$MPIRVER.tar.bz2
113153
tar xf mpir-$MPIRVER.tar.bz2
114154
cd mpir-$MPIRVER

bin/cibw.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This script can be used to test cibuildwheel locally on OSX/Linux
4+
#
5+
# It is also worth commenting out the BEFORE_ALL line to build GMP etc after you have
6+
# built those once because that is by far the slowest step.
7+
#
8+
9+
rm -f wheelhouse/*
10+
11+
# bin/build_dependencies_unix.sh places headers and shared libraries under .local
12+
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'
13+
14+
export CIBW_BUILD='cp39-* cp310-* cp311-*'
15+
# export CIBW_BUILD='cp311-*'
16+
export CIBW_SKIP='*-win32 *-manylinux_i686 *-musllinux_*'
17+
18+
# export CIBW_ARCHS_MACOS="x86_64"
19+
export CIBW_ARCHS_MACOS="arm64"
20+
21+
export CIBW_BEFORE_ALL_LINUX=bin/cibw_before_all_linux.sh
22+
# export CIBW_BEFORE_ALL_MACOS=bin/cibw_before_all_macosx_x86_64.sh
23+
export CIBW_BEFORE_ALL_MACOS=bin/cibw_before_all_macosx_arm64.sh
24+
export CIBW_BEFORE_ALL_WINDOWS='C:\\msys64\\usr\\bin\\bash bin/cibw_before_all_windows.sh'
25+
26+
export CIBW_BEFORE_BUILD='pip install numpy cython delvewheel'
27+
export CIBW_BEFORE_BUILD_WINDOWS='C:\\msys64\\usr\\bin\\bash bin/cibw_before_build_windows.sh'
28+
29+
export CIBW_REPAIR_WHEEL_COMMAND_WINDOWS='bin\cibw_repair_wheel_command_windows.bat {dest_dir} {wheel}'
30+
31+
# export CIBW_TEST_COMMAND="python -c 'import flint; print(str(flint.fmpz(2)))'"
32+
export CIBW_TEST_COMMAND="python {project}/test/test.py && python {project}/test/dtest.py"
33+
34+
# cibuildwheel --platform linux
35+
# cibuildwheel --platform windows
36+
cibuildwheel --platform macos

bin/cibw_before_all_macosx_arm64.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
export CPPFLAGS=" --target=arm64-apple-macos11"
4+
export LDFLAGS=" -arch arm64"
5+
6+
bin/build_dependencies_unix.sh\
7+
--gmp gmp\
8+
--host aarch64-apple-darwin\
9+
--patch-gmp-arm64
File renamed without changes.

0 commit comments

Comments
 (0)