Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run wasmer on iOS device #2760

Closed
zhangjiuzhou opened this issue Jan 20, 2022 · 4 comments
Closed

Run wasmer on iOS device #2760

zhangjiuzhou opened this issue Jan 20, 2022 · 4 comments
Assignees
Labels
bug Something isn't working priority-medium Medium priority issue 🏚 stale Inactive issues or PR

Comments

@zhangjiuzhou
Copy link

zhangjiuzhou commented Jan 20, 2022

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 zhangjiuzhou added the bug Something isn't working label Jan 20, 2022
@Amanieu Amanieu added the priority-medium Medium priority issue label Feb 9, 2022
@nuxlli
Copy link

nuxlli commented Feb 19, 2022

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.

bors bot added a commit that referenced this issue Sep 15, 2022
3185: Fix `wasmer compile` command for non-x86 target r=syrusakbary a=flfymoss

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

Currently, `wasmer compile` command with specifying non-x86 (e.g. `aarch64-apple-darwin`) target doesn't work.
This change fixes the issue by not SSE2 to be force added for non-x86 targets.


(Codes are ported from https://github.com/wasmerio/wasmer/blob/8a6c98702f1b8b63f5ab3d1b8c094959dd325afe/lib/cli/src/commands/create_obj.rs#L80 and https://github.com/wasmerio/wasmer/blob/d4a888abed6d877d46bf040a932e693ab39940b9/lib/cli/src/commands/create_exe.rs#L151 )

Possibly relates #2760 (comment)

## Demo

### Before
```sh
$ wasmer compile hello.wasm -o hello.wasmu
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu
Hello
World!
$ wasmer compile --target aarch64-apple-darwin -o hello.wasmu hello.wasm
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu 
error: failed to run `hello.wasmu`
│   1: failed to instantiate WASI module
╰─▶ 2: missing required CPU features: "EnumSet(SSE2)"
```

### After
```sh
$ wasmer compile --target aarch64-apple-darwin -o hello.wasmu hello.wasm
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu 
Hello
World!
```

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Go Murakami <[email protected]>
bors bot added a commit that referenced this issue Sep 15, 2022
3185: Fix `wasmer compile` command for non-x86 target r=syrusakbary a=flfymoss

<!-- 
Prior to submitting a PR, review the CONTRIBUTING.md document for recommendations on how to test:
https://github.com/wasmerio/wasmer/blob/master/CONTRIBUTING.md#pull-requests

-->

# Description
<!-- 
Provide details regarding the change including motivation,
links to related issues, and the context of the PR.
-->

Currently, `wasmer compile` command with specifying non-x86 (e.g. `aarch64-apple-darwin`) target doesn't work.
This change fixes the issue by not SSE2 to be force added for non-x86 targets.


(Codes are ported from https://github.com/wasmerio/wasmer/blob/8a6c98702f1b8b63f5ab3d1b8c094959dd325afe/lib/cli/src/commands/create_obj.rs#L80 and https://github.com/wasmerio/wasmer/blob/d4a888abed6d877d46bf040a932e693ab39940b9/lib/cli/src/commands/create_exe.rs#L151 )

Possibly relates #2760 (comment)

## Demo

### Before
```sh
$ wasmer compile hello.wasm -o hello.wasmu
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu
Hello
World!
$ wasmer compile --target aarch64-apple-darwin -o hello.wasmu hello.wasm
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu 
error: failed to run `hello.wasmu`
│   1: failed to instantiate WASI module
╰─▶ 2: missing required CPU features: "EnumSet(SSE2)"
```

### After
```sh
$ wasmer compile --target aarch64-apple-darwin -o hello.wasmu hello.wasm
Compiler: cranelift
Target: aarch64-apple-darwin
✔ File compiled successfully to `hello.wasmu`.
$ wasmer run hello.wasmu 
Hello
World!
```

# Review

- [ ] Add a short description of the change to the CHANGELOG.md file


Co-authored-by: Go Murakami <[email protected]>
@stale
Copy link

stale bot commented Feb 19, 2023

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 stale bot added the 🏚 stale Inactive issues or PR label Feb 19, 2023
@stale
Copy link

stale bot commented Mar 22, 2023

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

@stale stale bot closed this as completed Mar 22, 2023
@newNcy
Copy link

newNcy commented Apr 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-medium Medium priority issue 🏚 stale Inactive issues or PR
Projects
None yet
Development

No branches or pull requests

5 participants