Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize and add more wheel builds #9

Merged
merged 11 commits into from
Apr 4, 2024
122 changes: 78 additions & 44 deletions .github/workflows/build.yaml
Expand Up @@ -2,69 +2,103 @@ name: Build

on: [push]

env:
WORKING_DIRECTORY: 'dlib'
BUILD_COMMIT: 'v19.24.2'
DLIB_BIN_VERSION: '19.24.2'
PYTHON_REQUIRES: '>=3.7'

jobs:
build_wheels_matrix:
runs-on: ubuntu-latest
outputs:
include: ${{ steps.set-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-python@v5
with:
python-version: 3.x

- run: pip install cibuildwheel==2.17.0 # sync version with pypa/cibuildwheel below

- id: set-matrix
env:
CIBW_PROJECT_REQUIRES_PYTHON: '>=3.7' # it is missing in setup.py and needed to determine which wheels to build
run: |
MATRIX_INCLUDE=$(
{
cibuildwheel --print-build-identifiers --platform linux --arch x86_64,aarch64 | grep cp | jq -nRc '{"only": inputs, "os": "ubuntu-latest"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch x86_64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-13"}' \
&& cibuildwheel --print-build-identifiers --platform macos --arch arm64 | grep cp | jq -nRc '{"only": inputs, "os": "macos-14"}' \
&& cibuildwheel --print-build-identifiers --platform windows --arch AMD64 | grep cp | jq -nRc '{"only": inputs, "os": "windows-latest"}'
} | jq -sc
)
echo "include=$MATRIX_INCLUDE" >> $GITHUB_OUTPUT
working-directory: ${{ env.WORKING_DIRECTORY }}

build_wheels:
name: Build wheels on ${{ matrix.os }}
needs: build_wheels_matrix
runs-on: ${{ matrix.os }}
name: Build ${{ matrix.only }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
REPO_DIR: 'dlib'
BUILD_COMMIT: 'v19.24.2'
DLIB_BIN_VERSION: '19.24.2'
CIBUILDWHEEL_VERSION: '2.17.0'
CIBW_BEFORE_BUILD: 'pip install cmake'
CIBW_BUILD: 'cp37-* cp38-* cp39-* cp310-* cp311-*'
CIBW_SKIP: '*musllinux*'
CIBW_ARCHS: 'auto64'
include: ${{ fromJson(needs.build_wheels_matrix.outputs.include) }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Checkout submodules
defaults:
run:
shell: bash
run: |
git submodule update --init --recursive
git -C dlib checkout $BUILD_COMMIT

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Fix setup.py
shell: bash
run: |
sed -i'' -e "s/name='dlib'/name='dlib-bin'/" $REPO_DIR/setup.py
sed -i'' -e "s/version=read_version_from_cmakelists('dlib\/CMakeLists.txt')/version='$DLIB_BIN_VERSION'/" $REPO_DIR/setup.py
sed -i'' -e "s/url='https:\/\/github\.com\/davisking\/dlib'/url='https:\/\/github\.com\/alesanfra\/dlib-wheels'/" $REPO_DIR/setup.py
sed -i'' -e "s/_cmake_extra_options = \[\]/_cmake_extra_options = \['-DDLIB_NO_GUI_SUPPORT=ON'\]/" $REPO_DIR/setup.py
- name: Checkout build commit
run: git fetch --all && git checkout $BUILD_COMMIT
working-directory: ${{ env.WORKING_DIRECTORY }}

- name: Install cibuildwheel
shell: bash
run: python -m pip install cibuildwheel==$CIBUILDWHEEL_VERSION

- name: Build wheels
shell: bash
run: python3 -m cibuildwheel $REPO_DIR --output-dir wheelhouse
- name: Fix setup.py
run: |
sed -i'' -e "s/name='dlib'/name='dlib-bin'/" setup.py
sed -i'' -e "s/version=read_version_from_cmakelists('dlib\/CMakeLists.txt')/version='$DLIB_BIN_VERSION'/" setup.py
sed -i'' -e "s/url='https:\/\/github\.com\/davisking\/dlib'/url='https:\/\/github\.com\/alesanfra\/dlib-wheels'/" setup.py
sed -i'' -e "s/_cmake_extra_options = \[\]/_cmake_extra_options = \['-DDLIB_NO_GUI_SUPPORT=ON'\]/" setup.py
working-directory: ${{ env.WORKING_DIRECTORY }}

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3

- name: Save wheels
uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
- uses: pypa/cibuildwheel@v2.17.0 # sync version with pip install cibuildwheel above
with:
only: ${{ matrix.only }}
package-dir: ${{ env.WORKING_DIRECTORY }}
env:
CIBW_BUILD_VERBOSITY: 1
CIBW_BEFORE_BUILD: pip install cmake
CIBW_TEST_COMMAND: python -c "import dlib"

- uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.only }}
path: wheelhouse/*.whl

upload_pypi:
needs: [build_wheels]
runs-on: ubuntu-latest
# upload to PyPI on master
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: artifact
path: dist
path: dist/
pattern: dist-*
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down