From 4998f42d46019e8ed86b4ab1f7a8bc4c6094719d Mon Sep 17 00:00:00 2001 From: Tip ten Brink Date: Fri, 8 Oct 2021 00:53:13 +0200 Subject: [PATCH] Updated build wheels.yml --- .github/workflows/wheels.yml | 216 +++++++++++++++++------------------ 1 file changed, 103 insertions(+), 113 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index c476d89..a1fe900 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -6,143 +6,133 @@ on: types: [published] jobs: - # Build for manylinux, which allows it to be run on many different Linux platforms - build-manylinux: - strategy: - # Let individual matrix jobs go if one fails - fail-fast: false - matrix: - include: - # We are compatible with all supported Python versions. The 'cp37-cp37m' is the PEP 425 tag of that specific - # Python version, which is where the Python interpreters of the manylinux Docker container are located. - - py-version: 3.7 - py-pep-425: 'cp37-cp37m' - - py-version: 3.8 - py-pep-425: 'cp38-cp38' - - py-version: 3.9 - py-pep-425: 'cp39-cp39' - runs-on: ubuntu-latest - steps: - # Set up the repository with the Docker container action, which will allow us to build and run a manylinux Docker - # container that will ensure compatibility. See the action repository for more info. - - name: Checkout action - uses: actions/checkout@v2 - with: - repository: tmtenbrink/python-wheels-manylinux-build - # Set up the package repository in a sub-path, so it doesn't overwrite the Docker container action repo - - name: Checkout rustfrc - uses: actions/checkout@v2 - with: - path: ${{ github.repository }} - - name: Setup Python environment - uses: actions/setup-python@v2 + # Build for manylinux, which allows it to be run on many different Linux platforms + build-manylinux: + strategy: + # Let individual matrix jobs go if one fails + fail-fast: false + matrix: + include: + # We are compatible with all supported Python versions. The 'cp37-cp37m' is the PEP 425 tag of that specific + # Python version, which is where the Python interpreters of the manylinux Docker container are located. + - py-version: '3.7' + py-pep-425: 'cp37-cp37m' + - py-version: '3.8' + py-pep-425: 'cp38-cp38' + - py-version: '3.9' + py-pep-425: 'cp39-cp39' + - py-version: '3.10' + py-pep-425: 'cp310-cp310' + runs-on: ubuntu-latest + steps: + - name: Checkout rustfrc + uses: actions/checkout@v2 + with: + path: ${{ github.repository }} + # Set up the repository with the Docker container action, which will allow us to build and run a manylinux Docker + # container that will ensure compatibility. See the action repository for more info. + - name: maturin-manylinux-wheels-action + uses: tmtenbrink/maturin-manylinux-wheels-action@v1.0.1 + with: + py-version: "python${{ matrix.py-version }}" + py-pep-425: ${{ matrix.py-pep-425 }} + package-path: ${{ github.repository }} + # Set up the package repository in a sub-path, so it doesn't overwrite the Docker container action repo + + # It now uploads all the wheel files to an artifact that we can later retrieve + - uses: actions/upload-artifact@v2 + with: + name: wheels + path: ${{ github.repository }}/dist + + buildmac: + runs-on: macos-11 + strategy: + fail-fast: false + matrix: + # If we run it without this argument, it will generate only x86_64 wheels, which are compatible with more + # macOS and pip versions. Universal2 wheels are compatible with Apple Silicon (aarch64) Macs but also updated + # x86_64 Macs. In the future only universal2 wheels will be necessary. + target: ['--universal2', ''] + py-version: ['3.7', '3.8', '3.9', '3.10'] + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 with: python-version: ${{ matrix.py-version }} - # ./ means it will search for the 'action.yml' in the Docker container action repo root. It will then build the - # Docker container and run it with the variables we give it. Specifically, it will run entrypoint.sh that is - # also in the Docker container action repo, which will perform the same steps as the other jobs, but inside the - # container. When it is done, it will have placed the compiled wheels at the /dist directory of the package root, - # which we had set as ${{ github.repository }} when we checked out the package repository - - name: Build manylinux Python wheels - uses: './' - with: - py-version: "python${{ matrix.py-version }}" - py-pep-425: ${{ matrix.py-pep-425 }} - package-path: ${{ github.repository }} - # It now uploads all the wheel files to an artifact that we can later retrieve + + # The x86_64 Rust toolchain is installed on GitHub runners, but since we compile also for Apple Silicon, we also + # need the correct Rust toolchain. + - name: Rustup install aarch64 target + run: rustup target add aarch64-apple-darwin + if: ${{ matrix.target == '--universal2' }} + + # We install poetry as a dependency manager to read the pyproject.toml of our package. + - name: Poetry + run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - + + # GitHub has modified PATH behavior, so we use the below command to add poetry to our PATH + - name: Add poetry path + run: echo "$HOME/.local/bin" >> $GITHUB_PATH + + # poetry update will install all dependencies for our package, as well as maturin, which we use as our build + # back-end + - name: Poetry update + run: poetry update + working-directory: ${{ github.workspace }} + + # delocate is the macOS version of auditwheel. + - name: Install delocate + run: pip install delocate + working-directory: ${{ github.workspace }} + + # This command will actually compile the wheels. We use --release to make sure Rust properly optimizes the code. + # The ${{ matrix.target }} indicates whether we are building universal 2 wheels. Finally using -i python ensures + # only the Python we set up above will be used as target. + - name: maturin build release + run: poetry run maturin build --release ${{ matrix.target }} -i python + working-directory: ${{ github.workspace }} + + # We now fix the wheels using delocate + - name: delocate fix wheels + run: find . -name "*.whl" -exec delocate-wheel -w wheelhouse --require-archs=universal2 {} \; + working-directory: ${{ github.workspace }} + - uses: actions/upload-artifact@v2 with: name: wheels - path: ${{ github.repository }}/dist + path: ${{ github.workspace }}/wheelhouse - buildmac: - runs-on: macos-11 + buildwindows: + runs-on: windows-latest strategy: fail-fast: false matrix: - # If we run it without this argument, it will generate only x86_64 wheels, which are compatible with more - # macOS and pip versions. Universal2 wheels are compatible with Apple Silicon (aarch64) Macs but also updated - # x86_64 Macs. In the future only universal2 wheels will be necessary. - target: ['--universal2', ''] - py-version: ['3.7', '3.8', '3.9'] + py-version: ['3.7', '3.8', '3.9', '3.10'] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: python-version: ${{ matrix.py-version }} - # The x86_64 Rust toolchain is installed on GitHub runners, but since we compile also for Apple Silicon, we also - # need the correct Rust toolchain. - - name: Rustup install aarch64 target - run: rustup target add aarch64-apple-darwin - if: ${{ matrix.target == '--universal2' }} - - # We install poetry as a dependency manager to read the pyproject.toml of our package. + # Installing poetry requires a different command on Windows than on macOS/Linux - name: Poetry - run: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - + run: (Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python - - # GitHub has modified PATH behavior, so we use the below command to add poetry to our PATH - - name: Add poetry path - run: echo "$HOME/.local/bin" >> $GITHUB_PATH + # PATH is also different + - name: Poetry path + run: echo "$env:APPDATA\Python\Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - # poetry update will install all dependencies for our package, as well as maturin, which we use as our build - # back-end - name: Poetry update - run: poetry update + run: | + poetry update working-directory: ${{ github.workspace }} - # delocate is the macOS version of auditwheel. - - name: Install delocate - run: pip install delocate - working-directory: ${{ github.workspace }} - - # This command will actually compile the wheels. We use --release to make sure Rust properly optimizes the code. - # The ${{ matrix.target }} indicates whether we are building universal 2 wheels. Finally using -i python ensures - # only the Python we set up above will be used as target. - name: maturin build release - run: poetry run maturin build --release ${{ matrix.target }} -i python - working-directory: ${{ github.workspace }} - - # We now fix the wheels using delocate - - name: delocate fix wheels - run: find . -name "*.whl" -exec delocate-wheel -w wheelhouse --require-archs=universal2 {} \; + run: poetry run maturin build --release -i python working-directory: ${{ github.workspace }} - uses: actions/upload-artifact@v2 with: name: wheels - path: ${{ github.workspace }}/wheelhouse - - buildwindows: - runs-on: windows-latest - strategy: - fail-fast: false - matrix: - py-version: ['3.7', '3.8', '3.9'] - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.py-version }} - - # Installing poetry requires a different command on Windows than on macOS/Linux - - name: Poetry - run: (Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py -UseBasicParsing).Content | python - - - # PATH is also different - - name: Poetry path - run: echo "$env:APPDATA\Python\Scripts" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - - name: Poetry update - run: | - poetry update - working-directory: ${{ github.workspace }} - - - name: maturin build release - run: poetry run maturin build --release -i python - working-directory: ${{ github.workspace }} - - - uses: actions/upload-artifact@v2 - with: - name: wheels - path: ${{ github.workspace }}/target/wheels + path: ${{ github.workspace }}/target/wheels