6e33c95463
Adds shared libraries for embedding Dart VM and new API (runtime/engine/include/dart_engine.h). TEST=tests/standalone/embedder_samples_test.dart Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv32-try,vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-arm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-aot-win-product-x64-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-appjit-linux-product-x64-try,vm-appjit-linux-release-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-product-arm-try,vm-ffi-android-product-arm64c-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-try,vm-fuchsia-release-x64-try,vm-gcc-linux-try,vm-linux-debug-ia32-try,vm-linux-debug-simriscv32-try,vm-linux-debug-simriscv64-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-linux-release-arm64-try,vm-linux-release-ia32-try,vm-linux-release-simarm-try,vm-linux-release-x64-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-msvc-windows-try,vm-reload-linux-debug-x64-try,vm-reload-linux-release-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-reload-rollback-linux-release-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try,vm-win-release-x64-try Change-Id: Ia4e4d1b871ddef515cfb2f4639bdaa9fe3676936 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402860 Reviewed-by: Slava Egorov <vegorov@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
45 lines
1.4 KiB
Markdown
45 lines
1.4 KiB
Markdown
# Dart VM Embedding examples
|
|
|
|
Examples of using Dart VM and executing Dart code from C++ binaries.
|
|
|
|
All examples can run either AOT or Kernel snapshots, depending on
|
|
which shared library variant they depend on.
|
|
|
|
Since snapshot file formats are unstable, the `dart` binary needs to
|
|
be of a matching version. The simplest way to ensure this is to build
|
|
Dart SDK from the same checkout, see [Building Dart
|
|
SDK](https://github.com/dart-lang/sdk/blob/main/docs/Building.md#building).
|
|
|
|
## `run_main.cc`
|
|
|
|
This is the simplest example, which just calls a `main` function from a given AOT/Kernel
|
|
snapshot. It does not handle isolate messages, so it cannot run Dart
|
|
programs with async functions.
|
|
|
|
To run the example with a Kernel snapshot:
|
|
|
|
```sh
|
|
./tools/build.py --mode=release samples/embedder:run_main_kernel && \
|
|
out/ReleaseX64/run_main_kernel out/ReleaseX64/gen/hello_kernel.dart.snapshot.
|
|
```
|
|
|
|
To run the example with an AOT snapshot:
|
|
|
|
```sh
|
|
./tools/build.py --mode=release samples/embedder:run_main_aot && \
|
|
out/ReleaseX64/run_main_aot out/ReleaseX64/hello_aot.snapshot.
|
|
```
|
|
|
|
## `run_two_programs.cc`
|
|
|
|
This example calls a function from one Dart snapshot and then passes
|
|
the returned string to another Dart snapshot.
|
|
|
|
## `run_timer.cc`
|
|
|
|
Demonstrates running an isolate event loop in a separate thread.
|
|
|
|
## `run_timer_async.cc`
|
|
|
|
Demonstrates a custom message scheduler using `std::async`.
|