fuzzybinary / dart_shared_library

An attempt to package Dart into a usable shared library (.dll / .so)
Other
89 stars 12 forks source link

Dart dynamic reload #7

Closed antonbashir closed 1 year ago

antonbashir commented 1 year ago

Is it possible to take current Dart SDK version without additional modifications and make reloading of Dart libraries based on this project ?

Example use case:

  1. Load dart from .so
  2. Launch Isolate
  3. On event (any event which user wants) load new library, launch new isolate
  4. Kill first isolate in first library

I know that it requires some work but my question is about theoretical probability without Dart SDK/VM code modifications

fuzzybinary commented 1 year ago

I don't think I'll add support for this directly, but I don't see why killing and starting a new isolate wouldn't work. Just call Dart_ShutdownIsolate and then reload your library with DartDll_LoadScript. Using DartDll_RunMain makes this a bit more complicated though...

However, if you just want something similar to Flutter's hot reload, dart hot reload actually works out of the box, you don't need to kill and relaunch the isolate.

You can try it out by just attaching a debugger and letting the debugger send the hot reload commands, or you can look into how the hotreload package works and send the commands yourself.

antonbashir commented 1 year ago

I thought hotreload and other solutions which based on Dart VM Service reloadSources method are working only if Dart is running in JIT mode but not in AOT. Thank you for answer, you confirmed my expectations about that it is possible.

fuzzybinary commented 1 year ago

Ah, yes, AOT is actually a whole different story, and hot reload would only work on JIT targets.

That said, this library doesn't support AOT yet anyway, so we'd have to revisit once AOT is supported.