Skip to content

Commit

Permalink
Cython build GH action: support native (arm64 on M1/M2) and Intel (x8…
Browse files Browse the repository at this point in the history
…6_64) builds on macOS
  • Loading branch information
jfranmatheu committed Feb 12, 2025
1 parent a01e0fe commit 62f7b04
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/build_cython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.11']
include:
- os: macos-latest
target: native
- os: macos-latest
target: intel

steps:
- uses: actions/checkout@v3
Expand All @@ -36,7 +41,17 @@ jobs:
python -m pip install cython numpy setuptools wheel
- name: Build Cython extensions
run: python cy_setup.py build_ext --inplace
env:
ARCHFLAGS: ${{ matrix.target == 'intel' && '-arch x86_64' || '' }}
run: |
if [ "${{ matrix.os }}" == "macos-latest" ] && [ "${{ matrix.target }}" == "intel" ]; then
PYTHON_CROSSENV=$(pwd)/crossenv
python -m pip install crossenv
python -m crossenv $(which python3) $PYTHON_CROSSENV
source $PYTHON_CROSSENV/bin/activate
python -m pip install cython numpy setuptools wheel
fi
python cy_setup.py build_ext --inplace
- name: Rename compiled extensions
shell: bash
Expand All @@ -45,11 +60,16 @@ jobs:
if [ "${{ matrix.os }}" == "windows-latest" ]; then
echo "Windows build - keeping original name"
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
if [ "${{ matrix.target }}" == "intel" ]; then
arch="x86_64"
else
arch=$(uname -m)
fi
# First remove target if it exists
rm -f rfmesh_visibility.cpython-311-darwin-$(uname -m).so
rm -f rfmesh_visibility.cpython-311-darwin-${arch}.so
# Then move the file
for f in rfmesh_visibility*.so; do
mv "$f" rfmesh_visibility.cpython-311-darwin-$(uname -m).so
mv "$f" rfmesh_visibility.cpython-311-darwin-${arch}.so
done
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
# First remove target if it exists
Expand Down

0 comments on commit 62f7b04

Please sign in to comment.