wasmer icon indicating copy to clipboard operation
wasmer copied to clipboard

Run wasmer on iOS device

Open zhangjiuzhou opened this issue 3 years ago • 1 comments

In version 2.1.0, wasmer added iOS support.

I can run DylibExample on the IOS simulator and get the correct results.But when I was running on the real machine, I encountered a problem:

Because I need to compile dylib that can be run by the real machine , I changed the script "Compile .wasm to .dylib" to this:

export ARCH='aarch64-apple-ios'

./../../../../target/release/wasmer compile DylibExample/sum.wasm --target $ARCH --dylib  -o DylibExample/sum.dylib

It can be compiled and run normally, but an error occurred. The log is as follows:

Creating the store...
Loading .dylib file...
Compiling module...
> Error compiling module!

zhangjiuzhou avatar Jan 20 '22 03:01 zhangjiuzhou

I'm trying to do the same and got similar errors. So using wasmer_last_error_length and wasmer_last_error_message I made some changes to debug the errors and discovered two things:

  1. To get a module, we are reading the .dylib file from the disk and moving it to the disk again in deserialize function. Unfortunately, that generates a wrong signed code, so we get this error:
dlopen(
  /private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib,
  0x0005
): tried:
'/usr/lib/system/introspection/sum.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib'
(code signature invalid (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0000CAF0, codeBlobSize=0x00004B30 for '/private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib'),
'/usr/local/lib/sum.dylib' (no such file),
'/usr/lib/sum.dylib' (no such file)
  1. But changing the code to read the file directly from the executable folder (without copy and write), we get another error:
missing requires CPU features: "EnumSet(SSE2)"

In this case, I think the .dylib generated by wasmer compile --target aarch64-apple-ios has the wrong architecture target.

Running a code in iOS Simulator has many differences between running a code in a real device, even in the controlled development environment.

nuxlli avatar Feb 19 '22 10:02 nuxlli

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 19 '23 11:02 stale[bot]

Feel free to reopen the issue if it has been closed by mistake.

stale[bot] avatar Mar 22 '23 00:03 stale[bot]

I'm trying to do the same and got similar errors. So using wasmer_last_error_length and wasmer_last_error_message I made some changes to debug the errors and discovered two things:

  1. To get a module, we are reading the .dylib file from the disk and moving it to the disk again in deserialize function. Unfortunately, that generates a wrong signed code, so we get this error:
dlopen(
  /private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib,
  0x0005
): tried:
'/usr/lib/system/introspection/sum.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib'
(code signature invalid (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0000CAF0, codeBlobSize=0x00004B30 for '/private/var/mobile/Containers/Data/Application/765BB8A0-7D8B-4793-8E1D-0373AB98CF41/tmp/sum.dylib'),
'/usr/local/lib/sum.dylib' (no such file),
'/usr/lib/sum.dylib' (no such file)
  1. But changing the code to read the file directly from the executable folder (without copy and write), we get another error:
missing requires CPU features: "EnumSet(SSE2)"

In this case, I think the .dylib generated by wasmer compile --target aarch64-apple-ios has the wrong architecture target.

Running a code in iOS Simulator has many differences between running a code in a real device, even in the controlled development environment.

how to read directly

newNcy avatar Apr 11 '24 09:04 newNcy