Discussion:
[dart-misc] Embedding Dart in an executable, still possible?
Jeff Ward
2016-04-19 03:13:36 UTC
Permalink
I've been trying to embed the Dart VM in an executable for a few days and I
haven't been having much luck, and I'm wondering if this is still a
supported use case.

It would be nice if the following worked:

- Pull the dart source and build libdart
- Link in libdart, include dart_api.h and have that work.

Unfortunately that doesn't work. But, here's what I've tried and still
haven't had much success.

- Pull the dart source and build the full dart executable
- link in libdart, libdart_lib, libdart_vm,
libdart_vm_precompiled_runtime, and libdouble_conversion

With this approach, I'm able to build, but when the CreateIsolate callback
gets called for the "vm-service" isolate, I call "CreateIsolate" which
ASSERTS and exits (the assert is "runtime/vm/hash_table.h:378: error:
expected: !data_->IsNull()", where the most relevant function in the
callstack is Symbols::AddPredefinedSymbolsToIsolate)

It appears that even though the documentation says Dart_Iniitialize should
support supplying a NULL for both the vm_isolate_snapshot and that
Dart_CreateIsolate should support supplying a NULL isolate_snapshot, this
is no longer the case.

So, I added in the generated snapshot files to my project source
(dart_sdk_src\sdk\build\DebugX64\obj\global_intermediate\snapshot_gen.cc)
and re-ran. This gets past CreateIsolate, but fails attempting to load the
core library. ("Dart_LookupLibrary: library 'dart:builtin' not found.").

I've tried various combinations of compiling in generated files and
compiled libs but can't find a combination that links cleanly and supplies
a version of dart:builtin.

Obviously there's some amount of secret sauce here I'm missing, but I can't
figure out the magic combination to make it work.

--
Jeff
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
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+***@dartlang.org.
'Florian Schneider' via Dart Misc
2016-04-19 10:32:39 UTC
Permalink
Post by Jeff Ward
I've been trying to embed the Dart VM in an executable for a few days and
I haven't been having much luck, and I'm wondering if this is still a
supported use case.
- Pull the dart source and build libdart
- Link in libdart, include dart_api.h and have that work.
Unfortunately that doesn't work. But, here's what I've tried and still
haven't had much success.
- Pull the dart source and build the full dart executable
- link in libdart, libdart_lib, libdart_vm,
libdart_vm_precompiled_runtime, and libdouble_conversion
Normally you should only need libdart_vm, and not
libdart_vm_precompiled_runtime.
Post by Jeff Ward
With this approach, I'm able to build, but when the CreateIsolate callback
gets called for the "vm-service" isolate, I call "CreateIsolate" which
expected: !data_->IsNull()", where the most relevant function in the
callstack is Symbols::AddPredefinedSymbolsToIsolate)
It appears that even though the documentation says Dart_Iniitialize should
support supplying a NULL for both the vm_isolate_snapshot and that
Dart_CreateIsolate should support supplying a NULL isolate_snapshot, this
is no longer the case.
So, I added in the generated snapshot files to my project source
(dart_sdk_src\sdk\build\DebugX64\obj\global_intermediate\snapshot_gen.cc)
and re-ran. This gets past CreateIsolate, but fails attempting to load the
core library. ("Dart_LookupLibrary: library 'dart:builtin' not found.").
I've tried various combinations of compiling in generated files and
compiled libs but can't find a combination that links cleanly and supplies
a version of dart:builtin.
Hard to say what exactly is going wrong. Take a close look at
runtime/bin/main.cc as an example of how to embed libdart_vm.
Post by Jeff Ward
Obviously there's some amount of secret sauce here I'm missing, but I
can't figure out the magic combination to make it work.
--
Jeff
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
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
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
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+***@dartlang.org.
Jeff Ward
2016-04-19 15:26:53 UTC
Permalink
Hey Florian, thanks for the response!

What's in libdart_vm_precompiled_runtime?

Also, is my conclusion about Dart_CreateIsolate no longer supporting NULL
vm / isolate snapshots correct?

I did actually made some progress on this last night (by consulting
main.cc, I'll outline the fixes at the end for future generations) but
still having some issues.

Once I have a hello_world.dart file loaded, I attempt to invoke main using
Dart_Invoke, and I'm getting an error message along the lines of
"Dart_Invoke expects the library in 'target' to be loaded". I'm not sure
what to call to load the "library" other than call Dart_LoadScript (or
Dart_LoadLibrary, both do the same thing). I've added a Dart_RunLoop (which
main.cc does) but that doesn't seem to fix the issue.

Any thoughts?

How I Fixed My Dumb Issues:
First, I made sure that I'm not doing any extra work fro the vm-service
isolate that gets created when you call Dart_Initialize. In the creation
callbacks I checked for Dart_IsServiceIssolate and break out if that's the
case.
Second, the dart:builtin module is now called dart:_builtin. Loading that
library worked.

On Tue, Apr 19, 2016 at 6:32 AM, 'Florian Schneider' via Dart Misc <
Post by 'Florian Schneider' via Dart Misc
Post by Jeff Ward
I've been trying to embed the Dart VM in an executable for a few days and
I haven't been having much luck, and I'm wondering if this is still a
supported use case.
- Pull the dart source and build libdart
- Link in libdart, include dart_api.h and have that work.
Unfortunately that doesn't work. But, here's what I've tried and still
haven't had much success.
- Pull the dart source and build the full dart executable
- link in libdart, libdart_lib, libdart_vm,
libdart_vm_precompiled_runtime, and libdouble_conversion
Normally you should only need libdart_vm, and not
libdart_vm_precompiled_runtime.
Post by Jeff Ward
With this approach, I'm able to build, but when the CreateIsolate
callback gets called for the "vm-service" isolate, I call "CreateIsolate"
expected: !data_->IsNull()", where the most relevant function in the
callstack is Symbols::AddPredefinedSymbolsToIsolate)
It appears that even though the documentation says Dart_Iniitialize
should support supplying a NULL for both the vm_isolate_snapshot and that
Dart_CreateIsolate should support supplying a NULL isolate_snapshot, this
is no longer the case.
So, I added in the generated snapshot files to my project source
(dart_sdk_src\sdk\build\DebugX64\obj\global_intermediate\snapshot_gen.cc)
and re-ran. This gets past CreateIsolate, but fails attempting to load the
core library. ("Dart_LookupLibrary: library 'dart:builtin' not found.").
I've tried various combinations of compiling in generated files and
compiled libs but can't find a combination that links cleanly and supplies
a version of dart:builtin.
Hard to say what exactly is going wrong. Take a close look at
runtime/bin/main.cc as an example of how to embed libdart_vm.
Post by Jeff Ward
Obviously there's some amount of secret sauce here I'm missing, but I
can't figure out the magic combination to make it work.
--
Jeff
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
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
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the
Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/dartlang.org/d/topic/misc/BvUbN7qRhX4/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
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+***@dartlang.org.
'Florian Schneider' via Dart Misc
2016-04-19 15:46:10 UTC
Permalink
Post by Jeff Ward
Hey Florian, thanks for the response!
What's in libdart_vm_precompiled_runtime?
libdart_vm_precompiled_runtime is used to run programs from a precompiled
instruction snapshot - basically a Dart app compiled into a .so file.
Post by Jeff Ward
Also, is my conclusion about Dart_CreateIsolate no longer supporting NULL
vm / isolate snapshots correct?
Passing NULL is supported. For example, see runtime/bin/gen_snapshot.cc -
it loads all sources from source files instead of a snapshot. Maybe
gen_snapshot is actually a better (simpler) example to start from than
main.cc -- but instead of creating and writing a snapshot you would invoke
main there.
Post by Jeff Ward
I did actually made some progress on this last night (by consulting
main.cc, I'll outline the fixes at the end for future generations) but
still having some issues.
Once I have a hello_world.dart file loaded, I attempt to invoke main using
Dart_Invoke, and I'm getting an error message along the lines of
"Dart_Invoke expects the library in 'target' to be loaded". I'm not sure
what to call to load the "library" other than call Dart_LoadScript (or
Dart_LoadLibrary, both do the same thing). I've added a Dart_RunLoop (which
main.cc does) but that doesn't seem to fix the issue.
Any thoughts?
First, I made sure that I'm not doing any extra work fro the vm-service
isolate that gets created when you call Dart_Initialize. In the creation
callbacks I checked for Dart_IsServiceIssolate and break out if that's the
case.
Second, the dart:builtin module is now called dart:_builtin. Loading that
library worked.
On Tue, Apr 19, 2016 at 6:32 AM, 'Florian Schneider' via Dart Misc <
Post by 'Florian Schneider' via Dart Misc
Post by Jeff Ward
I've been trying to embed the Dart VM in an executable for a few days
and I haven't been having much luck, and I'm wondering if this is still a
supported use case.
- Pull the dart source and build libdart
- Link in libdart, include dart_api.h and have that work.
Unfortunately that doesn't work. But, here's what I've tried and still
haven't had much success.
- Pull the dart source and build the full dart executable
- link in libdart, libdart_lib, libdart_vm,
libdart_vm_precompiled_runtime, and libdouble_conversion
Normally you should only need libdart_vm, and not
libdart_vm_precompiled_runtime.
Post by Jeff Ward
With this approach, I'm able to build, but when the CreateIsolate
callback gets called for the "vm-service" isolate, I call "CreateIsolate"
expected: !data_->IsNull()", where the most relevant function in the
callstack is Symbols::AddPredefinedSymbolsToIsolate)
It appears that even though the documentation says Dart_Iniitialize
should support supplying a NULL for both the vm_isolate_snapshot and that
Dart_CreateIsolate should support supplying a NULL isolate_snapshot, this
is no longer the case.
So, I added in the generated snapshot files to my project source
(dart_sdk_src\sdk\build\DebugX64\obj\global_intermediate\snapshot_gen.cc)
and re-ran. This gets past CreateIsolate, but fails attempting to load the
core library. ("Dart_LookupLibrary: library 'dart:builtin' not found.").
I've tried various combinations of compiling in generated files and
compiled libs but can't find a combination that links cleanly and supplies
a version of dart:builtin.
Hard to say what exactly is going wrong. Take a close look at
runtime/bin/main.cc as an example of how to embed libdart_vm.
Post by Jeff Ward
Obviously there's some amount of secret sauce here I'm missing, but I
can't figure out the magic combination to make it work.
--
Jeff
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
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
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the
Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/dartlang.org/d/topic/misc/BvUbN7qRhX4/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
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
--
For other discussions, see https://groups.google.com/a/dartlang.org/

For HOWTO questions, visit http://stackoverflow.com/tags/dart

To file a bug report or feature request, go to http://www.dartbug.com/new
---
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+***@dartlang.org.
Loading...