Skip to content

Commit c2cb6b5

Browse files
committed
BLD: cross-compilation for android using cibuildwheel
Related to: numpy#27698.
1 parent 583993f commit c2cb6b5

4 files changed

Lines changed: 649 additions & 0 deletions

File tree

‎pyproject.toml‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,29 @@ repair-wheel-command = "bash -el ./tools/wheels/repair_windows.sh {wheel} {dest_
236236
# This does not work, use CIBW_ENVIRONMENT_WINDOWS
237237
environment = {PKG_CONFIG_PATH="./.openblas"}
238238

239+
[tool.cibuildwheel.android]
240+
# Architectures to build for Android
241+
# Use cibuildwheel's actual Android architecture names
242+
archs = ["arm64_v8a", "x86_64"] # armv7l not supported yet
243+
# We can't run tests on the host, so we skip them
244+
test-command = ""
245+
# We need a different before-build script for Android
246+
# This script would be responsible for setting up the Android NDK
247+
# and any other dependencies. You will need to create this script.
248+
before-build = "bash {project}/tools/wheels/cibw_before_build_android.sh {project}"
249+
# Use a custom repair command that ensures proper wheel tagging
250+
repair-wheel-command = "bash ./tools/wheels/repair_android_wheel.sh {wheel} {dest_dir}"
251+
252+
[tool.cibuildwheel.android.environment]
253+
ANDROID_API_LEVEL = "30"
254+
255+
[tool.cibuildwheel.android.config-settings]
256+
setup-args = [
257+
"--cross-file=/tmp/android_current.meson.cross",
258+
"-Dblas=none",
259+
"-Dlapack=none"
260+
]
261+
239262
[[tool.cibuildwheel.overrides]]
240263
select = ["*-win32"]
241264
config-settings = {setup-args = ["--vsenv", "-Dallow-noblas=true"], build-dir="build"}
@@ -277,3 +300,8 @@ cli = 'vendored-meson/meson/meson.py'
277300
".spin/cmds.py:check_tutorials",
278301
]
279302
"Metrics" = [".spin/cmds.py:bench"]
303+
304+
[tool.uv.workspace]
305+
members = [
306+
"android_test",
307+
]

‎tools/ci/android.meson.cross‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Meson cross file for Android
3+
#
4+
# This file defines the toolchain for Android cross-compilation.
5+
# It assumes that environment variables like CC, CXX, CFLAGS, CXXFLAGS, etc.,
6+
# are set by the calling environment (e.g., a cibuildwheel before-build script)
7+
# to point to the correct NDK tools and include the correct target flags.
8+
#
9+
10+
[binaries]
11+
pkg-config = 'pkg-config'
12+
13+
[host_machine]
14+
system = 'android'
15+
cpu_family = 'aarch64' # This is a placeholder, the build environment should target the correct arch
16+
cpu = 'aarch64'
17+
endian = 'little'
18+
19+
[properties]
20+
# This tells Meson not to try running compiled binaries on the host.
21+
needs_exe_wrapper = true

0 commit comments

Comments
 (0)