Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

WIP: iOS support #73

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

WIP: iOS support #73

wants to merge 16 commits into from

Conversation

liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Jan 25, 2022

(This doesn't work at all yet)

Most of the files are boilerplate created by flutter. The only relevant files are:

  • flutter_wasm/ios/flutter_wasm.podspec
  • wasm/bin/setup.dart
  • flutter_wasm/bin/ios_setup.dart

@gaaclarke
Copy link

I looked at this briefly. iOS is a bit different than Android because they don't have JIT. Wasmer has support for it though, you just have to do AOT compilation.

Here's what needs to change:

  1. The wasm module has to be put into its own file so it can be compiled
  2. There needs to be a command-line step that compiles the wasm module to a dylib for the appropriate target. Since this requires cross-compilation I have to believe using the rust toolchain is easiest. This step would be added in the plugin podspec like Liam was doing. There are 2 ways to compile the dylib:
    1. Use wasmer command-line tool (ex https://crates.io/crates/wasmer-cli). Once that is installed the wasm module can be compiled with: cargo wasmer compile ./tests/integration/ios/DylibExample/DylibExample/sum.wasm --dylib --target aarch64-apple-ios -o foo.dylib.
    2. Here is an example of how to compile it programmatically: https://github.com/wasmerio/wasmer/blob/master/examples/platform_ios_headless.rs
  3. The code for initializing the module has to be tweaked a bit for loading from a dylib. Where the current example uses wasm_module_new, the function wasm_module_deserialize must be used (which isn't currently surfaced to Dart). An example of that can be found here: https://github.com/wasmerio/wasmer/blob/61b72164a46cc2a6ac86ca7264a3207daaa84200/tests/integration/ios/DylibExample/DylibExample/calc.cpp#L64 (beware that example/test is difficult to get running and requires a bit of setup with Rust)

@liamappelbe
Copy link
Contributor Author

@gaaclarke Sorry for the slow reply, I missed your message. Thanks for taking a look.

Why would I need to compile the wasm code to a dylib to use the AOT backend? If I'm loading it via wasm_module_deserialize, doesn't that mean I just need to produce the file via wasm_module_serialize? If I compile the wasm to a dylib, wouldn't I need to load it using FFI or something?

The issue I'm having at the moment is just that I can't figure out how to get the package's native code to link into the app. I think there's something missing in flutter_wasm/ios/flutter_wasm.podspec, but I don't know enough about the iOS build system to figure it out. The way this problem manifests is that when I try to run the app, FFI simply fails to find any of the native wasmer functions. If someone can help me with the build magic, and get this PR to the point where FFI loads the wasmer functions correctly, I can figure out the rest.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants