Skip to content

Commit 1ba7b74

Browse files
authored
Merge pull request #289 from mhsmith/android
Add Android wheels
2 parents 3c821d6 + ea560de commit 1ba7b74

14 files changed

Lines changed: 186 additions & 155 deletions

‎.github/workflows/posix.yml‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020

2121
jobs:
2222
build:
23+
name: ${{ matrix.MB_ML_LIBC }}_${{ matrix.PLAT}}, ${{ matrix.INTERFACE64 == '1' && '64' || '32' }}
2324
runs-on: ${{ matrix.os }}
2425
defaults:
2526
run:
@@ -57,12 +58,15 @@ jobs:
5758
- { os: ubuntu-24.04-arm, PLAT: riscv64, INTERFACE64: '0', MB_ML_VER: '_2_39', MB_ML_LIBC: manylinux}
5859
- { os: ubuntu-24.04-arm, PLAT: riscv64, INTERFACE64: '1', MB_ML_VER: '_2_39', MB_ML_LIBC: manylinux}
5960

61+
- { os: ubuntu-latest, PLAT: x86_64, INTERFACE64: '0', MB_ML_LIBC: android}
62+
- { os: ubuntu-latest, PLAT: x86_64, INTERFACE64: '1', MB_ML_LIBC: android}
63+
64+
- { os: ubuntu-latest, PLAT: arm64_v8a, INTERFACE64: '0', MB_ML_LIBC: android}
65+
- { os: ubuntu-latest, PLAT: arm64_v8a, INTERFACE64: '1', MB_ML_LIBC: android}
66+
6067
env:
6168
NIGHTLY: ${{ inputs.publish == false && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }}
62-
MB_ML_LIBC: ${{ matrix.MB_ML_LIBC }}
63-
MB_ML_VER: ${{ matrix.MB_ML_VER }}
6469
INTERFACE64: ${{ matrix.INTERFACE64 }}
65-
PLAT: ${{ matrix.PLAT }}
6670

6771
steps:
6872
- uses: actions/checkout@v6.0.1
@@ -82,10 +86,6 @@ jobs:
8286
with:
8387
platforms: all
8488

85-
- name: Print some Environment variable
86-
run: |
87-
echo "PLAT: ${PLAT}"
88-
8989
# - name: Setup tmate session
9090
# if: ${{ failure() }}
9191
# uses: mxschmitt/action-tmate@v3
@@ -96,11 +96,12 @@ jobs:
9696
uses: pypa/cibuildwheel@v4.1.0
9797
timeout-minutes: 60
9898
with:
99+
# For Android, cibuildwheel has a minimum of Python 3.13, but the exact version
100+
# doesn't matter because setup.py will replace the tag with "py3".
101+
only: "cp313-${{ matrix.MB_ML_LIBC }}_${{matrix.PLAT}}"
99102
output-dir: dist
100103
env:
101-
CIBW_ARCHS: ${{matrix.PLAT}}
102104
CIBW_BUILD_VERBOSITY: 1
103-
CIBW_BUILD: "cp39-${{ matrix.MB_ML_LIBC }}_${{matrix.PLAT}}"
104105

105106
CIBW_MANYLINUX_I686_IMAGE: ${{ matrix.MB_ML_LIBC }}${{matrix.MB_ML_VER}}
106107
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.MB_ML_LIBC }}${{matrix.MB_ML_VER}}

‎.github/workflows/windows.yml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,14 @@ jobs:
119119
rm local/scipy_openblas64/lib/*.a
120120
rm -f local/scipy_openblas64/lib/*.exp # may not exist?
121121
rm local/scipy_openblas64/lib/*.def
122-
rm -rf local/scipy_openblas64/lib/pkgconfig
123122
if [[ -d local/scipy_openblas64/64 ]]; then
124123
rm -rf local/scipy_openblas64/64
125124
else
126125
rm -rf local/scipy_openblas64/32
127126
fi
128127
sed -e "s/bin/lib/" -i local/scipy_openblas64/lib/cmake/openblas/OpenBLASConfig.cmake
129128
sed -e "s/dll/lib/" -i local/scipy_openblas64/lib/cmake/openblas/OpenBLASConfig.cmake
130-
mkdir local/scipy_openblas64/lib/pkgconfig
129+
131130
if [[ "${INTERFACE64}" != "1" ]]; then
132131
mv local/scipy_openblas64 local/scipy_openblas32
133132
# rewrite the name of the project to scipy-openblas32
@@ -138,10 +137,10 @@ jobs:
138137
sed -e "s/cflags =.*/cflags = '-DBLAS_SYMBOL_PREFIX=scipy_'/" -i local/scipy_openblas32/__init__.py
139138
sed -e "s/openblas64/openblas32/" -i local/scipy_openblas32/__init__.py
140139
sed -e "s/openblas64/openblas32/" -i local/scipy_openblas32/__main__.py
141-
PYTHONPATH=$PWD/local python -c "import scipy_openblas32 as s; print(s.get_pkg_config(use_prefix=True))" > local/scipy_openblas32/lib/pkgconfig/scipy-openblas.pc
142-
else
143-
PYTHONPATH=$PWD/local python -c "import scipy_openblas64 as s; print(s.get_pkg_config(use_prefix=True))" > local/scipy_openblas64/lib/pkgconfig/scipy-openblas.pc
144140
fi
141+
142+
source tools/get_pkg_config.sh
143+
145144
echo "" >> LICENSE.txt
146145
echo "----" >> LICENSE.txt
147146
echo "" >> LICENSE.txt

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ local/scipy_openblas64/*.so
1818
local/scipy_openblas64/*.pyd
1919
local/scipy_openblas64/*.dylib
2020
objconv/
21+
wheelhouse/

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## OpenBLAS v0.3.34 (v0.3.34)
22

3+
### 0.3.34.481.2 (2026-11-01)
4+
5+
- Add Android wheels
6+
37
### 0.3.34.481.1 (2026-10-29)
48

59
- Add a weekly scheduled run to both Windows workflows against OpenBLAS HEAD.

‎build-openblas.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#! /bin/bash
22

33
set -xeo pipefail
4+
5+
# Check the required environment variables are set.
6+
: ${MB_ML_LIBC:?}
7+
: ${PLAT:?}
8+
49
source tools/build_steps.sh
510
echo "------ BEFORE BUILD ---------"
611
before_build

‎ci-before-build.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ fi
2929
export OPENBLAS_VERSION=$version
3030
echo "creating wheel from $OPENBLAS_COMMIT (NIGHTLY is $NIGHTLY)"
3131

32+
libc_plat=${CIBUILDWHEEL_BUILD_IDENTIFIER#*-}
33+
MB_ML_LIBC=${libc_plat%%_*}
34+
PLAT=${libc_plat#*_}
35+
36+
BUILD_PREFIX="$(pwd)/build/prefix/$libc_plat"
37+
rm -rf "$BUILD_PREFIX"
38+
mkdir -p "$BUILD_PREFIX"
39+
40+
# On emulated architectures, RUNNER_ARCH makes manylinux-install-clang install a
41+
# compiler for the native architecture, which will be much faster.
3242
case "$PLAT" in
3343
loongarch64|ppc64le|s390x|riscv64)
3444
manylinux-install-clang -v 21.1.6.0

‎ci-repair-wheel.sh‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#! /bin/bash
22
set -xe
33

4-
PYTHON=${PYTHON:-python3.9}
5-
64
if [ $(uname) == "Darwin" ]; then
7-
$PYTHON -m pip install delocate
5+
python3 -m pip install delocate
86
# move the mis-named scipy_openblas64-none-any.whl to a platform-specific name
97
# if [ "${PLAT}" == "arm64" ]; then
108
# for f in $2/*.whl; do mv $f "${f/%any.whl/macosx_11_0_$PLAT.whl}"; done

‎ci-test.sh‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
#!/bin/bash
2-
# Test that the wheel works with a different python
32
set -xe
43

5-
if [ "${PLAT}" == "arm64" ]; then
6-
# Cannot test
7-
exit 0
8-
fi
9-
10-
PYTHON=python3.9
11-
if [ "$(uname)" == "Darwin" -a "${PLAT}" == "x86_64" ]; then
12-
which python3.9
13-
PYTHON="arch -x86_64 python3.9"
4+
PYTHON=python3
5+
if [ "$CIBUILDWHEEL_BUILD_IDENTIFIER" = "macosx_x86_64" ]; then
6+
PYTHON="arch -x86_64 python3"
147
fi
158

169
# Make sure the module works and that the version strings match

‎local/scipy_openblas64/__init__.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ctypes
66
import os
77
from pathlib import Path
8+
import re
89
import sys
910
from textwrap import dedent
1011
import platform
@@ -91,11 +92,20 @@ def get_pkg_config(use_preloading=False, use_prefix=False):
9192
# Don't use `$prefix` since the file may be located outside the package tree
9293
libdir = get_lib_dir()
9394
incdir = get_include_dir()
95+
96+
variables = {}
97+
with open(f"{get_lib_dir()}/pkgconfig/scipy-openblas.pc") as pc_file:
98+
for line in pc_file:
99+
# The CMake build used by Windows ARM64 produces a Version: keyword but not
100+
# a version= variable, so parse both kinds of line.
101+
if match := re.fullmatch(r"(.+?)[:=](.*)", line.strip()):
102+
variables[match[1].strip()] = match[2].strip()
103+
94104
return dedent(f"""\
95105
libdir={libdir}
96106
includedir={incdir}
97-
openblas_config= {get_openblas_config()}
98-
version={get_openblas_config().split(" ")[1]}
107+
openblas_config= {variables["openblas_config"]}
108+
version={variables.get("version") or variables["Version"]}
99109
extralib={extralib}
100110
Name: openblas
101111
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
@@ -146,5 +156,10 @@ def get_openblas_config():
146156
bytes = openblas_config()
147157
return bytes.decode("utf8")
148158

149-
# Import the DLL which will make the namespace available to NumPy/SciPy
150-
get_openblas_config()
159+
160+
if "CIBUILDWHEEL" in os.environ and sys.platform == "android":
161+
# We're cross-compiling, so we can't load the library.
162+
pass
163+
else:
164+
# Import the DLL which will make the namespace available to NumPy/SciPy
165+
get_openblas_config()

‎pyproject.toml‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"
99
[project]
1010
name = "scipy-openblas64"
1111
# 0.3.34-481-g5137bb62
12-
version = "0.3.34.481.1"
12+
version = "0.3.34.481.2"
1313
requires-python = ">=3.7"
1414
description = "Provides OpenBLAS for python packaging"
1515
readme = "README.md"
@@ -45,15 +45,31 @@ before-build = "bash ci-before-build.sh"
4545
repair-wheel-command = "bash ci-repair-wheel.sh {dest_dir} {wheel}"
4646
test-command = "cd {package} && bash ci-test.sh"
4747
environment-pass = [
48-
"OPENBLAS_COMMIT",
4948
"NIGHTLY",
50-
"MB_ML_LIBC",
51-
"MB_ML_VER",
5249
"INTERFACE64",
53-
"BUILD_DIR",
54-
"PLAT",
55-
"OS-NAME",
50+
51+
# On emulated architectures, RUNNER_ARCH makes manylinux-install-clang install a
52+
# compiler for the native architecture, which will be much faster.
5653
"RUNNER_ARCH",
5754
]
55+
56+
[tool.cibuildwheel.android]
57+
# The Linux code in ci-repair-wheel.sh isn't relevant to Android, so use the default
58+
# repair command from the cibuildwheel documentation.
59+
repair-wheel-command = "auditwheel repair --ldpaths {ldpaths} -w {dest_dir} {wheel}"
60+
61+
# Mobile platforms only support Python test-commands, not shell scripts.
62+
test-command = """python -c '
63+
import runpy
64+
65+
def run_module(mod_name):
66+
runpy.run_module(mod_name, run_name="__main__", alter_sys=True)
67+
68+
try:
69+
run_module("scipy_openblas32")
70+
except ImportError:
71+
run_module("scipy_openblas64")
72+
'"""
73+
5874
[project.entry-points.pkg_config]
5975
scipy-openblas = 'scipy_openblas64.lib.pkgconfig'

0 commit comments

Comments
 (0)