How to build embeddable VM runtime on iOS?

326 views
Skip to first unread message

Yifeng Wang

unread,
Nov 5, 2020, 12:53:14 PM11/5/20
to Dart Misc
Hi, I'm trying to embed Dart VM on iOS, following guides in the Embedding Dart discussion  posted by Vegorov. For now I can build the minimal VM on macOS, making it running precompiled dill files. But for iOS, I found there are no related instructions on the official build guide. I have tried using different values for target_os / dart_target_arch / target_os / target_cpu build arg, but I got invalid build configs or "architecture not supported" compile time errors. I even tried open the xcodebuild/DebugX64/all.xcodeproj file, setting the target to iOS (neither does this work).

So, how to create a static library for minimal VM on iOS? How does Flutter do this? Thanks.

Vyacheslav Egorov

unread,
Nov 5, 2020, 2:50:18 PM11/5/20
to General Dart Discussion
Hi, 

Note that Kernel binaries (aka dill files) is not a viable solution for iOS outside of certain scenarios (running them requires JIT) - you would need to build precompiled runtime targeting iOS  - your only option is to build precompiled (AOT) runtime. 

Unfortunately I don't think that SDK is set for building to iOS right now. BUILDCONFIG.gn in our buildroot does not have enough stuff to enable building for iOS. 


I think the simplest approach can be to use a flutter engine build environment and then you can just take AOT runtime built there and use it in your app. 




// If you get an email from me outside of the 9-5 it is not because I'm always
// on or expect an immediate response from you; it is because of work flexibility.
// Evening and weekend emails are a sign I allocated some regular working hours
// for other things (such as family, gym, friends,...).  And I encourage you to
// feel free to do the same.



On Thu, Nov 5, 2020 at 6:53 PM Yifeng Wang <doodl...@gmail.com> wrote:
Hi, I'm trying to embed Dart VM on iOS, following guides in the Embedding Dart discussion  posted by Vegorov. For now I can build the minimal VM on macOS, making it running precompiled dill files. But for iOS, I found there are no related instructions on the official build guide. I have tried using different values for target_os / dart_target_arch / target_os / target_cpu build arg, but I got invalid build configs or "architecture not supported" compile time errors. I even tried open the xcodebuild/DebugX64/all.xcodeproj file, setting the target to iOS (neither does this work).

So, how to create a static library for minimal VM on iOS? How does Flutter do this? Thanks.

--
For more ways to connect visit https://dart.dev/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/5767f814-67f5-4aeb-8bb3-3b05dfb15ac5n%40dartlang.org.

Yifeng Wang

unread,
Nov 11, 2020, 11:47:39 AM11/11/20
to Dart Misc, Vyacheslav Egorov
Thanks for the suggestion, I’ve made pretty much progress porting standalone Dart VM to iOS, here are some follow-ups:

Within the Flutter’s build environment, I built a new static library containing libdartvm with no snapshot (the precompiled runtime library is also ready, but I just need a minimalist prototype for now). This library contains all symbols to run the embedder example, while two more kernel binary files are required:

* For the `vm_platform_strong.dill` , it’s inside the flutter engine’s compiled products for iOS. This works fine.
* For the `app.dill` kernel binary, I tweaked the flutter tool a little bit, then started an empty Flutter project, changed its lib/main.dart to a bare empty main function, got its compiled output (~5KB) from the CFE’s tmp output folder.

Now the question is that, when I call `Dart_LoadLibraryFromKernel` to load the `app.dill` file, I got an “Invalid kernel binary format version” error, which is a check that `vm_platform_strong.dill` passed. To be more specific, the Dart VM on iOS expects binary version 49, but the version of `app.dill` I compiled is 45.

The `vm_platform_strong.dill` that passed the check is compiled with Flutter engine’s source code, whose Dart VM version is 2.12.0-4.0.dev. But when I compile `app.dill`, the Dart VM running CFE on my Mac is v2.10.3. However, I got both of them coming from the official Flutter release (1.22.3), is this mismatch in VM version expected, or am I doing something wrong?

I think I’m much closer to a working prototype. I’d really appreciate any further advice. Thanks.

Yifeng

Yifeng Wang

unread,
Nov 12, 2020, 4:29:46 AM11/12/20
to Dart Misc, Yifeng Wang, Vyacheslav Egorov
Update: With same revision of Flutter Tool and Flutter Engine, I got the embedded VM running on iOS now. Thanks for the help!

Randal L. Schwartz

unread,
Nov 12, 2020, 8:24:37 AM11/12/20
to mi...@dartlang.org, Yifeng Wang, Vyacheslav Egorov


On Nov 11, 2020, at 9:59 PM, Yifeng Wang <doodl...@gmail.com> wrote:

Update: With same revision of Flutter Tool and Flutter Engine, I got the embedded VM running on iOS now. Thanks for the help!

does this mean it won’t be long before we get an nginx or apache plugin and get Dart seriously on the web server side?

Reply all
Reply to author
Forward
0 new messages