Skip to content

feat(android): Add wasmi fallback for targets without cranelift support (arm32, browser-WASM) #95

@metavacua

Description

@metavacua

Summary

Building for arm-linux-androideabi (Android 32-bit ARM) is blocked by a hard limitation in the wasmtime dependency.

Root cause

larql-inference depends unconditionally on wasmtime with the cranelift feature:

# crates/larql-inference/Cargo.toml
wasmtime = { version = "29", default-features = false, features = ["cranelift", "runtime"] }

Cranelift (wasmtime's JIT compiler backend) has no 32-bit ARM backend. The build fails immediately at the cranelift-codegen build script:

error: failed to run custom build command for `cranelift-codegen v0.116.1`
thread 'main' panicked: error when identifying target: "no supported isa found for arch `arm`"

Cranelift supports: x86_64, aarch64, s390x, riscv64. It does not and has no plans to support arm (32-bit).

Required prerequisite (any path)

wasmtime must be made optional in larql-inference and excluded on 32-bit ARM. model-compute already does this with its wasm feature flag — the pattern exists:

[features]
wasm-experts = ["dep:wasmtime", "dep:wasmtime-wasi", "dep:anyhow"]

All call sites in larql-inference that use wasmtime would then need #[cfg(feature = "wasm-experts")] guards, with the WASM expert registry path degrading gracefully on unsupported targets.

Alternative runtime paths

Option A — wasmi (pure-Rust interpreter)

  • wasmi is a fully interpreted WASM runtime with zero native-code generation — no Cranelift, no LLVM dependency
  • Works on any architecture Rust targets, including arm-linux-androideabi
  • Drop-in at the API level for the WASM expert registry use case
  • Trade-off: slower execution (interpreted vs JIT), but for the expert dispatch path this may be acceptable
  • Lowest complexity path to unblock the 32-bit Android build

Option B — wasmer + LLVM backend

  • Wasmer supports multiple backends; its LLVM backend uses LLVM for code generation, and LLVM does have an ARMv7 target
  • More complex: requires LLVM to be available and cross-compilable to arm-linux-androideabi
  • More informative for the attention mechanism decomposition work in larql-inference — the LLVM IR for WASM expert modules exposes the full lowering of attention kernels, which can surface optimisation opportunities and structural problems not visible through Cranelift's opaque ISel
  • Higher setup cost, but produces richer diagnostic output for mechanistic interpretability tooling

Recommendation

Start with Option A (wasmi) to unblock the build, keeping the WASM expert feature behind a flag. Option B (wasmer+LLVM) is a worthwhile follow-on if the attention decomposition analysis requires finer-grained IR visibility into expert execution.

Context

  • aarch64-linux-android builds successfully (PR feat(android): enable aarch64-linux-android cross-compilation #94)
  • Most Android devices shipping today are 64-bit; 32-bit ARM Android support is only needed for pre-2014 era devices (Cortex-A7/A9)
  • 32-bit ARM is targeted due to its similarity to WASM sandbox environments which are on the way to in browser build + test + use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions