From 8961bce62125fccb79cf721765b11d4e47bf9ea0 Mon Sep 17 00:00:00 2001 From: Klaus <41989304+hkk97@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:13:18 +0800 Subject: [PATCH] Create linux.yaml --- .github/workflows/linux.yaml | 253 +++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 .github/workflows/linux.yaml diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml new file mode 100644 index 0000000..2f44981 --- /dev/null +++ b/.github/workflows/linux.yaml @@ -0,0 +1,253 @@ +name: linux +on: push +jobs: + + sdist: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + env: + RUST_TOOLCHAIN: "1.72" # MSRV + steps: + - run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $RUST_TOOLCHAIN -y + - run: rustup default $RUST_TOOLCHAIN + + - uses: actions/checkout@v4 + + - run: python3 -m pip install --user --upgrade pip "maturin>=1,<2" wheel + + - run: maturin build + - run: cargo fetch + - run: mkdir .cargo + + - run: maturin sdist --out=dist + + - run: python3 -m pip install --user dist/rust_x3dh*.tar.gz + env: + CARGO_NET_OFFLINE: "true" + + - name: Store sdist + if: "startsWith(github.ref, 'refs/tags/')" + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + retention-days: 1 + + manylinux_2_17_amd64: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python: [ + { version: '3.12', abi: 'cp312-cp312' }, + { version: '3.11', abi: 'cp311-cp311' }, + { version: '3.10', abi: 'cp310-cp310' }, + { version: '3.9', abi: 'cp39-cp39' }, + { version: '3.8', abi: 'cp38-cp38' }, + ] + env: + PATH: /github/home/.local/bin:/github/home/.cargo/bin:/opt/python/${{ matrix.python.abi }}/bin:/opt/rh/gcc-toolset-12/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + CC: "clang" + CFLAGS: "-O2 -fstrict-aliasing -emit-llvm -flto=full" + LDFLAGS: "-O2 -fstrict-aliasing -emit-llvm -flto=full -fuse-ld=lld -Wl,--as-needed -Wl,-plugin-opt=also-emit-llvm" + RUSTFLAGS: "-C linker=clang -C linker-plugin-lto -C lto=fat -C link-arg=-fuse-ld=lld -Z mir-opt-level=4 -Z virtual-function-elimination -D warnings" + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + container: + image: quay.io/pypa/manylinux_2_28_x86_64:latest + options: --user 0 + steps: + - run: yum install -y clang lld + - run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2024-02-13 --profile minimal -y + - run: rustup component add rust-src --toolchain nightly-2024-02-13-x86_64-unknown-linux-gnu + - uses: actions/checkout@v4 + + - run: python3 -m pip install --user --upgrade pip "maturin>=1,<2" wheel + - run: | + maturin build --release --strip \ + --out=dist \ + --compatibility manylinux_2_17 \ + --interpreter python${{ matrix.python.version }} \ + --target=x86_64-unknown-linux-gnu + - run: python3 -m pip install --user dist/rust_x3dh*.whl + + - run: pytest -s -rxX -v test + env: + PYTHONMALLOC: "debug" + + - run: ./integration/run thread + - run: ./integration/run http + - run: ./integration/run init + + - name: Store wheels + if: "startsWith(github.ref, 'refs/tags/')" + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + retention-days: 1 + + musllinux_1_2: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python: [ + { version: '3.12' }, + { version: '3.11' }, + { version: '3.10' }, + { version: '3.9' }, + { version: '3.8' }, + ] + platform: + - target: aarch64-unknown-linux-musl + arch: aarch64 + platform: linux/arm64 + - target: x86_64-unknown-linux-musl + arch: x86_64 + platform: linux/amd64 + steps: + - uses: actions/checkout@v4 + + - name: Build + uses: PyO3/maturin-action@v1 + env: + CC: "gcc" + CFLAGS: "-O2" + LDFLAGS: "-O2 -flto -Wl,--as-needed" + RUSTFLAGS: "-C target-feature=-crt-static -Z mir-opt-level=4" + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + with: + rust-toolchain: nightly-2024-02-13 + rustup-components: rust-src + target: ${{ matrix.platform.target }} + manylinux: musllinux_1_2 + args: --release --strip --out=dist -i python${{ matrix.python.version }} + + - name: Set up QEMU + if: matrix.platform.arch != 'x86_64' + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:qemu-v8.1.4 + platforms: ${{ matrix.platform.platform }} + + - name: Store wheels + if: "startsWith(github.ref, 'refs/tags/')" + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + retention-days: 1 + + manylinux_2_17_non_amd64: + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + python: [ + { version: '3.12', abi: 'cp312-cp312' }, + { version: '3.11', abi: 'cp311-cp311' }, + { version: '3.10', abi: 'cp310-cp310' }, + { version: '3.9', abi: 'cp39-cp39' }, + { version: '3.8', abi: 'cp38-cp38' }, + ] + target: [ + { + arch: 'aarch64', + cflags: '-O2 -flto', + rustflags: '-Z mir-opt-level=4 -D warnings', + target: 'aarch64-unknown-linux-gnu', + }, + { + arch: 'armv7', + cflags: '-Os -flto -fstrict-aliasing', + rustflags: '-C opt-level=s -Z mir-opt-level=4 -D warnings', + target: 'armv7-unknown-linux-gnueabihf', + }, + { + arch: 'ppc64le', + cflags: '-O2 -flto', + rustflags: '-Z mir-opt-level=4 -D warnings', + target: 'powerpc64le-unknown-linux-gnu', + }, + { + arch: 's390x', + cflags: '-O2 -flto -march=z10', + # no unstable-simd as rotate_elements_left() causes exit 125 in at least QEMU + rustflags: '-Z mir-opt-level=4 -C target-cpu=z10 -D warnings', + target: 's390x-unknown-linux-gnu', + }, + ] + steps: + - uses: actions/checkout@v4 + + - name: Build + uses: PyO3/maturin-action@v1 + env: + PYO3_CROSS_LIB_DIR: "/opt/python/${{ matrix.python.abi }}" + CFLAGS: "${{ matrix.target.cflags }}" + LDFLAGS: "${{ matrix.target.cflags }} -Wl,--as-needed" + CARGO_UNSTABLE_SPARSE_REGISTRY: "true" + RUSTFLAGS: "${{ matrix.target.rustflags }}" + with: + target: ${{ matrix.target.target }} + rust-toolchain: nightly-2024-02-13 + rustup-components: rust-src + manylinux: auto + args: --release --strip --out=dist --features=${{ matrix.target.features }} -i python${{ matrix.python.version }} + + - uses: uraimo/run-on-arch-action@v2 + name: Test + with: + arch: ${{ matrix.target.arch }} + distro: ubuntu22.04 + githubToken: ${{ github.token }} + install: | + export TZ=UTC + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y --no-install-recommends software-properties-common gpg gpg-agent curl + add-apt-repository ppa:deadsnakes/ppa + apt-get update + apt-get install -y python${{ matrix.python.version }}-dev python${{ matrix.python.version }}-venv + run: | + python${{ matrix.python.version }} -m venv venv + venv/bin/pip install -U pip wheel + venv/bin/pip install -r test/requirements.txt + venv/bin/pip install rust_x3dh --no-index --find-links dist/ --force-reinstall + venv/bin/python -m pytest -s -rxX -v test + + - name: Store wheels + if: "startsWith(github.ref, 'refs/tags/')" + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + retention-days: 1 + + pypi: + name: PyPI + permissions: + # trusted publisher + id-token: write + contents: write + runs-on: ubuntu-22.04 + if: "startsWith(github.ref, 'refs/tags/')" + needs: [ manylinux_2_17_amd64, manylinux_2_17_non_amd64, musllinux_1_2, sdist ] + steps: + - uses: actions/download-artifact@v3 + with: + name: wheels + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - run: pip install pip "maturin>=1,<2" + - run: ls -1 . + - name: deploy wheel + run: maturin upload --skip-existing --username "$MATURIN_USERNAME" *.whl + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} + - name: deploy sdist + run: maturin upload --skip-existing --username "$MATURIN_USERNAME" *.tar.gz + env: + MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}