Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

feat: add support for Android Bionic wheels and update related tests

jakmrocb244973ef0b
diff --git a/needle/agent/fetch.py b/needle/agent/fetch.py
index a912bd3..29aa664 100644
--- a/needle/agent/fetch.py
+++ b/needle/agent/fetch.py
@@ -35,6 +35,8 @@ WHEEL_TAGS = ("macosx_11_0_arm64", "macosx_11_0_x86_64",
"manylinux2014_aarch64", "manylinux2014_x86_64",
"musllinux_1_2_aarch64", "musllinux_1_2_x86_64",
"win_amd64", "win_arm64")
+# Bionic, for Termux. Only the generation 3 engine is built for it.
+ANDROID_TAG = "android_24_arm64_v8a"
PLATFORMS = ("macos-arm64", "linux-x86_64", "linux-arm64", "linux-armv7",
"linux-riscv64", "linux-mipsel", "windows-x86_64", "windows-arm64",
@@ -106,7 +108,7 @@ _ENGINE_ARCHES = {"x86_64": "x86_64", "amd64": "x86_64", "aarch64": "aarch64", "
def _is_android():
- """Android reports itself as Linux but links Bionic, where no published engine loads.
+ """Android reports itself as Linux but links Bionic, where the Linux wheels cannot load.
Termux is the usual way this is reached. ``platform.libc_ver()`` finds no glibc
there, so the Linux path would pick the musl aarch64 wheel and fail to load it.
@@ -122,12 +124,12 @@ def _platform_tag():
arch = "arm64" if machine in ("arm64", "aarch64") else "x86_64"
return "macosx_11_0_" + arch
if _is_android():
- raise RuntimeError(
- "no Needle engine wheel is published for Android (Bionic): the Linux wheels link "
- "glibc or musl, so libneedle fails to load with a missing libm.so.6. The Android "
- "builds ship a static library and the needle CLI (needle download android-arm64), "
- "not a shared library for ctypes; to use the Python API here, build a shared "
- "libneedle for Bionic and point NEEDLE3_LIB_PATH (NEEDLE2_LIB_PATH for Needle 2) at it.")
+ if machine != "aarch64":
+ raise RuntimeError(
+ f"no Needle engine is published for Android on {platform.machine()}; the Android "
+ "engine is built for arm64. Build libneedle for this machine and point "
+ "NEEDLE3_LIB_PATH (NEEDLE2_LIB_PATH for Needle 2) at it.")
+ return ANDROID_TAG
arch = _ENGINE_ARCHES.get(machine)
if arch is None:
# Any other machine (32-bit ARM or x86, riscv64, a 32-bit Python on
@@ -180,7 +182,8 @@ def unpublished_engine_wheels():
listings[repo] = set(list_repo_files(repo))
except Exception:
listings[repo] = set()
- for tag in WHEEL_TAGS:
+ tags = WHEEL_TAGS + (ANDROID_TAG,) if generation == 3 else WHEEL_TAGS
+ for tag in tags:
wheel = engine_wheel(ENGINE_VERSIONS[generation], tag, generation)
if wheel not in listings[repo]:
missing.append(repo + "/" + wheel)
diff --git a/tests/test_fetch.py b/tests/test_fetch.py
index 1496ea0..468a6a4 100644
--- a/tests/test_fetch.py
+++ b/tests/test_fetch.py
@@ -116,6 +116,9 @@ def test_unpublished_engine_wheels_lists_every_missing_tag(monkeypatch):
fetch.engine_wheel(version, tag, generation) for tag in fetch.WHEEL_TAGS)
monkeypatch.setattr("huggingface_hub.list_repo_files",
lambda repo: sorted(published[repo]) + ["needle3.cact"])
+ android = fetch.engine_wheel(fetch.ENGINE_VERSIONS[3], fetch.ANDROID_TAG, 3)
+ assert fetch.unpublished_engine_wheels() == [fetch.ENGINE_REPOS[3] + "/" + android]
+ published[fetch.ENGINE_REPOS[3]].add(android)
assert fetch.unpublished_engine_wheels() == []
repo3 = fetch.ENGINE_REPOS[3]
@@ -137,7 +140,7 @@ def test_a_repo_that_cannot_be_listed_holds_none_of_its_wheels(monkeypatch):
monkeypatch.setattr("huggingface_hub.list_repo_files", refuse)
missing = fetch.unpublished_engine_wheels()
engines = len(fetch.ENGINE_VERSIONS) - len(fetch.WEIGHTS_ONLY)
- assert len(missing) == engines * len(fetch.WHEEL_TAGS)
+ assert len(missing) == engines * len(fetch.WHEEL_TAGS) + 1 # plus the generation 3 Android wheel
def test_release_gate_runs_before_the_publish_step():
@@ -297,7 +300,7 @@ def test_engine_load_falls_back_to_the_other_libc(monkeypatch, tmp_path):
assert loaded["path"].endswith("musl/libneedle.so")
-def test_android_is_refused_instead_of_being_handed_a_glibc_wheel(monkeypatch):
+def test_android_gets_the_bionic_wheel_instead_of_a_glibc_one(monkeypatch):
"""Termux reports Linux/aarch64, so it used to download a wheel Bionic cannot load."""
import platform
from needle.agent import fetch
@@ -310,7 +313,11 @@ def test_android_is_refused_instead_of_being_handed_a_glibc_wheel(monkeypatch):
assert fetch._platform_tag() == "manylinux2014_aarch64"
monkeypatch.setattr(fetch, "_is_android", lambda: True)
- with pytest.raises(RuntimeError, match="Android .Bionic.*libm.so.6.*NEEDLE3_LIB_PATH"):
+ assert fetch._platform_tag() == "android_24_arm64_v8a"
+ assert fetch.other_libc_tag() is None
+
+ monkeypatch.setattr(platform, "machine", lambda: "x86_64")
+ with pytest.raises(RuntimeError, match="Android on x86_64;.*NEEDLE3_LIB_PATH"):
fetch._platform_tag()