update cython-build #15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Cython Extensions | |
on: | |
push: | |
paths: | |
- 'retopoflow/cy/*.pyx' | |
- 'retopoflow/cy/*.pxd' | |
- 'cy_setup.py' | |
- '.github/workflows/build_cython.yml' | |
pull_request: | |
paths: | |
- 'retopoflow/cy/*.pyx' | |
- 'retopoflow/cy/*.pxd' | |
- 'cy_setup.py' | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
build: | |
name: Build on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
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 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install cython numpy setuptools wheel | |
- name: Build Cython extensions | |
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 | |
# 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 | |
- name: Rename compiled extensions | |
shell: bash | |
run: | | |
cd retopoflow/cy | |
echo "Files before renaming:" | |
ls -la *.so || ls -la *.pyd | |
if [ "${{ matrix.os }}" == "windows-latest" ]; then | |
echo "Windows build - keeping original names" | |
elif [ "${{ matrix.os }}" == "macos-latest" ]; then | |
if [ "${{ matrix.target }}" == "intel" ]; then | |
arch="x86_64" | |
else | |
arch=$(uname -m) | |
fi | |
echo "Target architecture: ${arch}" | |
# Process all .so files | |
for f in *.so; do | |
if [ -f "$f" ]; then | |
base_name="${f%.cpython*}" | |
# First remove target if it exists | |
rm -f "${base_name}.cpython-311-darwin-${arch}.so" | |
# Then move the file | |
mv "$f" "${base_name}.cpython-311-darwin-${arch}.so" | |
fi | |
done | |
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then | |
arch=$(uname -m) | |
echo "Linux architecture: ${arch}" | |
# Process all .so files | |
for f in *.so; do | |
if [ -f "$f" ]; then | |
base_name="${f%.cpython*}" | |
# First remove target if it exists | |
rm -f "${base_name}.cpython-311-linux-${arch}.so" | |
# Then move the file | |
mv "$f" "${base_name}.cpython-311-linux-${arch}.so" | |
fi | |
done | |
fi | |
echo "Files after renaming:" | |
ls -la *.so || ls -la *.pyd | |
- name: Upload compiled extensions | |
uses: actions/upload-artifact@v4 | |
with: | |
name: compiled-extensions-${{ matrix.os }} | |
path: | | |
retopoflow/cy/*.so | |
retopoflow/cy/*.pyd | |
retention-days: 7 | |
commit-files: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
merge-multiple: true | |
- name: Copy compiled files to cy folder | |
run: | | |
mkdir -p retopoflow/cy | |
find artifacts -type f \( -name "*.so" -o -name "*.pyd" \) -exec cp -f {} retopoflow/cy/ \; | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git add retopoflow/cy/*.so retopoflow/cy/*.pyd | |
git commit -m "Update compiled Cython extensions [skip ci]" || echo "No changes to commit" | |
git push |