Skip to content

Commit

Permalink
MacOS ARM64 wheels for M1 (and other) machines
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Aug 18, 2022
1 parent 5f431e3 commit c9de98a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
63 changes: 61 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ jobs:
path: ~/.hunter
key: hunter-macos-latest
- name: List .hunter cache directory
run: ls -a -l ~/.hunter/_Base/ || true
run: |
ls -a -l ~/.hunter/_Base/ || true
echo "PATH=$PATH"
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -283,6 +285,63 @@ jobs:
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_PASS: ${{ secrets.ARTIFACTORY_PASS }}

# This job builds wheels for macOS arm64 arch
build-macos-arm64:
needs: build-docstrings
runs-on: [self-hosted, macOS, ARM64]
steps:
# Cached locally on runner
# - name: Cache .hunter folder
# uses: actions/cache@v2
# with:
# path: ~/.hunter
# key: hunter-macos-latest
- name: List .hunter cache directory
run: |
ls -a -l ~/.hunter/_Base/ || true
echo "PATH=$PATH"
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: actions/download-artifact@v2
with:
name: 'docstrings'
path: docstrings
- name: Specify docstring to use while building the wheel
run: echo "DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/docstrings/depthai_python_docstring.hpp" >> $GITHUB_ENV

- name: Append build hash if not a tagged commit
if: startsWith(github.ref, 'refs/tags/v') != true
run: echo "BUILD_COMMIT_HASH=${{github.sha}}" >> $GITHUB_ENV

# - name: Build and install depthai-core
# run: |
# echo "MACOSX_DEPLOYMENT_TARGET=11.0" >> $GITHUB_ENV
# cmake -S depthai-core/ -B build_core -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=$PWD/cmake/toolchain/pic.cmake
# cmake --build build_core --target install --parallel 4
# echo "DEPTHAI_INSTALLATION_DIR=$PWD/build_core/install/" >> $GITHUB_ENV

- name: Build wheels
run: for PYBIN in {9..10}; do "python3.${PYBIN}" -m pip wheel . -w wheelhouse/ --verbose; done

- name: Auditing wheels
run: delocate-wheel -v -w wheelhouse/audited wheelhouse/*.whl

- name: Archive wheel artifacts
uses: actions/upload-artifact@v2
with:
name: audited-wheels
path: wheelhouse/audited/
- name: Deploy wheels to artifactory (if not a release)
if: startsWith(github.ref, 'refs/tags/v') != true
run: bash ./ci/upload-artifactory.sh
env:
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
ARTIFACTORY_USER: ${{ secrets.ARTIFACTORY_USER }}
ARTIFACTORY_PASS: ${{ secrets.ARTIFACTORY_PASS }}

# This job builds wheels for x86_64 arch
build-linux-x86_64:
needs: build-docstrings
Expand Down Expand Up @@ -406,7 +465,7 @@ jobs:

release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [pytest, build-linux-armhf, build-windows-x86_64, build-macos-x86_64, build-linux-x86_64, build-linux-arm64]
needs: [pytest, build-linux-armhf, build-windows-x86_64, build-macos-x86_64, build-macos-arm64, build-linux-x86_64, build-linux-arm64]
runs-on: ubuntu-latest

steps:
Expand Down
16 changes: 13 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
## Read description (README.md)
long_description = io.open("README.md", encoding="utf-8").read()

## Early settings
MACOS_ARM64_WHEEL_NAME_OVERRIDE = 'macosx-11.0-arm64'
if sys.platform == 'darwin' and platform.machine() == 'arm64':
os.environ['_PYTHON_HOST_PLATFORM'] = MACOS_ARM64_WHEEL_NAME_OVERRIDE

class CMakeExtension(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])
Expand Down Expand Up @@ -105,7 +110,7 @@ def build_extension(self, ext):
# Windows - remove case insensitive variants
env = {key:env[key] for key in env if key.upper() != 'pythonLocation'.upper()}
env['pythonLocation'] = str(Path(sys.executable).parent.absolute())


# Pass a commit hash
if buildCommitHash != None :
Expand Down Expand Up @@ -155,8 +160,13 @@ def build_extension(self, ext):
# if macos add some additional env vars
if sys.platform == 'darwin':
from distutils import util
env['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
env['_PYTHON_HOST_PLATFORM'] = re.sub(r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.9-\1', util.get_platform())
if platform.machine() == 'arm64':
# Build ARM64 wheels explicitly instead of universal2
env['MACOSX_DEPLOYMENT_TARGET'] = '11.0'
env['_PYTHON_HOST_PLATFORM'] = MACOS_ARM64_WHEEL_NAME_OVERRIDE
else:
env['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
env['_PYTHON_HOST_PLATFORM'] = re.sub(r'macosx-[0-9]+\.[0-9]+-(.+)', r'macosx-10.9-\1', util.get_platform())

# Specify how many threads to use when building, depending on available memory
max_threads = multiprocessing.cpu_count()
Expand Down

0 comments on commit c9de98a

Please sign in to comment.