diff --git a/.github/workflows/build_python.yml b/.github/workflows/build_python.yml index 9860b9c7fc..fe135a1368 100644 --- a/.github/workflows/build_python.yml +++ b/.github/workflows/build_python.yml @@ -77,4 +77,3 @@ jobs: # python3 setup.py install --user # - name: Test # run: python3 -m pytest --ignore docs --ignore dlib - diff --git a/.github/workflows/build_python_wheel.yml b/.github/workflows/build_python_wheel.yml new file mode 100644 index 0000000000..76b932c0ef --- /dev/null +++ b/.github/workflows/build_python_wheel.yml @@ -0,0 +1,100 @@ +name: Python wheels + +on: + push: + branches: + - master + paths: + - ".github/workflows/build_python.yml" + - "**.cpp" + - "**.h" + - "**.c" + - "**.cu" + - "**.cmake" + - "**CMakeLists.txt" + - "**py" + pull_request: + branches: + - master + paths: + - ".github/workflows/build_python.yml" + - "**.cpp" + - "**.h" + - "**.c" + - "**.cu" + - "**.cmake" + - "**CMakeLists.txt" + - "**py" + +defaults: + run: + shell: bash + +jobs: + build_wheels_matrix: + runs-on: ubuntu-latest + outputs: + include: ${{ steps.set-matrix.outputs.include }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: 3.x + - run: pip install cibuildwheel==2.20.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 + + build_wheels: + needs: build_wheels_matrix + runs-on: ${{ matrix.os }} + name: Build ${{ matrix.only }} + + strategy: + fail-fast: false + matrix: + include: ${{ fromJson(needs.build_wheels_matrix.outputs.include) }} + + steps: + - uses: actions/checkout@v4 + + - name: Disable gui support + run: | + sed -i'' -e "s/_cmake_extra_options = \[\]/_cmake_extra_options = \['-DDLIB_NO_GUI_SUPPORT=ON'\]/" setup.py + + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v3 + + - uses: pypa/cibuildwheel@v2.20.0 # sync version with pip install cibuildwheel above + with: + only: ${{ matrix.only }} + env: + CIBW_BUILD_VERBOSITY: 1 + CIBW_TEST_COMMAND: python -c "import dlib" + +# Disabled for now since something is going sideways with python packages on github actions +# MacOS: +# runs-on: 'macos-latest' +# steps: +# - uses: actions/checkout@v3 +# - uses: actions/setup-python@v4 +# - name: Install python deps +# run: pip3 install pytest numpy +# - name: Build +# run: | +# python3 setup.py build +# python3 setup.py install --user +# - name: Test +# run: python3 -m pytest --ignore docs --ignore dlib + diff --git a/pyproject.toml b/pyproject.toml index 9787c3bdf0..50c57b3627 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools", "wheel", "cmake==3.24.0"] build-backend = "setuptools.build_meta"