mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Restore functionality to run from .so file on Android (flutter/engine#5278)
Flutter AOT builds can be done on Android using .so files (instead of separate instruction/data snapshots) using the `--build-shared-library` flag. Running from .so files stopped working after the engine refactoring in 82c5c8feda, which this CL restores. Issue https://github.com/flutter/flutter/issues/17236
This commit is contained in:
parent
ecbfc45249
commit
83f32f0961
@ -21,6 +21,22 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData";
|
||||
const char* DartSnapshot::kIsolateInstructionsSymbol =
|
||||
"kDartIsolateSnapshotInstructions";
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
// When assembling the .S file of the application, dart_bootstrap will prefix
|
||||
// symbols via an `_` to ensure Mac's `dlsym()` can find it (Mac ABI prefixes C
|
||||
// symbols with underscores).
|
||||
// But Linux ABI does not prefix C symbols with underscores, so we have to
|
||||
// explicitly look up the prefixed version.
|
||||
#define SYMBOL_PREFIX "_"
|
||||
#else
|
||||
#define SYMBOL_PREFIX ""
|
||||
#endif
|
||||
|
||||
static const char* kVMDataSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotData";
|
||||
static const char* kVMInstructionsSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotInstructions";
|
||||
static const char* kIsolateDataSymbolSo = SYMBOL_PREFIX "kDartIsolateSnapshotData";
|
||||
static const char* kIsolateInstructionsSymbolSo = SYMBOL_PREFIX "kDartIsolateSnapshotInstructions";
|
||||
|
||||
std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
|
||||
if (settings.vm_snapshot_data_path.size() > 0) {
|
||||
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
|
||||
@ -29,6 +45,14 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.application_library_path.size() > 0) {
|
||||
auto shared_library = fml::NativeLibrary::Create(settings.application_library_path.c_str());
|
||||
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
shared_library, kVMDataSymbolSo)) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess();
|
||||
return DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
loaded_process, DartSnapshot::kVMDataSymbol);
|
||||
@ -47,7 +71,7 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
|
||||
auto library =
|
||||
fml::NativeLibrary::Create(settings.application_library_path.c_str());
|
||||
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
library, DartSnapshot::kVMInstructionsSymbol)) {
|
||||
library, kVMInstructionsSymbolSo)) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
@ -67,6 +91,15 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.application_library_path.size() > 0) {
|
||||
auto library =
|
||||
fml::NativeLibrary::Create(settings.application_library_path.c_str());
|
||||
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
library, kIsolateDataSymbolSo)) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess();
|
||||
return DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
loaded_process, DartSnapshot::kIsolateDataSymbol);
|
||||
@ -86,7 +119,7 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
|
||||
auto library =
|
||||
fml::NativeLibrary::Create(settings.application_library_path.c_str());
|
||||
if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary(
|
||||
library, DartSnapshot::kIsolateInstructionsSymbol)) {
|
||||
library, kIsolateInstructionsSymbolSo)) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,6 +170,10 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
|
||||
command_line.GetOptionValue(FlagForSwitch(Switch::Packages),
|
||||
&settings.packages_file_path);
|
||||
|
||||
std::string aot_shared_library_path;
|
||||
command_line.GetOptionValue(FlagForSwitch(Switch::AotSharedLibraryPath),
|
||||
&aot_shared_library_path);
|
||||
|
||||
std::string aot_snapshot_path;
|
||||
command_line.GetOptionValue(FlagForSwitch(Switch::AotSnapshotPath),
|
||||
&aot_snapshot_path);
|
||||
@ -191,7 +195,9 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
|
||||
FlagForSwitch(Switch::AotIsolateSnapshotInstructions),
|
||||
&aot_isolate_snapshot_instr_filename);
|
||||
|
||||
if (aot_snapshot_path.size() > 0) {
|
||||
if (aot_shared_library_path.size() > 0) {
|
||||
settings.application_library_path = aot_shared_library_path;
|
||||
} else if (aot_snapshot_path.size() > 0) {
|
||||
settings.vm_snapshot_data_path = fml::paths::JoinPaths(
|
||||
{aot_snapshot_path, aot_vm_snapshot_data_filename});
|
||||
settings.vm_snapshot_instr_path = fml::paths::JoinPaths(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user