Skip to content

Commit 2a13e1a

Browse files
committed
Add cibuildwheel Android workflow and matrix build
Add a new GitHub Actions workflow (build-wheels-with-cibuildwheel.yml) to build Android wheels using cibuildwheel. Revamp build-wheels.yml into a matrix-based job that supports Android and iOS builds, parameterizes Python versions and NDK, integrates mobile-forge artifacts, installs toolchains (Rust, NDK, iOS targets), runs forge packaging, and publishes built wheels. Also adds conditional artifact uploads for logs/errors and generalizes checkout and setup steps for multi-runner usage.
1 parent cc97b83 commit 2a13e1a

2 files changed

Lines changed: 149 additions & 27 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: wheels-android
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build_android_wheels:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.12" # cibuildwheel runner python; not the target
18+
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: temurin
23+
java-version: "17"
24+
25+
- name: Set up Android SDK
26+
uses: android-actions/setup-android@v3
27+
28+
- name: Build Android wheels
29+
env:
30+
CIBW_PLATFORM: android
31+
CIBW_BUILD: "cp313-android_*"
32+
CIBW_ARCHS_ANDROID: "arm64_v8a x86_64"
33+
ANDROID_API_LEVEL: "24"
34+
run: |
35+
wget https://files.pythonhosted.org/packages/04/24/4b2031d72e840ce4c1ccb255f693b15c334757fc50023e4db9537080b8c4/websockets-16.0.tar.gz
36+
tar xf websockets-16.0.tar.gz
37+
cd websockets-16.0
38+
python -m pip install -U pip cibuildwheel
39+
cibuildwheel --output-dir wheelhouse
40+
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: wheels-android
44+
path: websockets-16.0/wheelhouse/*.whl

.github/workflows/build-wheels.yml

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,122 @@
1-
name: wheels-android
1+
name: Build wheels
22

33
on:
44
push:
55
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
PYTHON_VERSION: "3.13.12"
10+
PYTHON_SHORT_VERSION: "3.13"
11+
MOBILE_FORGE_CACHE_DOWNLOADS_OFF: "1"
12+
NDK_VERSION: r27d
613

714
jobs:
8-
build_android_wheels:
9-
runs-on: ubuntu-latest
15+
build:
16+
name: ${{ matrix.job_name }}
17+
runs-on: ${{ matrix.runner }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
include:
22+
- job_name: "Android: pydantic-core 2.33.2"
23+
runner: ubuntu-latest
24+
forge_arch: android
25+
forge_packages: "pydantic-core:2.33.2"
26+
build_number: "1"
27+
platform: android
28+
- job_name: "iOS: pydantic-core 2.33.2"
29+
runner: macos-latest
30+
forge_arch: iOS
31+
forge_packages: "pydantic-core:2.33.2"
32+
build_number: "1"
33+
platform: ios
1034

1135
steps:
12-
- uses: actions/checkout@v4
36+
- name: Checkout
37+
uses: actions/checkout@v4
1338

1439
- name: Set up Python
1540
uses: actions/setup-python@v5
1641
with:
17-
python-version: "3.12" # cibuildwheel runner python; not the target
18-
19-
- name: Set up JDK
20-
uses: actions/setup-java@v4
21-
with:
22-
distribution: temurin
23-
java-version: "17"
42+
python-version: ${{ env.PYTHON_SHORT_VERSION }}
2443

25-
- name: Set up Android SDK
26-
uses: android-actions/setup-android@v3
27-
28-
- name: Build Android wheels
44+
- name: Build and publish wheels
45+
shell: bash
2946
env:
30-
CIBW_PLATFORM: android
31-
CIBW_BUILD: "cp313-android_*"
32-
CIBW_ARCHS_ANDROID: "arm64_v8a x86_64"
33-
ANDROID_API_LEVEL: "24"
47+
GEMFURY_TOKEN: ${{ secrets.GEMFURY_TOKEN }}
48+
APPVEYOR_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || '' }}
49+
FORGE_ARCH: ${{ matrix.forge_arch }}
50+
FORGE_PACKAGES: ${{ matrix.forge_packages }}
51+
BUILD_NUMBER: ${{ matrix.build_number }}
52+
PLATFORM: ${{ matrix.platform }}
3453
run: |
35-
wget https://files.pythonhosted.org/packages/04/24/4b2031d72e840ce4c1ccb255f693b15c334757fc50023e4db9537080b8c4/websockets-16.0.tar.gz
36-
tar xf websockets-16.0.tar.gz
37-
cd websockets-16.0
38-
python -m pip install -U pip cibuildwheel
39-
cibuildwheel --output-dir wheelhouse
54+
set -euxo pipefail
55+
56+
. .ci/common.sh
57+
export MOBILE_FORGE_ANDROID_SUPPORT_PATH=""
58+
export MOBILE_FORGE_IOS_SUPPORT_PATH=""
59+
60+
if [[ "$PLATFORM" == "android" ]]; then
61+
sudo apt-get update
62+
sudo apt-get install -y sqlite3
63+
64+
python_android_dir="$HOME/projects/python-build/android"
65+
curl -#OL "https://github.com/flet-dev/python-build/releases/download/v${PYTHON_SHORT_VERSION}/python-android-mobile-forge-${PYTHON_SHORT_VERSION}.tar.gz"
66+
mkdir -p "$python_android_dir"
67+
tar -xzf "python-android-mobile-forge-${PYTHON_SHORT_VERSION}.tar.gz" -C "$python_android_dir"
68+
69+
.ci/install_ndk.sh
70+
71+
curl https://sh.rustup.rs -sSf | sh -s -- -y
72+
. "$HOME/.cargo/env"
73+
export PATH="$PATH:$HOME/.cargo/bin"
74+
rustup target add aarch64-linux-android
75+
rustup target add arm-linux-androideabi
76+
rustup target add x86_64-linux-android
77+
rustup target add i686-linux-android
78+
79+
export MOBILE_FORGE_ANDROID_SUPPORT_PATH="$python_android_dir"
80+
else
81+
python_ios_dir="$HOME/projects/python-build/darwin/Python-Apple-support"
82+
curl -#OL "https://github.com/flet-dev/python-build/releases/download/v${PYTHON_SHORT_VERSION}/python-ios-mobile-forge-${PYTHON_SHORT_VERSION}.tar.gz"
83+
mkdir -p "$python_ios_dir"
84+
tar -xzf "python-ios-mobile-forge-${PYTHON_SHORT_VERSION}.tar.gz" -C "$python_ios_dir"
85+
86+
curl https://sh.rustup.rs -sSf | sh -s -- -y
87+
. "$HOME/.cargo/env"
88+
export PATH="$PATH:$HOME/.cargo/bin"
89+
rustup target add aarch64-apple-ios
90+
rustup target add aarch64-apple-ios-sim
91+
rustup target add x86_64-apple-ios
92+
93+
export MOBILE_FORGE_IOS_SUPPORT_PATH="$python_ios_dir"
94+
fi
95+
96+
source ./setup.sh "$PYTHON_VERSION"
97+
export PATH="$PATH:$HOME/.cargo/bin"
98+
99+
IFS=' ' read -r -a packages <<< "$FORGE_PACKAGES"
100+
for package in "${packages[@]}"; do
101+
forge "$FORGE_ARCH" "$package:$BUILD_NUMBER"
102+
done
103+
104+
rm -f dist/bzip2-* dist/xz-* dist/openssl-* dist/libffi-*
105+
106+
if compgen -G "dist/*.whl" > /dev/null; then
107+
publish_to_pypi dist/*.whl
108+
fi
109+
110+
- name: Upload logs on success
111+
if: ${{ success() && hashFiles('logs/*.log') != '' }}
112+
uses: actions/upload-artifact@v4
113+
with:
114+
name: ${{ matrix.platform }}-logs-${{ github.run_id }}-${{ github.run_attempt }}
115+
path: logs/*.log
40116

41-
- uses: actions/upload-artifact@v4
117+
- name: Upload errors on failure
118+
if: ${{ failure() && hashFiles('errors/*.log') != '' }}
119+
uses: actions/upload-artifact@v4
42120
with:
43-
name: wheels-android
44-
path: websockets-16.0/wheelhouse/*.whl
121+
name: ${{ matrix.platform }}-errors-${{ github.run_id }}-${{ github.run_attempt }}
122+
path: errors/*.log

0 commit comments

Comments
 (0)