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

Commit d53b3c2

Browse files
authored
Fix aot builds in the dart_runner for fuchsia (#30722)
The dart_runner was crashing in aot builds. These changes allow the dart_runner to run aot builds in fuchsia.
1 parent a0bbfeb commit d53b3c2

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fdio_ns_t* GetNamespace() {
160160
Dart_Handle zircon_lib = Dart_LookupLibrary(ToDart("dart:zircon"));
161161
FML_DCHECK(!tonic::LogIfError(zircon_lib));
162162
Dart_Handle namespace_type =
163-
Dart_GetType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
163+
Dart_GetNonNullableType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
164164
FML_DCHECK(!tonic::LogIfError(namespace_type));
165165
Dart_Handle namespace_field =
166166
Dart_GetField(namespace_type, ToDart("_namespace"));

shell/platform/fuchsia/dart_runner/builtin_libraries.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void InitBuiltinLibrariesForIsolate(
185185

186186
// Set up the namespace in dart:io.
187187
Dart_Handle namespace_type =
188-
Dart_GetType(io_lib, ToDart("_Namespace"), 0, nullptr);
188+
Dart_GetNonNullableType(io_lib, ToDart("_Namespace"), 0, nullptr);
189189
FML_CHECK(!tonic::LogIfError(namespace_type));
190190

191191
Dart_Handle namespace_args[1];
@@ -195,7 +195,8 @@ void InitBuiltinLibrariesForIsolate(
195195
FML_CHECK(!tonic::LogIfError(result));
196196

197197
// Set up the namespace in dart:zircon.
198-
namespace_type = Dart_GetType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
198+
namespace_type =
199+
Dart_GetNonNullableType(zircon_lib, ToDart("_Namespace"), 0, nullptr);
199200
FML_CHECK(!tonic::LogIfError(namespace_type));
200201

201202
result = Dart_SetField(namespace_type, ToDart("_namespace"),
@@ -212,7 +213,7 @@ void InitBuiltinLibrariesForIsolate(
212213

213214
// Disable some dart:io operations.
214215
Dart_Handle embedder_config_type =
215-
Dart_GetType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
216+
Dart_GetNonNullableType(io_lib, ToDart("_EmbedderConfig"), 0, nullptr);
216217
FML_CHECK(!tonic::LogIfError(embedder_config_type));
217218

218219
result =

shell/platform/fuchsia/dart_runner/dart_component_controller.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,13 @@ bool DartComponentController::Main() {
400400
Dart_EnterIsolate(isolate_);
401401
Dart_EnterScope();
402402

403-
Dart_Handle dart_arguments =
404-
Dart_NewListOf(Dart_CoreType_String, arguments.size());
403+
Dart_Handle corelib = Dart_LookupLibrary(ToDart("dart:core"));
404+
Dart_Handle string_type =
405+
Dart_GetNonNullableType(corelib, ToDart("String"), 0, NULL);
406+
407+
Dart_Handle dart_arguments = Dart_NewListOfTypeFilled(
408+
string_type, Dart_EmptyString(), arguments.size());
409+
405410
if (Dart_IsError(dart_arguments)) {
406411
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",
407412
Dart_GetError(dart_arguments));

shell/platform/fuchsia/dart_runner/dart_component_controller_v2.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ bool DartComponentControllerV2::RunDartMain() {
412412
// that run in the dart runner are written with main functions that have the
413413
// signature `void main(List<String> args)`. In order to ensure that these
414414
// components do not break we need to have this stub argument list.
415-
Dart_Handle dart_arguments = Dart_NewListOf(Dart_CoreType_String, 0);
415+
Dart_Handle corelib = Dart_LookupLibrary(ToDart("dart:core"));
416+
Dart_Handle string_type =
417+
Dart_GetNonNullableType(corelib, ToDart("String"), 0, NULL);
418+
Dart_Handle dart_arguments =
419+
Dart_NewListOfTypeFilled(string_type, Dart_EmptyString(), 0);
416420

417421
if (Dart_IsError(dart_arguments)) {
418422
FX_LOGF(ERROR, LOG_TAG, "Failed to allocate Dart arguments list: %s",

shell/platform/fuchsia/dart_runner/service_isolate.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ void EmbedderInformationCallback(Dart_EmbedderInformation* info) {
7373

7474
} // namespace
7575

76-
Dart_Isolate CreateServiceIsolate(const char* uri,
77-
Dart_IsolateFlags* flags,
78-
char** error) {
76+
Dart_Isolate CreateServiceIsolate(
77+
const char* uri,
78+
Dart_IsolateFlags* flags_unused, // These flags are currently unused
79+
char** error) {
7980
Dart_SetEmbedderInformationCallback(EmbedderInformationCallback);
8081

8182
const uint8_t *vmservice_data = nullptr, *vmservice_instructions = nullptr;
@@ -122,10 +123,24 @@ Dart_Isolate CreateServiceIsolate(const char* uri,
122123
}
123124
#endif
124125

126+
bool is_null_safe =
127+
Dart_DetectNullSafety(nullptr, // script_uri
128+
nullptr, // package_config
129+
nullptr, // original_working_directory
130+
vmservice_data, // snapshot_data
131+
vmservice_instructions, // snapshot_instructions
132+
nullptr, // kernel_buffer
133+
0u // kernel_buffer_size
134+
);
135+
136+
Dart_IsolateFlags flags;
137+
Dart_IsolateFlagsInitialize(&flags);
138+
flags.null_safety = is_null_safe;
139+
125140
auto state = new std::shared_ptr<tonic::DartState>(new tonic::DartState());
126141
Dart_Isolate isolate = Dart_CreateIsolateGroup(
127142
uri, DART_VM_SERVICE_ISOLATE_NAME, vmservice_data, vmservice_instructions,
128-
nullptr /* flags */, state, state, error);
143+
&flags, state, state, error);
129144
if (!isolate) {
130145
FX_LOGF(ERROR, LOG_TAG, "Dart_CreateIsolateGroup failed: %s", *error);
131146
return nullptr;

shell/platform/fuchsia/flutter/isolate_configurator.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void IsolateConfigurator::BindZircon() {
5353
Dart_Handle zircon_lib = Dart_LookupLibrary(tonic::ToDart("dart:zircon"));
5454
FML_CHECK(!tonic::LogIfError(zircon_lib));
5555

56-
Dart_Handle namespace_type =
57-
Dart_GetType(zircon_lib, tonic::ToDart("_Namespace"), 0, nullptr);
56+
Dart_Handle namespace_type = Dart_GetNonNullableType(
57+
zircon_lib, tonic::ToDart("_Namespace"), 0, nullptr);
5858
FML_CHECK(!tonic::LogIfError(namespace_type));
5959

6060
Dart_Handle result =
@@ -70,8 +70,8 @@ void IsolateConfigurator::BindDartIO() {
7070
FML_CHECK(!tonic::LogIfError(io_lib));
7171

7272
// Disable dart:io exit()
73-
Dart_Handle embedder_config_type =
74-
Dart_GetType(io_lib, tonic::ToDart("_EmbedderConfig"), 0, nullptr);
73+
Dart_Handle embedder_config_type = Dart_GetNonNullableType(
74+
io_lib, tonic::ToDart("_EmbedderConfig"), 0, nullptr);
7575
FML_CHECK(!tonic::LogIfError(embedder_config_type));
7676

7777
Dart_Handle result = Dart_SetField(embedder_config_type,
@@ -80,7 +80,7 @@ void IsolateConfigurator::BindDartIO() {
8080

8181
// Tell dart:io about the FDIO namespace configured for this instance.
8282
Dart_Handle namespace_type =
83-
Dart_GetType(io_lib, tonic::ToDart("_Namespace"), 0, nullptr);
83+
Dart_GetNonNullableType(io_lib, tonic::ToDart("_Namespace"), 0, nullptr);
8484
FML_CHECK(!tonic::LogIfError(namespace_type));
8585

8686
Dart_Handle namespace_args[] = {

0 commit comments

Comments
 (0)