Skip to content

Commit

Permalink
actions: add Apple M support
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
  • Loading branch information
noxdafox committed Feb 17, 2024
1 parent 6d10327 commit 4051816
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 36 deletions.
143 changes: 109 additions & 34 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,87 @@ name: CLIPSPy build job
on: [push, pull_request]

jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Manylinux Container
run: |
docker build -t clipspy-build-wheels:latest -f manylinux/Dockerfile .
- name: Build Manylinux packages
run: |
docker run --rm -v `pwd`/manylinux/wheelhouse:/io/wheelhouse clipspy-build-wheels:latest
- name: Store build artifacts
uses: actions/upload-artifact@v3
with:
name: linux-build
path: manylinux/wheelhouse
# build-linux:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - name: Build Manylinux Container
# run: |
# docker build -t clipspy-build-wheels:latest -f manylinux/Dockerfile .
# - name: Build Manylinux packages
# run: |
# docker run --rm -v `pwd`/manylinux/wheelhouse:/io/wheelhouse clipspy-build-wheels:latest
# - name: Store build artifacts
# uses: actions/upload-artifact@v3
# with:
# name: linux-build
# path: manylinux/wheelhouse

# build-windows:
# runs-on: windows-latest
# strategy:
# matrix:
# python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
# steps:
# - uses: actions/checkout@v2
# # Install nmake
# - uses: ilammy/msvc-dev-cmd@v1
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v2
# with:
# python-version: ${{ matrix.python-version }}
# - name: Build CLIPSPy
# run: |
# python -m pip install --upgrade pip
# pip install --upgrade cffi wheel pytest setuptools
# nmake /F Makefile.win
# - name: Install CLIPSPy
# run: |
# pip install --find-links=dist clipspy
# - name: Run tests
# run: |
# # Run test from outside module to test installed package
# cd ../
# python -m pytest -v clipspy/test
# - name: Store build artifacts
# uses: actions/upload-artifact@v3
# with:
# name: windows-build
# path: dist/

build-windows:
runs-on: windows-latest
build-macos-intel:
runs-on: macos-12
env:
ARCHFLAGS: "-arch x86_64"
MACOSX_DEPLOYMENT_TARGET: "11.0"
_PYTHON_HOST_PLATFORM: macosx_11_0_x86_64
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.11', '3.12']
steps:
- uses: actions/checkout@v2
# Install nmake
- uses: ilammy/msvc-dev-cmd@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Build CLIPSPy
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade cffi wheel pytest setuptools
nmake /F Makefile.win
pip install --upgrade cffi wheel delocate pytest setuptools
- name: Build and install CLIPS
run: |
make install-clips
- name: Build CLIPSPy
run: |
make clipspy
- name: Repair wheels
run: |
for whl in $(ls dist | grep .whl); do
delocate-wheel -v "dist/$whl"
done
- name: Install CLIPSPy
run: |
pip install --find-links=dist clipspy
pip install dist/*.whl
- name: Run tests
run: |
# Run test from outside module to test installed package
Expand All @@ -48,14 +92,18 @@ jobs:
- name: Store build artifacts
uses: actions/upload-artifact@v3
with:
name: windows-build
name: macos-intel-build
path: dist/

build-macos:
runs-on: macos-latest
build-macos-arm:
runs-on: macos-14
env:
ARCHFLAGS: "-arch arm64"
MACOSX_DEPLOYMENT_TARGET: "11.0"
_PYTHON_HOST_PLATFORM: "macosx_10.9_arm64"
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.11', '3.12']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -68,15 +116,17 @@ jobs:
pip install --upgrade cffi wheel delocate pytest setuptools
- name: Build and install CLIPS
run: |
make install-clips
make clips
sudo make install-clips
- name: Build CLIPSPy
run: |
make clipspy
sudo make clipspy
- name: Repair wheels
run: |
for whl in $(ls dist | grep .whl); do
delocate-wheel -v "dist/$whl"
done
# This is a shortcut to have a successful delocate-wheel. Credits: @alexsavulescu
# See: https://github.com/matthew-brett/delocate/issues/153
python -c "import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()" | xargs -I{} sed -i."" "s/first, /input.pop('x86_64',None); first, /g" {}
sudo delocate-wheel -v dist/*.whl
- name: Install CLIPSPy
run: |
pip install dist/*.whl
Expand All @@ -88,5 +138,30 @@ jobs:
- name: Store build artifacts
uses: actions/upload-artifact@v3
with:
name: macos-build
name: macos-arm-build
path: dist/

build-macos-universal:
needs: [build-macos-intel, build-macos-arm]
runs-on: macos-12
steps:
- uses: actions/download-artifact@master
with:
name: macos-intel-build
path: artifacts/
- uses: actions/download-artifact@master
with:
name: macos-arm-build
path: artifacts/
- name: Unzip artifacts
run: |
mkdir -p wheels
for artifact in $(ls artifacts | grep .zip); do
unzip --extract-dir wheels $artifact
done
ls -ahl wheels
- name: Store build artifacts
uses: actions/upload-artifact@v3
with:
name: macos-intel-build
path: dist/
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ endif

clipspy: clips
$(PYTHON) setup.py build_ext --include-dirs=clips_source/ \
--library-dirs=clips_source/
$(PYTHON) setup.py sdist bdist_wheel
--library-dirs=clips_source/ bdist_wheel

test: clipspy
cp build/lib.*/clips/_clips*.so clips
Expand Down
28 changes: 28 additions & 0 deletions repair_wheels_osx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -xe

py_platform=$(python -c "import sysconfig; print('%s' % sysconfig.get_platform());")

echo " - Python platform: ${py_platform}"
if [[ "${py_platform}" == *"-universal2" ]]; then
if [[ `uname -m` == 'arm64' ]]; then
export _PYTHON_HOST_PLATFORM="${py_platform/universal2/arm64}"
echo " - Python installation is universal2 and we are on arm64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}"
export ARCHFLAGS="-arch arm64"
echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}"
# This is a shortcut to have a successful delocate-wheel. See:
# https://github.com/matthew-brett/delocate/issues/153
python -c "import os,delocate; print(os.path.join(os.path.dirname(delocate.__file__), 'tools.py'));quit()" | xargs -I{} sed -i."" "s/first, /input.pop('x86_64',None); first, /g" {}
else
export _PYTHON_HOST_PLATFORM="${py_platform/universal2/x86_64}"
echo " - Python installation is universal2 and we are on x84_64, setting _PYTHON_HOST_PLATFORM to: ${_PYTHON_HOST_PLATFORM}"
export ARCHFLAGS="-arch x86_64"
echo " - Setting ARCHFLAGS to: ${ARCHFLAGS}"
fi
fi

python setup.py build_ext --include-dirs=clips_source/ --library-dirs=clips_source/ bdist_wheel

delocate-listdeps dist/*.whl

delocate-wheel -v dist/*.whl

0 comments on commit 4051816

Please sign in to comment.