Skip to content

Commit fe0357c

Browse files
authored
Merge pull request #8 from andyfaff/macwheel
CI: macosx_arm64 natively on cirrus
2 parents 8a32e35 + 8462739 commit fe0357c

File tree

7 files changed

+118
-13
lines changed

7 files changed

+118
-13
lines changed

.cirrus.star

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def main(ctx):
1616
if env.get("CIRRUS_REPO_FULL_NAME") != "numpy/numpy":
1717
return []
1818

19-
# if env.get("CIRRUS_CRON", "") == "nightly":
20-
# return fs.read("ci/cirrus_wheels.yml")
19+
# only run the wheels entry on a cron job
20+
if env.get("CIRRUS_CRON", "") == "nightly":
21+
return fs.read("tool/ci/cirrus_wheels.yml")
2122

2223
# Obtain commit message for the event. Unfortunately CIRRUS_CHANGE_MESSAGE
2324
# only contains the actual commit message on a non-PR trigger event.
@@ -31,8 +32,8 @@ def main(ctx):
3132
if "[skip cirrus]" in dct["message"] or "[skip ci]" in dct["message"]:
3233
return []
3334

34-
config = fs.read("tools/ci/cirrus_general.yml")
35-
3635
# add extra jobs to the cirrus run by += adding to config
36+
config = fs.read("tools/ci/cirrus_wheels.yml")
37+
config += fs.read("tools/ci/cirrus_macosx_arm64.yml")
3738

3839
return config

.github/workflows/wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
buildplat:
7777
- [ubuntu-20.04, manylinux_x86_64]
7878
- [ubuntu-20.04, musllinux_x86_64]
79-
- [macos-12, macosx_*]
79+
- [macos-12, macosx_x86_64]
8080
- [windows-2019, win_amd64]
8181
- [windows-2019, win32]
8282
python: ["cp39", "cp310", "cp311", "pp39"]

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ environment = { CFLAGS="-std=c99 -fno-strict-aliasing", LDFLAGS="-Wl,--strip-deb
163163
# https://github.com/multi-build/multibuild/blame/devel/README.rst#L541-L565
164164
# for more info
165165
archs = "x86_64 arm64"
166-
test-skip = "*_arm64 *_universal2:arm64"
166+
test-skip = "*_universal2:arm64"
167167
# MACOS linker doesn't support stripping symbols
168-
environment = { CFLAGS="-std=c99 -fno-strict-aliasing", OPENBLAS64_="/usr/local", NPY_USE_BLAS_ILP64="1", CC="clang", CXX = "clang++" }
168+
environment = { CFLAGS="-std=c99 -fno-strict-aliasing", OPENBLAS64_="/usr/local", NPY_USE_BLAS_ILP64="1", CC="clang", CXX = "clang++", RUNNER_OS="macOS" }
169169

170170
[tool.cibuildwheel.windows]
171171
environment = { OPENBLAS64_="openblas", OPENBLAS="", NPY_USE_BLAS_ILP64="1", CFLAGS="", LDFLAGS="" }

tools/ci/cirrus_macosx_arm64.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
modified_clone: &MODIFIED_CLONE
2+
# makes sure that for a PR the CI runs against a merged main
3+
clone_script: |
4+
if [ -z "$CIRRUS_PR" ]; then
5+
# if you're not in a PR then clone against the branch name that was pushed to.
6+
git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
7+
git reset --hard $CIRRUS_CHANGE_IN_REPO
8+
else
9+
# it's a PR so clone the main branch then merge the changes from the PR
10+
git clone https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
11+
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR
12+
13+
# CIRRUS_BASE_BRANCH will probably be `main` for the majority of the time
14+
# However, if you do a PR against a maintenance branch we will want to
15+
# merge the PR into the maintenance branch, not main
16+
git checkout $CIRRUS_BASE_BRANCH
17+
18+
# alpine git package needs default user.name and user.email to be set before a merge
19+
git -c user.email="[email protected]" merge --no-commit pull/$CIRRUS_PR
20+
git submodule update --init --recursive
21+
fi
22+
23+
24+
macos_arm64_test_task:
25+
macos_instance:
26+
image: ghcr.io/cirruslabs/macos-monterey-xcode:14
27+
28+
<<: *MODIFIED_CLONE
29+
30+
pip_cache:
31+
folder: ~/.cache/pip
32+
33+
test_script: |
34+
brew install [email protected]
35+
36+
export PATH=/opt/homebrew/opt/[email protected]/libexec/bin:$PATH
37+
python --version
38+
39+
RUNNER_OS="macOS"
40+
CFLAGS="-std=c99 -fno-strict-aliasing"
41+
SDKROOT=/Applications/Xcode-14.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk
42+
43+
# used for installing OpenBLAS/gfortran
44+
bash tools/wheels/cibw_before_build.sh $PWD
45+
46+
pushd ~/
47+
python -m venv numpy-dev
48+
source numpy-dev/bin/activate
49+
popd
50+
51+
pip install -r build_requirements.txt
52+
pip install pytest hypothesis typing_extensions
53+
54+
spin build
55+
spin test

tools/ci/cirrus_general.yml renamed to tools/ci/cirrus_wheels.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build_and_store_wheels: &BUILD_AND_STORE_WHEELS
22
install_cibuildwheel_script:
3-
- python -m pip install cibuildwheel==2.12.0
3+
- python -m pip install cibuildwheel==2.12.1
44
cibuildwheel_script:
55
- cibuildwheel
66
wheels_artifacts:
@@ -42,6 +42,50 @@ linux_aarch64_task:
4242
<<: *BUILD_AND_STORE_WHEELS
4343

4444

45+
######################################################################
46+
# Build macosx_arm64 natively
47+
######################################################################
48+
49+
macosx_arm64_task:
50+
macos_instance:
51+
image: ghcr.io/cirruslabs/macos-monterey-xcode:14
52+
matrix:
53+
- env:
54+
CIRRUS_CLONE_SUBMODULES: true
55+
CIBW_BUILD: cp39-*
56+
- env:
57+
CIRRUS_CLONE_SUBMODULES: true
58+
CIBW_BUILD: cp310-* cp311-*
59+
env:
60+
PATH: /opt/homebrew/opt/[email protected]/bin:/usr/local/lib:/usr/local/include:$PATH
61+
CIBW_ARCHS: arm64
62+
# Specifying CIBW_ENVIRONMENT_MACOS overrides pyproject.toml, so include
63+
# all the settings from there, otherwise they're lost.
64+
# SDKROOT needs to be set for repackaged conda-forge gfortran compilers
65+
# supplied by isuruf.
66+
# Find out SDKROOT via `xcrun --sdk macosx --show-sdk-path`
67+
CIBW_ENVIRONMENT_MACOS: >
68+
RUNNER_OS=macOS
69+
SDKROOT=/Applications/Xcode-14.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk
70+
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
71+
CFLAGS="-std=c99 -fno-strict-aliasing"
72+
OPENBLAS64_="/usr/local"
73+
NPY_USE_BLAS_ILP64="1"
74+
75+
build_script:
76+
- brew install [email protected]
77+
- ln -s python3 /opt/homebrew/opt/[email protected]/bin/python
78+
- which python
79+
# needed for submodules
80+
- git submodule update --init
81+
# need to obtain all the tags so setup.py can determine FULLVERSION
82+
- git fetch origin
83+
- uname -m
84+
- python -c "import platform;print(platform.python_version());print(platform.system());print(platform.machine())"
85+
- clang --version
86+
<<: *BUILD_AND_STORE_WHEELS
87+
88+
4589
######################################################################
4690
# Upload all wheels
4791
######################################################################
@@ -53,6 +97,7 @@ wheels_upload_task:
5397
# which bash, etc, may not be present.
5498
depends_on:
5599
- linux_aarch64
100+
- macosx_arm64
56101
compute_engine_instance:
57102
image_project: cirrus-images
58103
image: family/docker-builder

tools/wheels/cibw_before_build.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ fi
1515
# Install Openblas
1616
if [[ $RUNNER_OS == "Linux" || $RUNNER_OS == "macOS" ]] ; then
1717
basedir=$(python tools/openblas_support.py)
18-
cp -r $basedir/lib/* /usr/local/lib
19-
cp $basedir/include/* /usr/local/include
2018
if [[ $RUNNER_OS == "macOS" && $PLATFORM == "macosx-arm64" ]]; then
19+
# /usr/local/lib doesn't exist on cirrus-ci runners
20+
sudo mkdir -p /usr/local/lib /usr/local/include /usr/local/lib/cmake/openblas
2121
sudo mkdir -p /opt/arm64-builds/lib /opt/arm64-builds/include
2222
sudo chown -R $USER /opt/arm64-builds
2323
cp -r $basedir/lib/* /opt/arm64-builds/lib
2424
cp $basedir/include/* /opt/arm64-builds/include
2525
fi
26+
sudo cp -r $basedir/lib/* /usr/local/lib
27+
sudo cp $basedir/include/* /usr/local/include
2628
elif [[ $RUNNER_OS == "Windows" ]]; then
2729
PYTHONPATH=tools python -c "import openblas_support; openblas_support.make_init('numpy')"
2830
target=$(python tools/openblas_support.py)
@@ -42,5 +44,7 @@ if [[ $RUNNER_OS == "macOS" ]]; then
4244
fi
4345
source $PROJECT_DIR/tools/wheels/gfortran_utils.sh
4446
install_gfortran
47+
48+
ls -al /usr/local/lib
4549
pip install "delocate==0.10.4"
4650
fi

tools/wheels/gfortran_utils.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ if [ "$(uname)" == "Darwin" ]; then
123123
curl -L -O https://github.com/isuruf/gcc/releases/download/gcc-11.3.0-2/gfortran-darwin-${arch}-${type}.tar.gz
124124
case ${arch}-${type} in
125125
arm64-native)
126-
export GFORTRAN_SHA=142290685240f4f86cdf359cb2030d586105d7e4
126+
export GFORTRAN_SHA=0d5c118e5966d0fb9e7ddb49321f63cac1397ce8
127127
;;
128128
arm64-cross)
129129
export GFORTRAN_SHA=527232845abc5af21f21ceacc46fb19c190fe804
@@ -148,10 +148,10 @@ if [ "$(uname)" == "Darwin" ]; then
148148
if [[ "${type}" == "native" ]]; then
149149
# Link these into /usr/local so that there's no need to add rpath or -L
150150
for f in libgfortran.dylib libgfortran.5.dylib libgcc_s.1.dylib libgcc_s.1.1.dylib libquadmath.dylib libquadmath.0.dylib; do
151-
ln -sf /opt/gfortran-darwin-${arch}-${type}/lib/$f /usr/local/lib/$f
151+
sudo ln -sf /opt/gfortran-darwin-${arch}-${type}/lib/$f /usr/local/lib/$f
152152
done
153153
# Add it to PATH
154-
ln -sf /opt/gfortran-darwin-${arch}-${type}/bin/gfortran /usr/local/bin/gfortran
154+
sudo ln -sf /opt/gfortran-darwin-${arch}-${type}/bin/gfortran /usr/local/bin/gfortran
155155
fi
156156
}
157157

0 commit comments

Comments
 (0)