Skip to content

Commit 0c7a3f2

Browse files
authored
Copy //dart-pkg/zircon|fuchsia from Topaz into the engine. (#8884)
Build rules and include paths have been updated as necessary. No other functional change.
1 parent ba82ea2 commit 0c7a3f2

30 files changed

Lines changed: 1963 additions & 0 deletions

‎ci/licenses_golden/licenses_flutter‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,21 @@ FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.cc
715715
FILE: ../../../flutter/shell/platform/embedder/platform_view_embedder.h
716716
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.cc
717717
FILE: ../../../flutter/shell/platform/embedder/vsync_waiter_embedder.h
718+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/lib/fuchsia.dart
719+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.cc
720+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h
721+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart
722+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle_waiter.dart
723+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart
724+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart
725+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc
726+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.h
727+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.cc
728+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle_waiter.h
729+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.cc
730+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.h
731+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.cc
732+
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.h
718733
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/files.cc
719734
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/files.h
720735
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exception.cc
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/fuchsia/sdk.gni")
6+
7+
config("sdk_ext_config") {
8+
include_dirs = [ "../.." ]
9+
}
10+
11+
group("fuchsia") {
12+
public_deps = [
13+
":sdk_ext",
14+
]
15+
}
16+
17+
source_set("sdk_ext") {
18+
sources = [
19+
"sdk_ext/fuchsia.cc",
20+
"sdk_ext/fuchsia.h",
21+
]
22+
23+
deps = [
24+
"$flutter_root/fml",
25+
"$fuchsia_sdk_root/fidl:fuchsia.sys",
26+
"$fuchsia_sdk_root/pkg:async-cpp",
27+
"../zircon",
28+
"//third_party/tonic",
29+
]
30+
31+
public_configs = [ ":sdk_ext_config" ]
32+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dart:fuchsia
2+
===========
3+
4+
These are the Dart bindings for the Fuchsia application model.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
include: ../../analysis_options.yaml
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
library fuchsia;
6+
7+
import 'dart:io';
8+
import 'dart:isolate';
9+
import 'dart:zircon';
10+
11+
// ignore_for_file: native_function_body_in_non_sdk_code
12+
// ignore_for_file: public_member_api_docs
13+
14+
// TODO: refactors this incomingServices instead
15+
@pragma('vm:entry-point')
16+
Handle _environment;
17+
18+
@pragma('vm:entry-point')
19+
Handle _outgoingServices;
20+
21+
class MxStartupInfo {
22+
// TODO: refactor Handle to a Channel
23+
static Handle takeEnvironment() {
24+
if (_outgoingServices == null && Platform.isFuchsia) {
25+
throw Exception(
26+
'Attempting to call takeEnvironment more than once per process');
27+
}
28+
Handle handle = _environment;
29+
_environment = null;
30+
return handle;
31+
}
32+
33+
// TODO: refactor Handle to a Channel
34+
static Handle takeOutgoingServices() {
35+
if (_outgoingServices == null && Platform.isFuchsia) {
36+
throw Exception(
37+
'Attempting to call takeOutgoingServices more than once per process');
38+
}
39+
Handle handle = _outgoingServices;
40+
_outgoingServices = null;
41+
return handle;
42+
}
43+
}
44+
45+
void _setReturnCode(int returnCode) native 'SetReturnCode';
46+
47+
void exit(int returnCode) {
48+
_setReturnCode(returnCode);
49+
Isolate.current.kill(priority: Isolate.immediate);
50+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
fuchsia_sdk_ext_lib = "//topaz/public/dart-pkg/fuchsia/lib/fuchsia.dart"
6+
7+
fuchsia_sdk_ext_files = [ fuchsia_sdk_ext_lib ]
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "dart-pkg/fuchsia/sdk_ext/fuchsia.h"
6+
7+
#include <zircon/syscalls.h>
8+
9+
#include <stdio.h>
10+
#include <string.h>
11+
12+
#include <memory>
13+
#include <vector>
14+
15+
#include "dart-pkg/zircon/sdk_ext/handle.h"
16+
#include "dart-pkg/zircon/sdk_ext/natives.h"
17+
#include "dart-pkg/zircon/sdk_ext/system.h"
18+
#include "flutter/fml/arraysize.h"
19+
#include "third_party/dart/runtime/include/dart_api.h"
20+
#include "third_party/tonic/dart_binding_macros.h"
21+
#include "third_party/tonic/dart_class_library.h"
22+
#include "third_party/tonic/dart_class_provider.h"
23+
#include "third_party/tonic/dart_library_natives.h"
24+
#include "third_party/tonic/dart_state.h"
25+
#include "third_party/tonic/logging/dart_invoke.h"
26+
#include "third_party/tonic/typed_data/uint8_list.h"
27+
28+
using tonic::ToDart;
29+
30+
namespace fuchsia {
31+
namespace dart {
32+
namespace {
33+
34+
static tonic::DartLibraryNatives* g_natives;
35+
36+
tonic::DartLibraryNatives* InitNatives() {
37+
tonic::DartLibraryNatives* natives = new tonic::DartLibraryNatives();
38+
39+
return natives;
40+
}
41+
42+
#define REGISTER_FUNCTION(name, count) {"" #name, name, count},
43+
#define DECLARE_FUNCTION(name, count) \
44+
extern void name(Dart_NativeArguments args);
45+
46+
#define FIDL_NATIVE_LIST(V) V(SetReturnCode, 1)
47+
48+
FIDL_NATIVE_LIST(DECLARE_FUNCTION);
49+
50+
static struct NativeEntries {
51+
const char* name;
52+
Dart_NativeFunction function;
53+
int argument_count;
54+
} Entries[] = {FIDL_NATIVE_LIST(REGISTER_FUNCTION)};
55+
56+
Dart_NativeFunction NativeLookup(Dart_Handle name,
57+
int argument_count,
58+
bool* auto_setup_scope) {
59+
const char* function_name = nullptr;
60+
Dart_Handle result = Dart_StringToCString(name, &function_name);
61+
if (Dart_IsError(result)) {
62+
Dart_PropagateError(result);
63+
}
64+
FML_DCHECK(function_name != nullptr);
65+
FML_DCHECK(auto_setup_scope != nullptr);
66+
*auto_setup_scope = true;
67+
size_t num_entries = arraysize(Entries);
68+
for (size_t i = 0; i < num_entries; ++i) {
69+
const struct NativeEntries& entry = Entries[i];
70+
if (!strcmp(function_name, entry.name) &&
71+
(entry.argument_count == argument_count)) {
72+
return entry.function;
73+
}
74+
}
75+
if (!g_natives)
76+
g_natives = InitNatives();
77+
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
78+
}
79+
80+
const uint8_t* NativeSymbol(Dart_NativeFunction native_function) {
81+
size_t num_entries = arraysize(Entries);
82+
for (size_t i = 0; i < num_entries; ++i) {
83+
const struct NativeEntries& entry = Entries[i];
84+
if (entry.function == native_function) {
85+
return reinterpret_cast<const uint8_t*>(entry.name);
86+
}
87+
}
88+
if (!g_natives)
89+
g_natives = InitNatives();
90+
return g_natives->GetSymbol(native_function);
91+
}
92+
93+
void SetReturnCode(Dart_NativeArguments arguments) {
94+
int64_t return_code;
95+
Dart_Handle status =
96+
Dart_GetNativeIntegerArgument(arguments, 0, &return_code);
97+
if (!tonic::LogIfError(status)) {
98+
tonic::DartState::Current()->SetReturnCode(return_code);
99+
}
100+
}
101+
102+
} // namespace
103+
104+
void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
105+
zx::channel directory_request) {
106+
zircon::dart::Initialize();
107+
108+
Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia"));
109+
FML_CHECK(!tonic::LogIfError(library));
110+
Dart_Handle result = Dart_SetNativeResolver(
111+
library, fuchsia::dart::NativeLookup, fuchsia::dart::NativeSymbol);
112+
FML_CHECK(!tonic::LogIfError(result));
113+
114+
auto dart_state = tonic::DartState::Current();
115+
std::unique_ptr<tonic::DartClassProvider> fuchsia_class_provider(
116+
new tonic::DartClassProvider(dart_state, "dart:fuchsia"));
117+
dart_state->class_library().add_provider("fuchsia",
118+
std::move(fuchsia_class_provider));
119+
120+
result = Dart_SetField(
121+
library, ToDart("_environment"),
122+
ToDart(zircon::dart::Handle::Create(environment.TakeChannel())));
123+
FML_CHECK(!tonic::LogIfError(result));
124+
125+
if (directory_request) {
126+
result = Dart_SetField(
127+
library, ToDart("_outgoingServices"),
128+
ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
129+
FML_CHECK(!tonic::LogIfError(result));
130+
}
131+
}
132+
133+
} // namespace dart
134+
} // namespace fuchsia
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_FUCHSIA_SDK_EXT_FUCHSIA_H_
6+
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_FUCHSIA_SDK_EXT_FUCHSIA_H_
7+
8+
#include <fuchsia/sys/cpp/fidl.h>
9+
10+
namespace fuchsia {
11+
namespace dart {
12+
13+
void Initialize(fidl::InterfaceHandle<fuchsia::sys::Environment> environment,
14+
zx::channel directory_request);
15+
16+
} // namespace dart
17+
} // namespace fuchsia
18+
19+
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_FUCHSIA_SDK_EXT_FUCHSIA_H_
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2013 The Flutter Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/fuchsia/sdk.gni")
6+
7+
config("zircon_config") {
8+
include_dirs = [ "." ]
9+
}
10+
11+
source_set("zircon") {
12+
public_configs = [ ":zircon_config" ]
13+
14+
sources = [
15+
"sdk_ext/handle.cc",
16+
"sdk_ext/handle.h",
17+
"sdk_ext/handle_waiter.cc",
18+
"sdk_ext/handle_waiter.h",
19+
"sdk_ext/natives.cc",
20+
"sdk_ext/natives.h",
21+
"sdk_ext/system.cc",
22+
"sdk_ext/system.h",
23+
]
24+
25+
deps = [
26+
"$fuchsia_sdk_root/pkg:async-cpp",
27+
"$fuchsia_sdk_root/pkg:async-loop-cpp",
28+
"$fuchsia_sdk_root/pkg:fdio",
29+
"$fuchsia_sdk_root/pkg:zx",
30+
"//flutter/fml",
31+
"//third_party/tonic",
32+
]
33+
}

0 commit comments

Comments
 (0)