Skip to content

Commit

Permalink
restore working cross-rs-based workflow
Browse files Browse the repository at this point in the history
see PyO3/maturin#2461 for the problem with
manylinux containers
  • Loading branch information
joe-p committed Feb 6, 2025
1 parent b922e78 commit 4b03993
Showing 1 changed file with 62 additions and 51 deletions.
113 changes: 62 additions & 51 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,42 @@ env:
CRATE_PATH: crates/algo_models_ffi

jobs:
# build_and_test:
# defaults:
# run:
# shell: bash
# runs-on: ${{ matrix.target.runner }}
# strategy:
# matrix:
# target:
# # name: The name of the target passed to cargo build
# # runner: The GitHub runner to use
# - name: x86_64-pc-windows-msvc
# runner: windows-latest
# - name: x86_64-apple-darwin
# runner: macos-13
# - name: aarch64-apple-darwin
# runner: macos-latest
# - name: x86_64-unknown-linux-gnu
# runner: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# - uses: actions/setup-python@v5
# with:
# python-version: '3.13'
# cache: 'pip' # caching pip dependencies
# - run: pip install maturin
# - name: Install python dependencies
# run: pip install -r ${{ env.CRATE_PATH }}/tests/py/requirements.txt
# - name: maturin build
# run: cd ${{ env.CRATE_PATH }} && maturin build --target ${{ matrix.target.name }}
# - name: pytest
# run: |
# set -e
# pip install target/wheels/*.whl
# cd ${{ env.CRATE_PATH }}
# pytest

build_and_test:
defaults:
run:
shell: bash
runs-on: ${{ matrix.target.runner }}
strategy:
matrix:
target:
# name: The name of the target passed to cargo build
# runner: The GitHub runner to use
- name: x86_64-pc-windows-msvc
runner: windows-latest
- name: x86_64-apple-darwin
runner: macos-13
- name: aarch64-apple-darwin
runner: macos-latest
- name: x86_64-unknown-linux-gnu
runner: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip' # caching pip dependencies
- run: pip install maturin
- name: Install python dependencies
run: pip install -r ${{ env.CRATE_PATH }}/tests/py/requirements.txt
- name: maturin build
run: cd ${{ env.CRATE_PATH }} && maturin build --target ${{ matrix.target.name }}
- name: pytest
run: |
set -e
pip install target/wheels/*.whl
cd ${{ env.CRATE_PATH }}
pytest
cross_build_and_test:
defaults:
run:
Expand All @@ -72,17 +71,17 @@ jobs:
# runner: The GitHub runner to use
# arch: The architecture to use when testing the built package
# distro: The distro to use when testing the built package. Should use alpine_latest for musl and ubuntu_latest for glibc
# container: The container to use to build against the target
# - name: aarch64-unknown-linux-musl
# runner: ubuntu-22.04
# arch: aarch64
# distro: alpine_latest
# container: ghcr.io/cross-rs/aarch64-unknown-linux-musl:0.2.5
# container: The container (typically from cross-rs) to use to build against the target
- name: aarch64-unknown-linux-musl
runner: ubuntu-22.04
arch: aarch64
distro: alpine_latest
container: ghcr.io/cross-rs/aarch64-unknown-linux-musl:0.2.5
- name: aarch64-unknown-linux-gnu
runner: ubuntu-22.04
arch: aarch64
distro: ubuntu_latest
container: messense/manylinux2014-cross:aarch64
container: ghcr.io/cross-rs/aarch64-unknown-linux-gnu:0.2.5

steps:
- uses: actions/checkout@v4
Expand All @@ -94,10 +93,16 @@ jobs:
docker run --name build-container \
-d \
-v ${{ github.workspace }}:/workspace \
-e MISE_DATA_DIR="/mise" \
-e MISE_CONFIG_DIR="/mise" \
-e MISE_CACHE_DIR="/mise/cache" \
-e MISE_INSTALL_PATH="/usr/local/bin/mise" \
-e CARGO_HOME="/usr/local" \
${{ matrix.target.container }} \
tail -f /dev/null
# "Install Rustup" through "Install maturin" can be done at image build time
# We'd just need to create our own image based on the respective matrix.target.container
# Or create an action similar to run-on-arch that caches install steps
- name: Install Rustup
env:
SCRIPT: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
Expand All @@ -108,14 +113,24 @@ jobs:
SCRIPT: rustup target add ${{ matrix.target.name }}
run: docker exec build-container bash -c "$SCRIPT"

- name: Install mise
env:
SCRIPT: curl https://mise.run | sh
run: docker exec build-container bash -c "$SCRIPT"

- name: Install python (mise)
env:
SCRIPT: mise settings set python.compile false && mise use -g python
run: docker exec build-container bash -c "$SCRIPT"

- name: Install maturin
env:
SCRIPT: python3.10 -m pip install maturin[patchelf]
SCRIPT: mise x -- pip install maturin[patchelf]
run: docker exec build-container bash -c "$SCRIPT"

- name: maturin build
env:
SCRIPT: cd /workspace/${{ env.CRATE_PATH }} && maturin build --release --target ${{ matrix.target.name }}
SCRIPT: cd /workspace/${{ env.CRATE_PATH }} && mise x -- maturin build --release --target ${{ matrix.target.name }}
run: docker exec build-container bash -c "$SCRIPT"

- name: Pytest (alpine)
Expand All @@ -133,13 +148,11 @@ jobs:
# no secrets are present in the container state or logs.
install: |
apk add --no-cache python3 py3-pip
run: |
pip install --break-system-packages target/wheels/*.whl
cd ${{ env.CRATE_PATH }}
pip install --break-system-packages -r tests/py/requirements.txt
pytest
- name: Pytest
if: matrix.target.distro != 'alpine_latest'
uses: uraimo/run-on-arch-action@v2
Expand All @@ -151,7 +164,6 @@ jobs:
MISE_CONFIG_DIR: /mise
MISE_CACHE_DIR: /mise/cache
MISE_INSTALL_PATH: /usr/local/bin/mise
# Install some dependencies in the container. This speeds up builds if
# you are also using githubToken. Any dependencies installed here will
# be part of the container image that gets cached, so subsequent
Expand All @@ -167,7 +179,6 @@ jobs:
export MISE_VERSION="v2025.1.14"
curl https://mise.run | sh
mise settings set python.compile false && mise use -g python
run: |
mise x -- pip install target/wheels/*.whl
cd ${{ env.CRATE_PATH }}
Expand Down

0 comments on commit 4b03993

Please sign in to comment.