Skip to content

Merge pull request #43 from YangLiuWillow/main #70

Merge pull request #43 from YangLiuWillow/main

Merge pull request #43 from YangLiuWillow/main #70

Workflow file for this run

name: Build Python Binding
on:
push:
branches:
- main
tags:
- '**'
# pull_request: {}
jobs: # Workflow credit to https://github.com/samuelcolvin/rtoml/blob/main/.github/workflows/ci.yml
# Yue: I use cibuildwheel to start multiple dockers with different targets, and use maturin to actually generate the wheel
build_wheels:
name: Build wheels py3.${{ matrix.python-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu
- macos
- windows
python-version: # Yue 2022.10.9: I enabled abi3-py37 in pyo3, so everything built will be py37-abi3 which is compatible with py37+
# - '7'
- '8' # use python 3.8 to build because macos universal2 requires at least python 3.8; however the result will be py37-abi3
# - '9'
# - '10'
# - '11'
include:
- os: ubuntu
platform: linux
- os: windows
ls: dir
runs-on: ${{ format('{0}-latest', matrix.os) }}
steps:
- uses: actions/checkout@v3
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
- uses: actions/setup-python@v3
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
- name: Install Rust
# unnecessary for ubuntu because it's installed inside cibuildwheel
# no python37 for macos
if: matrix.os != 'ubuntu' && (matrix.os != 'macos' || matrix['python-version'] != '7')
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2023-11-16
override: true
- name: Install Python dependencies
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
run: python -m pip install -U setuptools wheel twine cibuildwheel
# - name: Set up QEMU for building with emulator
# if: matrix.os == 'ubuntu'
# uses: docker/setup-qemu-action@v2
# with:
# platforms: all
- name: Build Wheels
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-*'
CIBW_SKIP: "*-win32 *_i686" # do not build for 32bit machines, rustc seems to complain about it
CIBW_PLATFORM: ${{ matrix.platform || matrix.os }} # only build for specific platform
CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH"'
CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_MANYLINUX_X86_64_IMAGE: 'manylinux2014'
# Yue 2022.10.17: build on aarch64 failed due to strange `cargo metadata` exited with an error: Updating crates.io index
CIBW_ARCHS_LINUX: x86_64 # aarch64 requires QEMU, ~ 40min for each manylinux and musllinux...
CIBW_ARCHS_MACOS: universal2
CIBW_BEFORE_BUILD: >
rustup default nightly-2023-11-16 &&
rustup show
CIBW_BEFORE_BUILD_MACOS: >
rustup default nightly-2023-11-16 &&
rustup target add aarch64-apple-darwin &&
rustup target add x86_64-apple-darwin &&
rustup show
CIBW_BEFORE_BUILD_LINUX: >
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=nightly-2023-11-16 --profile=minimal -y &&
rustup show
- name: Build windows 32bit wheels
if: matrix.os == 'windows'
run: cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: 'cp3${{ matrix.python-version }}-win32'
CIBW_PLATFORM: windows
CIBW_ENVIRONMENT: 'PATH="$UserProfile\.cargo\bin;$PATH"'
CIBW_BEFORE_BUILD: >
rustup toolchain install nightly-2023-11-16-i686-pc-windows-msvc &&
rustup default nightly-2023-11-16-i686-pc-windows-msvc &&
rustup override set nightly-2023-11-16-i686-pc-windows-msvc &&
rustup show
- name: list wheel files
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
run: ${{ matrix.ls || 'ls -lh' }} wheelhouse/
- name: twine check
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
run: twine check wheelhouse/*
- uses: actions/upload-artifact@v3
if: matrix.os != 'macos' || matrix['python-version'] != '7' # no python37 for macos
with:
path: wheelhouse/*.whl
# build_sdist:
# name: Build source distribution
# runs-on: ubuntu-latest
# - uses: actions/checkout@v3
# - uses: actions/setup-python@v3
# - name: Install Python dependencies
# run: python -m pip install -U maturin cffi
# - uses: actions/upload-artifact@v3
# with:
# path: ./wheelhouse/*.tar.gz
# upload_pypi:
# needs: [build_wheels, build_sdist]