wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Add support for Android NDK

Open leeveel opened this issue 4 years ago • 10 comments

Describe the bug

device: x86_64-linux os: centos7.7 wasmer version: 1.0.1,1.0.2, master cmd: make build-capi build tool: https://github.com/bbqsrc/cargo-ndk I got these errors for aarch64-linux-android on all wamser version:

   Compiling wasmer-c-api v1.0.2 (/data/wasmer-master/lib/c-api)
error: unsupported platform
   --> lib/vm/src/trap/traphandlers.rs:275:21
    |
275 |                     compile_error!("unsupported platform");
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: no method named `si_addr` found for struct `siginfo_t` in the current scope
   --> lib/vm/src/trap/traphandlers.rs:119:43
    |
119 |                     let addr = (*siginfo).si_addr() as usize;
    |                                           ^^^^^^^ method not found in `siginfo_t`

error[E0308]: mismatched types
   --> lib/vm/src/trap/traphandlers.rs:197:52
    |
197 |         unsafe fn get_pc(cx: *mut libc::c_void) -> *const u8 {
    |                   ------                           ^^^^^^^^^ expected *-ptr, found `()`
    |                   |
    |                   implicitly returns `()` as its body has no tail or `return` expression
    |
    = note: expected raw pointer `*const u8`
                 found unit type `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `wasmer-vm`

leeveel avatar Feb 07 '21 15:02 leeveel

Hello,

As the error says, the targeted platform isn't supported yet by the runtime. What's your usecase or project :-)?

Hywan avatar Feb 22 '21 08:02 Hywan

@Hywan Thanks for your replay. I want to use wasmer for embedded-use in unity3d game.

leeveel avatar Feb 22 '21 09:02 leeveel

And this game runs on an Android platform, is that correct?

Hywan avatar Feb 22 '21 09:02 Hywan

Yes, It's just like lua. my main purpose is do some thing like hot reload scripts to fix game bugs on android/ios

leeveel avatar Feb 22 '21 09:02 leeveel

Let me see if we can push this idea further. cc @syrusakbary

Hywan avatar Feb 22 '21 10:02 Hywan

I would also really love to see Android support.

There are many use cases. The main benefit is that it would make using C or Rust code in Android apps much, much easier, because you wouldn't need to deal with the hassle of handling native compilation.

This would especially be true if https://github.com/wasmerio/wasmer-java had pre-built JARs for the various Android architectures.

Please also note that Android has multiple ABIs. (See https://developer.android.com/ndk/guides/abis )

By far the most important one is armeabi-v7a, followed by arm64-v8a.

theduke avatar Jul 05 '21 21:07 theduke

Thank you for your comment.

Hywan avatar Jul 06 '21 08:07 Hywan

This would also support building Rust libs / apps that depend on wasmer on Termux. e.g. zellij uses wasm plugins

dead10ck avatar Jan 23 '22 14:01 dead10ck

Would love to see support for Android. For me the build error is mman::shm_open not being available for Android. My use case is to make the Solidity compiler portable across all platforms supported by wasmer by embedding the wasm module.

xJonathanLEI avatar Apr 12 '22 13:04 xJonathanLEI

+1

caiiiycuk avatar Jun 16 '22 08:06 caiiiycuk

~Looks like the Termux guys actually got it to compile on Android?~

~https://github.com/termux/termux-packages/pull/7982~

~Is it possible we bring their patch here to make things work? I would like to give it a try this weekend.~

Nvm I overlooked the part where it says ARM builds are not supported yet.

Update:

I just tested building wasmer-vm and it works:

$ rustc -vV
rustc 1.64.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: aarch64-linux-android
release: 1.64.0
LLVM version: 15.0.1
$ cargo build --package wasmer-vm

Repo checked out at tag 2.3.0.

xJonathanLEI avatar Oct 21 '22 08:10 xJonathanLEI

I was able to use Zellij on Android after bumping wasmer to 2.3.0: https://github.com/zellij-org/zellij/issues/1021#issuecomment-1300565593

There's also a Termux package for wasmer that builds without applying custom patches.

So I think this issue is already resolved? In that case maybe someone from the team can close this to avoid confusion on Android support. Having an open issue gives the wrong (?) impression that it's not supported.

xJonathanLEI avatar Nov 02 '22 16:11 xJonathanLEI

Hey I just built my library (which uses wasmer) to all android targets using cargo-ndk. So just to confirm, this issue can be closed :smile:

cbrzn avatar Feb 16 '23 23:02 cbrzn

Awesome, closing the issue

syrusakbary avatar Feb 17 '23 06:02 syrusakbary

Are android and ios officially supported now? I haven't seen relevant documents

tsangint avatar Jul 12 '23 04:07 tsangint

I think it's supported in the sense that "it works now", not in that the team would put in work on bug fixes etc.

xJonathanLEI avatar Jul 12 '23 12:07 xJonathanLEI