Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1663ac9

Browse files
authored
Add FlutterEngineRunsAOTCompiledDartCode to the embedder API. (#13319)
For embedder code that is configured for both AOT and JIT mode Dart execution based on the Flutter engine being linked to, this runtime check may be used to appropriately configure the `FlutterProjectArgs`. In JIT mode execution, the kernel snapshots must be present in the Flutter assets directory specified in the `FlutterProjectArgs`. For AOT execution, the fields `vm_snapshot_data`, `vm_snapshot_instructions`, `isolate_snapshot_data` and `isolate_snapshot_instructions` (along with their size fields) must be specified in `FlutterProjectArgs`.
1 parent 3b97d3a commit 1663ac9

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

shell/platform/embedder/embedder.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,3 +1573,7 @@ FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine)
15731573
"Could not send message to update locale of "
15741574
"a running Flutter application.");
15751575
}
1576+
1577+
bool FlutterEngineRunsAOTCompiledDartCode(void) {
1578+
return flutter::DartVM::IsRunningPrecompiledCode();
1579+
}

shell/platform/embedder/embedder.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,26 @@ FlutterEngineResult FlutterEngineUpdateLocales(FLUTTER_API_SYMBOL(FlutterEngine)
14561456
const FlutterLocale** locales,
14571457
size_t locales_count);
14581458

1459+
//------------------------------------------------------------------------------
1460+
/// @brief Returns if the Flutter engine instance will run AOT compiled
1461+
/// Dart code. This call has no threading restrictions.
1462+
///
1463+
/// For embedder code that is configured for both AOT and JIT mode
1464+
/// Dart execution based on the Flutter engine being linked to, this
1465+
/// runtime check may be used to appropriately configure the
1466+
/// `FlutterProjectArgs`. In JIT mode execution, the kernel
1467+
/// snapshots must be present in the Flutter assets directory
1468+
/// specified in the `FlutterProjectArgs`. For AOT execution, the
1469+
/// fields `vm_snapshot_data`, `vm_snapshot_instructions`,
1470+
/// `isolate_snapshot_data` and `isolate_snapshot_instructions`
1471+
/// (along with their size fields) must be specified in
1472+
/// `FlutterProjectArgs`.
1473+
///
1474+
/// @return True, if AOT Dart code is run. JIT otherwise.
1475+
///
1476+
FLUTTER_EXPORT
1477+
bool FlutterEngineRunsAOTCompiledDartCode(void);
1478+
14591479
#if defined(__cplusplus)
14601480
} // extern "C"
14611481
#endif

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,5 +2809,10 @@ TEST_F(EmbedderTest, CanUpdateLocales) {
28092809
check_latch.Wait();
28102810
}
28112811

2812+
TEST_F(EmbedderTest, CanQueryDartAOTMode) {
2813+
ASSERT_EQ(FlutterEngineRunsAOTCompiledDartCode(),
2814+
flutter::DartVM::IsRunningPrecompiledCode());
2815+
}
2816+
28122817
} // namespace testing
28132818
} // namespace flutter

0 commit comments

Comments
 (0)