Skip to content

Commit

Permalink
Cross-compilation for MacOS 12 arm64.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchanial committed Dec 12, 2022
1 parent 4473f32 commit 630a8e1
Show file tree
Hide file tree
Showing 5 changed files with 1,025 additions and 5 deletions.
65 changes: 61 additions & 4 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ jobs:
- os: macos-11
arch: x86_64
fflags: -march=x86-64 -mavx
# - os: macos-11
# arch: arm64
# fflags: -march=armv8.5-a
- os: macos-12
arch: arm64
fflags: -march=armv8.5-a
python:
- version: "3.8"
cp: cp38
Expand Down Expand Up @@ -79,11 +79,12 @@ jobs:
run: gfortran --version

- name: Build wheels
if: ${{ matrix.platform.arch != 'arm64' }}
uses: pypa/cibuildwheel@v2.9.0
env:
CIBW_BUILD: ${{ matrix.python.cp }}-*
CIBW_BUILD_VERBOSITY: 3
CIBW_ENVIRONMENT: NPY_DISTUTILS_APPEND_FLAGS=1 FFLAGS='${{ matrix.platform.fflags }}'
CIBW_ENVIRONMENT: FFLAGS='${{ matrix.platform.fflags }}'
CIBW_SKIP: "*-musllinux_*"
CIBW_ARCHS: ${{ matrix.platform.arch }}
CIBW_BEFORE_TEST_LINUX: |
Expand All @@ -94,6 +95,62 @@ jobs:
CIBW_TEST_COMMAND: pytest {package}/tests
PYTHONFAULTHANDLER: "1"

- name: Build macosx_arm64
# This is solely used to build macosx_arm64. As soon as Github Actions make
# MacOS arm64 runners available, it should be removed. Adapted from scipy's CI.
if: ${{ matrix.platform.os == 'macos-12' && matrix.platform.arch == 'arm64' }}
run: |
set -ex
# Update license
cat tools/wheels/LICENSE_osx.txt >> LICENSE.txt
export PLAT="arm64"
export _PYTHON_HOST_PLATFORM="macosx-12.0-arm64"
export CROSS_COMPILE=1
# Need macOS >= 11 for arm compilation.
export MACOSX_DEPLOYMENT_TARGET=11.0
# SDK root needs to be set early, installation of gfortran/openblas
# needs to go in the correct location.
export SDKROOT=/Applications/Xcode_13.2.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk
export ARCHFLAGS=" -arch arm64 "
source tools/wheels/gfortran_utils.sh
export MACOSX_DEPLOYMENT_TARGET=11.0
# The install script requires the PLAT variable in order to set
# the FC variable
export PLAT=arm64
install_arm64_cross_gfortran
export FC=$FC_ARM64
export PATH=$FC_LOC:$PATH
export FFLAGS=" -arch arm64 $FFLAGS"
export LDFLAGS=" $FC_ARM64_LDFLAGS $LDFLAGS -L/opt/arm64-builds/lib -arch arm64"
sudo ln -s $FC $FC_LOC/gfortran
echo $(type -p gfortran)
# having a test fortran program has helped in debugging problems with the
# compiler environment.
$FC $FFLAGS tools/wheels/test.f $LDFLAGS
ls -al *.out
otool -L a.out
export PKG_CONFIG_PATH=/opt/arm64-builds/lib/pkgconfig
export PKG_CONFIG=/usr/local/bin/pkg-config
export CFLAGS=" -arch arm64 $CFLAGS"
export CXXFLAGS=" -arch arm64 $CXXFLAGS"
export LD_LIBRARY_PATH="/opt/arm64-builds/lib:$FC_LIBDIR:$LD_LIBRARY_PATH"
# install dependencies for the build machine
pipx run build --wheel
# Enables delocate to find the libopenblas/libgfortran libraries.
export DYLD_LIBRARY_PATH=/opt/gfortran-darwin-arm64/lib/gcc/arm64-apple-darwin20.0.0/10.2.1:/opt/arm64-builds/lib
pip3 install delocate
delocate-listdeps dist/pysimulators*.whl
delocate-wheel --require-archs=arm64 -k -w wheelhouse dist/pysimulators*.whl
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "setuptools.build_meta"
requires = [
"oldest-supported-numpy",
"pchanial-legacy-install-hooks>=1.3",
"pchanial-legacy-install-hooks>=1.5",
"setuptools==64.0.3",
"setuptools_scm[toml]>=6.2",
"wheel",
Expand Down
Loading

0 comments on commit 630a8e1

Please sign in to comment.