mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Setup NativeAssetsApi during isolate group creation (flutter/engine#53329)
This initializes the `NativeAssetsApi` for native assets resolution in the isolate group creation callback. * https://github.com/dart-lang/sdk/issues/55523 ## Implementation considerations The DartIO initialization lives in its own GN target. This doesn't work for the native assets initialization due to it having to look up the `script_uri` in one of the callbacks. Since the callbacks are function pointers, we can't have a lambda that captures the script uri. So instead, the native assets initialization lives in the flutter/runtime target. The import from dart should probably be `runtime/include/bin/native_assets_api.h` to mirror what we're doing with dart IO, rather than directly importing from `runtime/bin/native_assets.h`. ## Testing All native asset testing is in flutter_tools, so those tests will only run once this rolls into flutter/flutter. I have done manual testing locally with a Dart branch that removes the fallback: https://dart-review.googlesource.com/c/sdk/+/370740 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
7574abb3f8
commit
f7a4157683
@ -107,6 +107,7 @@ source_set("runtime") {
|
||||
":test_font",
|
||||
"$dart_src/runtime:dart_api",
|
||||
"$dart_src/runtime/bin:dart_io_api",
|
||||
"$dart_src/runtime/bin:native_assets_api",
|
||||
"//flutter/assets",
|
||||
"//flutter/common",
|
||||
"//flutter/flow",
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "fml/message_loop_task_queues.h"
|
||||
#include "fml/task_source.h"
|
||||
#include "fml/time/time_point.h"
|
||||
#include "third_party/dart/runtime/include/bin/native_assets_api.h"
|
||||
#include "third_party/dart/runtime/include/dart_api.h"
|
||||
#include "third_party/dart/runtime/include/dart_tools_api.h"
|
||||
#include "third_party/tonic/converter/dart_converter.h"
|
||||
@ -1165,6 +1166,27 @@ bool DartIsolate::DartIsolateInitializeCallback(void** child_callback_data,
|
||||
return true;
|
||||
}
|
||||
|
||||
static void* NativeAssetsDlopenRelative(const char* path, char** error) {
|
||||
auto* isolate_group_data =
|
||||
static_cast<std::shared_ptr<DartIsolateGroupData>*>(
|
||||
Dart_CurrentIsolateGroupData());
|
||||
const std::string& script_uri = (*isolate_group_data)->GetAdvisoryScriptURI();
|
||||
return dart::bin::NativeAssets::DlopenRelative(path, script_uri.data(),
|
||||
error);
|
||||
}
|
||||
|
||||
static void InitDartFFIForIsolateGroup() {
|
||||
NativeAssetsApi native_assets;
|
||||
memset(&native_assets, 0, sizeof(native_assets));
|
||||
native_assets.dlopen_absolute = &dart::bin::NativeAssets::DlopenAbsolute;
|
||||
native_assets.dlopen_relative = &NativeAssetsDlopenRelative;
|
||||
native_assets.dlopen_system = &dart::bin::NativeAssets::DlopenSystem;
|
||||
native_assets.dlopen_executable = &dart::bin::NativeAssets::DlopenExecutable;
|
||||
native_assets.dlopen_process = &dart::bin::NativeAssets::DlopenProcess;
|
||||
native_assets.dlsym = &dart::bin::NativeAssets::Dlsym;
|
||||
Dart_InitializeNativeAssetsResolver(&native_assets);
|
||||
};
|
||||
|
||||
Dart_Isolate DartIsolate::CreateDartIsolateGroup(
|
||||
std::unique_ptr<std::shared_ptr<DartIsolateGroupData>> isolate_group_data,
|
||||
std::unique_ptr<std::shared_ptr<DartIsolate>> isolate_data,
|
||||
@ -1191,6 +1213,8 @@ Dart_Isolate DartIsolate::CreateDartIsolateGroup(
|
||||
isolate_data.release();
|
||||
// NOLINTEND(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
|
||||
InitDartFFIForIsolateGroup();
|
||||
|
||||
success = InitializeIsolate(embedder_isolate, isolate, error);
|
||||
}
|
||||
if (!success) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user