tana / Wasm3DotNet

A .NET binding for wasm3
MIT License
19 stars 2 forks source link

Unity: iOS Support #3

Open johannesvollmer opened 2 years ago

johannesvollmer commented 2 years ago

As iOS libraries are statically linked in Unity, the DLLImport attributes might need to be configurable.

See unity docs example for native libraries. Of course, this would not be done with a weird UNITY_IPHONE flag, but with some other generic mechanism.

Any ideas? I am willing to contribute, but need some hints. How could we approach this?

johannesvollmer commented 2 years ago

Note: As wasm3 is the only wasm library that does not require System.Reflection.Emit internally, it is the only option for running wasm on iOS in Unity. Therefore, Wasm3DotNet should want to support iOS.

Disclaimer: I did not actually test whether it is currently already possible to run on iOS, just assuming the unity docs are still valid.

johannesvollmer commented 2 years ago

Inside of Unity, we cannot pass any flags to the managed dll. But, we can define constraints that can control which dll is selected in which platform. So maybe we can have two different managed dlls, one for static linking and one for dynamic linking, and then in Unity choose the static linking variant on iOS?

tana commented 11 months ago

Since I have no knowledge about iOS development, I cannot help with actual programming on this issue. However, supporting iOS might be possible with the three steps:

  1. Creating a static library (.a) equivalent of wasm3_dll.
  2. Adding #if UNITY_IOS conditional compilation in NativeFunctions.cs.
  3. Distributing Unity version of Wasm3DotNet as C# sources, instead of managed DLL.

Sorry for forgetting this issue for long time.

johannesvollmer commented 11 months ago

Don't worry, it's fine :) due to iOS being very restrictive about code execution, this will probably not get into to AppStore either way. They only allow code downloaded and executed by their WebKit view.... which might include web assembly, but definitely excludes wasm3