Files
sdk/samples/embedder
Ivan Inozemtsev 15c58a889f Add static variants of Dart engine library and update samples
Fixes https://github.com/dart-lang/sdk/issues/60799

Change-Id: I16a8dd2c854ed6915f14e1b71547879f50f2de0e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432920
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
2025-06-06 04:00:45 -07:00
..
2025-04-29 07:45:07 -07:00
2025-01-28 03:53:40 -08:00
2025-01-28 03:53:40 -08:00
2025-01-28 03:53:40 -08:00

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.

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:

./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:

./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.