Skip to content

Commit b963431

Browse files
authored
Merge pull request #74 from ardera/develop
updates for 1.20
2 parents 0c2f0e3 + 257a4ef commit b963431

File tree

1 file changed

+43
-49
lines changed

1 file changed

+43
-49
lines changed

src/flutter-pi.c

+43-49
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ OPTIONS:\n\
7777
pattern you use as a parameter so it isn't \n\
7878
implicitly expanded by your shell.\n\
7979
\n\
80-
--aot Run the app in AOT mode. The AOT snapshot\n\
80+
--release Run the app in release mode. The AOT snapshot\n\
8181
of the app (\"app.so\") must be located inside the\n\
8282
asset bundle directory.\n\
83+
This also requires a libflutter_engine.so that was\n\
84+
built with --runtime-mode=release.\n\
8385
\n\
8486
-o, --orientation <orientation> Start the app in this orientation. Valid\n\
8587
for <orientation> are: portrait_up, landscape_left,\n\
@@ -1568,7 +1570,9 @@ static int init_display(void) {
15681570
* FLUTTER INITIALIZATION *
15691571
**************************/
15701572
static int init_application(void) {
1573+
FlutterEngineAOTDataSource aot_source;
15711574
FlutterRendererConfig renderer_config = {0};
1575+
FlutterEngineAOTData aot_data;
15721576
FlutterEngineResult engine_result;
15731577
FlutterProjectArgs project_args = {0};
15741578
void *app_elf_handle;
@@ -1632,54 +1636,44 @@ static int init_application(void) {
16321636
.compositor = &flutter_compositor
16331637
};
16341638

1635-
if (flutterpi.flutter.is_aot) {
1636-
const uint8_t *vm_instr, *vm_data, *isolate_instr, *isolate_data;
1637-
1638-
app_elf_handle = dlopen(flutterpi.flutter.app_elf_path, RTLD_NOW | RTLD_LOCAL);
1639-
if (app_elf_handle == NULL) {
1640-
perror("[flutter-pi] Could not open \"app.so\". dlopen");
1641-
return errno;
1642-
}
1643-
1644-
vm_instr = dlsym(app_elf_handle, "_kDartVmSnapshotInstructions");
1645-
if (vm_instr == NULL) {
1646-
perror("[flutter-pi] Could not resolve vm instructions section in \"app.so\". dlsym");
1647-
dlclose(app_elf_handle);
1648-
return errno;
1649-
}
1650-
1651-
vm_data = dlsym(app_elf_handle, "_kDartVmSnapshotData");
1652-
if (vm_data == NULL) {
1653-
perror("[flutter-pi] Could not resolve vm data section in \"app.so\". dlsym");
1654-
dlclose(app_elf_handle);
1655-
return errno;
1656-
}
1657-
1658-
isolate_instr = dlsym(app_elf_handle, "_kDartIsolateSnapshotInstructions");
1659-
if (isolate_instr == NULL) {
1660-
perror("[flutter-pi] Could not resolve isolate instructions section in \"app.so\". dlsym");
1661-
dlclose(app_elf_handle);
1662-
return errno;
1663-
}
1639+
bool engine_is_aot = FlutterEngineRunsAOTCompiledDartCode();
1640+
if (engine_is_aot && !flutterpi.flutter.is_aot) {
1641+
fprintf(
1642+
stderr,
1643+
"[flutter-pi] The flutter engine was built for release (AOT) mode,\n"
1644+
" but flutter-pi was not started up in release mode. \n"
1645+
" Either you swap out the libflutter_engine.so \n"
1646+
" with one that was built for debug mode, or you start\n"
1647+
" flutter-pi with the --release flag and make sure\n"
1648+
" a valid \"app.so\" is located inside the asset bundle\n"
1649+
" directory.\n"
1650+
);
1651+
return EINVAL;
1652+
} else if (!engine_is_aot && flutterpi.flutter.is_aot) {
1653+
fprintf(
1654+
stderr,
1655+
"[flutter-pi] The flutter engine was built for debug mode,\n"
1656+
" but flutter-pi was started up in release mode.\n"
1657+
" Either you swap out the libflutter_engine.so\n"
1658+
" with one that was built for release mode, or you\n"
1659+
" start flutter-pi without the --release flag.\n"
1660+
);
1661+
return EINVAL;
1662+
}
16641663

1665-
isolate_data = dlsym(app_elf_handle, "_kDartIsolateSnapshotData");
1666-
if (isolate_data == NULL) {
1667-
perror("[flutter-pi] Could not resolve isolate data section in \"app.so\". dlsym");
1668-
dlclose(app_elf_handle);
1669-
return errno;
1664+
if (flutterpi.flutter.is_aot) {
1665+
aot_source = (FlutterEngineAOTDataSource) {
1666+
.elf_path = flutterpi.flutter.app_elf_path,
1667+
.type = kFlutterEngineAOTDataSourceTypeElfPath
1668+
};
1669+
1670+
engine_result = FlutterEngineCreateAOTData(&aot_source, &aot_data);
1671+
if (engine_result != kSuccess) {
1672+
fprintf(stderr, "[flutter-pi] Could not load AOT data. FlutterEngineCreateAOTData: %s\n", FLUTTER_RESULT_TO_STRING(engine_result));
1673+
return EIO;
16701674
}
16711675

1672-
project_args.vm_snapshot_instructions = vm_instr;
1673-
project_args.vm_snapshot_instructions_size = 0;
1674-
1675-
project_args.isolate_snapshot_instructions = isolate_instr;
1676-
project_args.isolate_snapshot_instructions_size = 0;
1677-
1678-
project_args.vm_snapshot_data = vm_data;
1679-
project_args.vm_snapshot_data_size = 0;
1680-
1681-
project_args.isolate_snapshot_data = isolate_data;
1682-
project_args.isolate_snapshot_data_size = 0;
1676+
project_args.aot_data = aot_data;
16831677
}
16841678

16851679
// spin up the engine
@@ -2328,11 +2322,11 @@ static bool parse_cmd_args(int argc, char **argv) {
23282322
bool input_specified = false;
23292323
int opt;
23302324
int longopt_index = 0;
2331-
int is_aot_int = false;
2325+
int is_release_int = false;
23322326
int disable_text_input_int = false;
23332327

23342328
struct option long_options[] = {
2335-
{"aot", no_argument, &is_aot_int, true},
2329+
{"release", no_argument, &is_release_int, true},
23362330
{"input", required_argument, NULL, 'i'},
23372331
{"orientation", required_argument, NULL, 'o'},
23382332
{"rotation", required_argument, NULL, 'r'},
@@ -2428,7 +2422,7 @@ static bool parse_cmd_args(int argc, char **argv) {
24282422

24292423
flutterpi.input.use_paths = input_specified;
24302424
flutterpi.flutter.asset_bundle_path = strdup(argv[optind]);
2431-
flutterpi.flutter.is_aot = is_aot_int;
2425+
flutterpi.flutter.is_aot = is_release_int;
24322426
flutterpi.input.disable_text_input = disable_text_input_int;
24332427
flutterpi.input.input_devices_glob = input_devices_glob;
24342428

0 commit comments

Comments
 (0)