Skip to content

Commit

Permalink
GH action: another try to support cython build for both macos native …
Browse files Browse the repository at this point in the history
…and intel
  • Loading branch information
jfranmatheu committed Feb 12, 2025
1 parent 23ca50f commit e8222c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/build_cython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ jobs:
python -m pip install cython numpy setuptools wheel
- name: Build Cython extensions
shell: bash # Simplified - bash works on all platforms in GitHub Actions
shell: bash
env:
ARCHFLAGS: ${{ matrix.target == 'intel' && '-arch x86_64' || '' }}
CC: ${{ matrix.target == 'intel' && 'gcc -arch x86_64' || 'gcc' }}
CXX: ${{ matrix.target == 'intel' && 'g++ -arch x86_64' || 'g++' }}
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
# Install Rosetta 2 if needed
softwareupdate --install-rosetta --agree-to-license || true
# Use homebrew to install cross-compilation tools
brew install gcc
python -m pip install --upgrade pip
python -m pip install cython numpy setuptools wheel
fi
python cy_setup.py build_ext --inplace
Expand Down
19 changes: 16 additions & 3 deletions cy_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
import numpy as np
import sys
import platform
import os

# Platform-specific compiler flags
compiler_flags = {
'Windows': ['/O2'],
'Darwin': ['-O3', '-stdlib=libc++'], # macOS
'Darwin': ['-O3'], # macOS
'Linux': ['-O3'],
}

# Get the current platform
current_platform = platform.system()

# Base compiler flags
extra_compile_args = compiler_flags.get(current_platform, ['-O3'])

# Handle macOS cross-compilation
if current_platform == 'Darwin' and os.environ.get('ARCHFLAGS'):
extra_compile_args.extend(os.environ['ARCHFLAGS'].split())

shared_ext_kwargs = {
'extra_compile_args': compiler_flags.get(current_platform, ['-O3']),
'extra_compile_args': extra_compile_args,
'language': 'c++'
}

if current_platform == 'Darwin':
shared_ext_kwargs['extra_link_args'] = ['-stdlib=libc++']
shared_ext_kwargs['extra_link_args'] = extra_compile_args

np_ext_kwargs = {
"include_dirs": [np.get_include()],
Expand All @@ -33,6 +41,11 @@
sources=["retopoflow/cy/rfmesh_visibility.pyx"],
**shared_ext_kwargs,
**np_ext_kwargs
),
Extension(
"retopoflow.cy.bmesh_fast",
sources=["retopoflow/cy/bmesh_fast.pyx"],
**shared_ext_kwargs
)
]

Expand Down

0 comments on commit e8222c6

Please sign in to comment.