Skip to content

Commit 5b0571d

Browse files
committed
fix(main/wasmtime): implement support for 32-bit ARM Android
- Concepts used to implement `listenfd-32-bit-android.diff` based on similar patches found in other packages like `fish` and `below` - `S_IFMT` is not the same type as `st_mode` on 32-bit Android - `socklen_t` should be passed to `getsockname()` and `getsockopt()`, not `unsigned int` - Based on this comment, `wasmtime` now has a codepath that supports 32-bit ARM: bytecodealliance/wasmtime#1173 (comment) - This build of `wasmtime` has been tested on a 32-bit ARM Android device to run a precompiled `wasi-hello-world.wasm` that was copied from a different device, and is working successfully: - The `wasi-hello-world.wasm` was compiled using a GNU/Linux PC running the `cargo install cargo-component` tool via a Rust toolchain https://github.com/bytecodealliance/cargo-component ``` ~ $ wasmtime wasi-hello-world.wasm Hello, world! ~ $ uname -a Linux localhost 3.4.112-Lineage-g716f00ee2e8 #1 SMP PREEMPT Sun Oct 13 11:16:54 CDT 2019 armv7l Android ~ $ ``` - 32-bit x86 still has an error which is different and does not appear during the build for 32-bit ARM
1 parent 2eae682 commit 5b0571d

2 files changed

Lines changed: 69 additions & 19 deletions

File tree

packages/wasmtime/build.sh

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@ TERMUX_PKG_LICENSE="Apache-2.0"
44
TERMUX_PKG_LICENSE_FILE="LICENSE"
55
TERMUX_PKG_MAINTAINER="@termux"
66
TERMUX_PKG_VERSION="38.0.3"
7+
TERMUX_PKG_REVISION=1
78
TERMUX_PKG_SRCURL=git+https://github.com/bytecodealliance/wasmtime
89
TERMUX_PKG_GIT_BRANCH="v${TERMUX_PKG_VERSION}"
910
TERMUX_PKG_BUILD_IN_SRC=true
1011
TERMUX_PKG_AUTO_UPDATE=true
1112

12-
# arm:
13-
# ```
14-
# error: failed to run custom build command for `cranelift-codegen v0.90.1 (/home/builder/.termux-build/wasmtime/src/cranelift/codegen)`
15-
#
16-
# Caused by:
17-
# process didn't exit successfully: `/home/builder/.termux-build/wasmtime/src/target/release/build/cranelift-codegen-6ca5eab3f38213ac/build-script-build` (exit status: 101)
18-
# --- stderr
19-
# thread 'main' panicked at 'error when identifying target: "no supported isa found for arch `armv7`"', cranelift/codegen/build.rs:42:53
20-
# ```
21-
#
22-
# arm, i686:
23-
# ```
24-
# error[E0308]: mismatched types
25-
# --> /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/listenfd-1.0.0/src/unix.rs:14:25
26-
# |
27-
# 14 | (stat.st_mode & libc::S_IFMT) == libc::S_IFSOCK
28-
# | ^^^^^^^^^^^^ expected `u32`, found `u16`
29-
# ```
30-
TERMUX_PKG_EXCLUDED_ARCHES="arm, i686"
13+
# = note: ld.lld: error: relocation R_386_32 cannot be used against local symbol;
14+
# recompile with -fPIC
15+
# >>> defined in /home/builder/.termux-build/wasmtime/src/target/
16+
# i686-linux-android/release/deps/libwasmtime_internal_fiber-ed766d87e782b761.rlib
17+
# (wasmtime_internal_fiber-ed766d87e782b761.wasmtime_internal_fiber.32287cf82a9b7e1f-cgu.
18+
# 0.rcgu.o)
19+
# >>> referenced by wasmtime_internal_fiber.32287cf82a9b7e1f-cgu.0
20+
# >>> wasmtime_internal_fiber-ed766d87e782b761.
21+
# wasmtime_internal_fiber.32287cf82a9b7e1f-cgu.0.rcgu.o:(wasmtime_internal_fiber::
22+
# stackswitch::x86::wasmtime_fiber_init::hd48a3380a323ed84) in archive
23+
# /home/builder/.termux-build/wasmtime/src/target/i686-linux-android/
24+
# release/deps/libwasmtime_internal_fiber-ed766d87e782b761.rlib
25+
# clang: error: linker command failed with exit code 1
26+
# (use -v to see invocation)
27+
TERMUX_PKG_EXCLUDED_ARCHES="i686"
3128

3229
termux_pkg_auto_update() {
3330
local e=0
@@ -58,6 +55,21 @@ termux_pkg_auto_update() {
5855

5956
termux_step_pre_configure() {
6057
termux_setup_rust
58+
59+
cargo vendor
60+
find ./vendor \
61+
-mindepth 1 -maxdepth 1 -type d \
62+
! -wholename ./vendor/listenfd \
63+
-exec rm -rf '{}' \;
64+
65+
local patch="$TERMUX_PKG_BUILDER_DIR/listenfd-32-bit-android.diff"
66+
local dir="vendor/listenfd"
67+
echo "Applying patch: $patch"
68+
patch -p1 -d "$dir" < "${patch}"
69+
70+
echo "" >> Cargo.toml
71+
echo '[patch.crates-io]' >> Cargo.toml
72+
echo 'listenfd = { path = "./vendor/listenfd" }' >> Cargo.toml
6173
}
6274

6375
termux_step_make() {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--- a/src/unix.rs
2+
+++ b/src/unix.rs
3+
@@ -7,6 +7,7 @@ use std::os::unix::net::{UnixDatagram, UnixListener};
4+
5+
pub type FdType = RawFd;
6+
7+
+#[cfg(not(all(target_os = "android", target_pointer_width = "32")))]
8+
fn is_sock(fd: FdType) -> bool {
9+
unsafe {
10+
let mut stat: libc::stat = mem::zeroed();
11+
@@ -15,6 +16,15 @@ fn is_sock(fd: FdType) -> bool {
12+
}
13+
}
14+
15+
+#[cfg(all(target_os = "android", target_pointer_width = "32"))]
16+
+fn is_sock(fd: FdType) -> bool {
17+
+ unsafe {
18+
+ let mut stat: libc::stat = mem::zeroed();
19+
+ libc::fstat(fd as libc::c_int, &mut stat);
20+
+ (stat.st_mode as u16 & libc::S_IFMT) == libc::S_IFSOCK
21+
+ }
22+
+}
23+
+
24+
fn validate_socket(
25+
fd: FdType,
26+
sock_fam: libc::c_int,
27+
@@ -30,9 +40,9 @@ fn validate_socket(
28+
29+
let is_valid = unsafe {
30+
let mut ty: libc::c_int = mem::zeroed();
31+
- let mut ty_len = mem::size_of_val(&ty) as libc::c_uint;
32+
+ let mut ty_len = mem::size_of_val(&ty) as libc::socklen_t;
33+
let mut sockaddr: libc::sockaddr = mem::zeroed();
34+
- let mut sockaddr_len = mem::size_of_val(&sockaddr) as libc::c_uint;
35+
+ let mut sockaddr_len = mem::size_of_val(&sockaddr) as libc::socklen_t;
36+
libc::getsockname(fd, &mut sockaddr, &mut sockaddr_len) == 0
37+
&& libc::getsockopt(
38+
fd,

0 commit comments

Comments
 (0)