PyO3 / maturin-action

GitHub Action to install and run a custom maturin command with built-in support for cross compilation
MIT License
127 stars 35 forks source link

Use matrix instead of separate jobs in generated CI workflow #225

Open djc opened 11 months ago

djc commented 11 months ago

Currently the generated CI workflow has something like this:

jobs:
  linux:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target: [x86_64, x86, aarch64, armv7, s390x, ppc64le]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --find-interpreter
          sccache: 'true'
          manylinux: auto
      - name: Upload wheels
        uses: actions/upload-artifact@v3
        with:
          name: wheels
          path: dist

  windows:
    runs-on: windows-latest
    strategy:
      matrix:
        target: [x64, x86]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
          architecture: ${{ matrix.target }}
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --find-interpreter
          sccache: 'true'
      - name: Upload wheels
        uses: actions/upload-artifact@v3
        with:
          name: wheels
          path: dist

  macos:
    runs-on: macos-latest
    strategy:
      matrix:
        target: [x86_64, aarch64]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --find-interpreter
          sccache: 'true'
      - name: Upload wheels
        uses: actions/upload-artifact@v3
        with:
          name: wheels
          path: dist

The only difference between the different jobs seems to be the use of manylinux: auto? Assuming that that would do the right thing on non-Linux platform, it would be nice to use a matrix instead to use one job that runs over a matrix of platforms and targets. Especially since we can then also set a python variable in the matrix to produce wheels for multiple Python versions.

Here's my adapted version:

  build:
    strategy:
      matrix:
        target: [x86_64]
        python: [3.9, "3.10", "3.11"]
        include:
          - os: ubuntu-latest
            target: x86_64
          - os: windows-latest
            target: x64
          - os: macos-latest
            target: aarch64

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python }}
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --out dist --find-interpreter
          sccache: 'true'
          manylinux: auto
      - name: Upload wheels
        uses: actions/upload-artifact@v3
        with:
          name: wheels
          path: dist

(Personally I think it makes sense to avoid generating binaries for pretty obscure platforms by default.)

djc commented 11 months ago

(So far I'm not actually getting my proposed matrix to work, seems like there's a bug with the matrix setup.)

davidhewitt commented 7 months ago

Closely related to #166