Fix aot builds in the dart_runner for fuchsia (flutter/engine#30722)

The dart_runner was crashing in aot builds. These changes allow the
dart_runner to run aot builds in fuchsia.
This commit is contained in:
Chase Latta 2022-01-06 16:45:53 -08:00 committed by GitHub
parent cbd5abd3b3
commit 0d51ef6307
6 changed files with 41 additions and 16 deletions

View File

@ -160,7 +160,7 @@ fdio_ns_t* GetNamespace() {
Dart_Handle zircon_lib = Dart_LookupLibrary(ToDart("dart:zircon"));
FML_DCHECK(!tonic::LogIfError(zircon_lib));
Dart_Handle namespace_type =
Dart_GetType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
Dart_GetNonNullableType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
FML_DCHECK(!tonic::LogIfError(namespace_type));
Dart_Handle namespace_field =
Dart_GetField(namespace_type, ToDart("_namespace"));

View File

@ -185,7 +185,7 @@ void InitBuiltinLibrariesForIsolate(
// Set up the namespace in dart:io.
Dart_Handle namespace_type =
Dart_GetType(io_lib, ToDart("_Namespace"), 0, nullptr);
Dart_GetNonNullableType(io_lib, ToDart("_Namespace"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(namespace_type));
Dart_Handle namespace_args[1];
@ -195,7 +195,8 @@ void InitBuiltinLibrariesForIsolate(
FML_CHECK(!tonic::LogIfError(result));
// Set up the namespace in dart:zircon.
namespace_type = Dart_GetType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
namespace_type =
Dart_GetNonNullableType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(namespace_type));
result = Dart_SetField(namespace_type, ToDart("_namespace"),
@ -212,7 +213,7 @@ void InitBuiltinLibrariesForIsolate(
// Disable some dart:io operations.
Dart_Handle embedder_config_type =
Dart_GetType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
Dart_GetNonNullableType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(embedder_config_type));
result =

View File

@ -400,8 +400,13 @@ bool DartComponentController::Main() {
Dart_EnterIsolate(isolate_);
Dart_EnterScope();
Dart_Handle dart_arguments =
Dart_NewListOf(Dart_CoreType_String, arguments.size());
Dart_Handle corelib = Dart_LookupLibrary(ToDart("dart:core"));
Dart_Handle string_type =
Dart_GetNonNullableType(corelib, ToDart("String"), 0, NULL);
Dart_Handle dart_arguments = Dart_NewListOfTypeFilled(
string_type, Dart_EmptyString(), arguments.size());
if (Dart_IsError(dart_arguments)) {
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",
Dart_GetError(dart_arguments));

View File

@ -412,7 +412,11 @@ bool DartComponentControllerV2::RunDartMain() {
// that run in the dart runner are written with main functions that have the
// signature `void main(List<String> args)`. In order to ensure that these
// components do not break we need to have this stub argument list.
Dart_Handle dart_arguments = Dart_NewListOf(Dart_CoreType_String, 0);
Dart_Handle corelib = Dart_LookupLibrary(ToDart("dart:core"));
Dart_Handle string_type =
Dart_GetNonNullableType(corelib, ToDart("String"), 0, NULL);
Dart_Handle dart_arguments =
Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), 0);
if (Dart_IsError(dart_arguments)) {
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",

View File

@ -73,9 +73,10 @@ void EmbedderInformationCallback(Dart_EmbedderInformation* info) {
} // namespace
Dart_Isolate CreateServiceIsolate(const char* uri,
Dart_IsolateFlags* flags,
char** error) {
Dart_Isolate CreateServiceIsolate(
const char* uri,
Dart_IsolateFlags* flags_unused, // These flags are currently unused
char** error) {
Dart_SetEmbedderInformationCallback(EmbedderInformationCallback);
const uint8_t *vmservice_data = nullptr, *vmservice_instructions = nullptr;
@ -122,10 +123,24 @@ Dart_Isolate CreateServiceIsolate(const char* uri,
}
#endif
bool is_null_safe =
Dart_DetectNullSafety(nullptr, // script_uri
nullptr, // package_config
nullptr, // original_working_directory
vmservice_data, // snapshot_data
vmservice_instructions, // snapshot_instructions
nullptr, // kernel_buffer
0u // kernel_buffer_size
);
Dart_IsolateFlags flags;
Dart_IsolateFlagsInitialize(&flags);
flags.null_safety = is_null_safe;
auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState());
Dart_Isolate isolate = Dart_CreateIsolateGroup(
uri, DART_VM_SERVICE_ISOLATE_NAME, vmservice_data, vmservice_instructions,
nullptr /* flags */, state, state, error);
&flags, state, state, error);
if (!isolate) {
FX_LOGF(ERROR, LOG_TAG, "Dart_CreateIsolateGroup failed: %s", *error);
return nullptr;

View File

@ -53,8 +53,8 @@ void IsolateConfigurator::BindZircon() {
Dart_Handle zircon_lib = Dart_LookupLibrary(tonic::ToDart("dart:zircon"));
FML_CHECK(!tonic::LogIfError(zircon_lib));
Dart_Handle namespace_type =
Dart_GetType(zircon_lib, tonic::ToDart("_Namespace"), 0, nullptr);
Dart_Handle namespace_type = Dart_GetNonNullableType(
zircon_lib, tonic::ToDart("_Namespace"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(namespace_type));
Dart_Handle result =
@ -70,8 +70,8 @@ void IsolateConfigurator::BindDartIO() {
FML_CHECK(!tonic::LogIfError(io_lib));
// Disable dart:io exit()
Dart_Handle embedder_config_type =
Dart_GetType(io_lib, tonic::ToDart("_EmbedderConfig"), 0, nullptr);
Dart_Handle embedder_config_type = Dart_GetNonNullableType(
io_lib, tonic::ToDart("_EmbedderConfig"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(embedder_config_type));
Dart_Handle result = Dart_SetField(embedder_config_type,
@ -80,7 +80,7 @@ void IsolateConfigurator::BindDartIO() {
// Tell dart:io about the FDIO namespace configured for this instance.
Dart_Handle namespace_type =
Dart_GetType(io_lib, tonic::ToDart("_Namespace"), 0, nullptr);
Dart_GetNonNullableType(io_lib, tonic::ToDart("_Namespace"), 0, nullptr);
FML_CHECK(!tonic::LogIfError(namespace_type));
Dart_Handle namespace_args[] = {