From e8222c6c96e00a48980d0f7d2f789365719a8ee8 Mon Sep 17 00:00:00 2001 From: jfranmatheu <45881831+jfranmatheu@users.noreply.github.com> Date: Wed, 12 Feb 2025 17:23:03 +0100 Subject: [PATCH] GH action: another try to support cython build for both macos native and intel --- .github/workflows/build_cython.yml | 15 ++++++++++----- cy_setup.py | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_cython.yml b/.github/workflows/build_cython.yml index 68ecbb11..88bc483e 100644 --- a/.github/workflows/build_cython.yml +++ b/.github/workflows/build_cython.yml @@ -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 diff --git a/cy_setup.py b/cy_setup.py index 0d0204fe..9f4f5cbd 100644 --- a/cy_setup.py +++ b/cy_setup.py @@ -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()], @@ -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 ) ]