mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[fuchsia] Use FFI to get System clockMonotonic (flutter/engine#27353)
This commit is contained in:
parent
a1fe1c8ca5
commit
45cf4e9ab1
@ -1318,6 +1318,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/fuchsia/sdk_ext/fuchsia.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle_disposition.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/handle_waiter.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/init.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/handle.cc
|
||||
@ -1330,6 +1331,9 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/natives.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon/sdk_ext/system.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.h
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart-pkg/zircon_ffi/lib/zircon_ffi.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart/compiler.dart
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/builtin_libraries.cc
|
||||
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/builtin_libraries.h
|
||||
|
||||
@ -30,6 +30,7 @@ source_set("zircon") {
|
||||
"$fuchsia_sdk_root/pkg:async-loop-cpp",
|
||||
"$fuchsia_sdk_root/pkg:fdio",
|
||||
"$fuchsia_sdk_root/pkg:zx",
|
||||
"../zircon_ffi",
|
||||
"//flutter/fml",
|
||||
"//flutter/third_party/tonic",
|
||||
]
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of zircon;
|
||||
|
||||
final _kLibZirconDartPath = '/pkg/lib/libzircon_ffi.so';
|
||||
|
||||
class _Bindings {
|
||||
static ZirconFFIBindings? _bindings;
|
||||
|
||||
@pragma('vm:entry-point')
|
||||
static ZirconFFIBindings? get() {
|
||||
// For soft-transition until libzircon_ffi.so rolls into GI.
|
||||
if (!File(_kLibZirconDartPath).existsSync()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_bindings == null) {
|
||||
final _dylib = DynamicLibrary.open(_kLibZirconDartPath);
|
||||
_bindings = ZirconFFIBindings(_dylib);
|
||||
}
|
||||
return _bindings;
|
||||
}
|
||||
}
|
||||
|
||||
final ZirconFFIBindings? zirconFFIBindings = _Bindings.get();
|
||||
@ -236,7 +236,15 @@ class System extends NativeFieldWrapperClass1 {
|
||||
static MapResult vmoMap(Handle vmo) native 'System_VmoMap';
|
||||
|
||||
// Time operations.
|
||||
static int clockGetMonotonic() native 'System_ClockGetMonotonic';
|
||||
static int clockGetMonotonic() {
|
||||
if (zirconFFIBindings == null) {
|
||||
return _nativeClockGetMonotonic();
|
||||
} else {
|
||||
return zirconFFIBindings!.zircon_dart_clock_get_monotonic();
|
||||
}
|
||||
}
|
||||
|
||||
static int _nativeClockGetMonotonic() native 'System_ClockGetMonotonic';
|
||||
|
||||
// TODO(edcoyne): Remove this, it is required to safely do an API transition across repos.
|
||||
static int reboot() { return -2; /*ZX_ERR_NOT_SUPPORTED*/ }
|
||||
|
||||
@ -5,10 +5,14 @@
|
||||
library zircon;
|
||||
|
||||
import 'dart:convert' show utf8;
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:nativewrappers';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:zircon_ffi';
|
||||
|
||||
part 'src/handle.dart';
|
||||
part 'src/handle_disposition.dart';
|
||||
part 'src/handle_waiter.dart';
|
||||
part 'src/init.dart';
|
||||
part 'src/system.dart';
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
# Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//build/fuchsia/sdk.gni")
|
||||
|
||||
config("zircon_ffi_config") {
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
|
||||
shared_library("zircon_ffi") {
|
||||
public_configs = [ ":zircon_ffi_config" ]
|
||||
|
||||
sources = [
|
||||
"clock.cc",
|
||||
"clock.h",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$fuchsia_sdk_root/pkg:zx",
|
||||
"//third_party/dart/runtime:dart_api",
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "clock.h"
|
||||
|
||||
#include <zircon/syscalls.h>
|
||||
|
||||
uint64_t zircon_dart_clock_get_monotonic() {
|
||||
return zx_clock_get_monotonic();
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ZIRCON_FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ZIRCON_FFI_EXPORT uint64_t zircon_dart_clock_get_monotonic();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_PKG_ZIRCON_SDK_FFI_CLOCK_H_
|
||||
@ -0,0 +1,36 @@
|
||||
// AUTO GENERATED FILE, DO NOT EDIT.
|
||||
//
|
||||
// Generated by `package:ffigen`.
|
||||
import 'dart:ffi' as ffi;
|
||||
|
||||
/// Bindings for `dart:zircon_ffi`.
|
||||
class ZirconFFIBindings {
|
||||
/// Holds the symbol lookup function.
|
||||
final ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
_lookup;
|
||||
|
||||
/// The symbols are looked up in [dynamicLibrary].
|
||||
ZirconFFIBindings(ffi.DynamicLibrary dynamicLibrary)
|
||||
: _lookup = dynamicLibrary.lookup;
|
||||
|
||||
/// The symbols are looked up with [lookup].
|
||||
ZirconFFIBindings.fromLookup(
|
||||
ffi.Pointer<T> Function<T extends ffi.NativeType>(String symbolName)
|
||||
lookup)
|
||||
: _lookup = lookup;
|
||||
|
||||
int zircon_dart_clock_get_monotonic() {
|
||||
return _zircon_dart_clock_get_monotonic();
|
||||
}
|
||||
|
||||
late final _zircon_dart_clock_get_monotonic_ptr =
|
||||
_lookup<ffi.NativeFunction<_c_zircon_dart_clock_get_monotonic>>(
|
||||
'zircon_dart_clock_get_monotonic');
|
||||
late final _dart_zircon_dart_clock_get_monotonic
|
||||
_zircon_dart_clock_get_monotonic = _zircon_dart_clock_get_monotonic_ptr
|
||||
.asFunction<_dart_zircon_dart_clock_get_monotonic>();
|
||||
}
|
||||
|
||||
typedef _c_zircon_dart_clock_get_monotonic = ffi.Uint64 Function();
|
||||
|
||||
typedef _dart_zircon_dart_clock_get_monotonic = int Function();
|
||||
@ -0,0 +1,40 @@
|
||||
name: zircon_ffi
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
ffi: ^1.0.0
|
||||
|
||||
dev_dependencies:
|
||||
ffigen: ^3.0.0
|
||||
lints: ^1.0.1
|
||||
|
||||
ffigen:
|
||||
name: ZirconFFIBindings
|
||||
description: Bindings for `dart:zircon_ffi`.
|
||||
output: 'lib/zircon_ffi.dart'
|
||||
headers:
|
||||
entry-points:
|
||||
- 'clock.h'
|
||||
functions:
|
||||
include:
|
||||
- 'zircon_dart_.*'
|
||||
macros:
|
||||
include:
|
||||
- nothing
|
||||
enums:
|
||||
include:
|
||||
- nothing
|
||||
unnamed-enums:
|
||||
include:
|
||||
- nothing
|
||||
globals:
|
||||
include:
|
||||
- nothing
|
||||
structs:
|
||||
include:
|
||||
- nothing
|
||||
dependency-only: opaque
|
||||
compiler-opts:
|
||||
- '-I../../../../../../../third_party/dart/runtime'
|
||||
@ -10,6 +10,14 @@ import("//flutter/tools/fuchsia/dart.gni")
|
||||
import("//flutter/tools/fuchsia/fuchsia_archive.gni")
|
||||
import("//flutter/tools/fuchsia/fuchsia_libs.gni")
|
||||
|
||||
# Loaded via FFI
|
||||
_common_runner_libs = common_libs + [
|
||||
{
|
||||
name = "libzircon_ffi.so"
|
||||
path = rebase_path("$root_out_dir")
|
||||
},
|
||||
]
|
||||
|
||||
template("runner") {
|
||||
assert(defined(invoker.product), "The parameter 'product' must be defined")
|
||||
assert(defined(invoker.output_name),
|
||||
@ -40,6 +48,9 @@ template("runner") {
|
||||
|
||||
defines = extra_defines
|
||||
|
||||
# For `libzircon_ffi` see _common_runner_libs.
|
||||
public_deps = [ "../dart-pkg/zircon_ffi:zircon_ffi" ]
|
||||
|
||||
dart_deps = []
|
||||
if (!invoker.product) {
|
||||
dart_deps += [
|
||||
@ -151,7 +162,7 @@ template("aot_runner_package") {
|
||||
|
||||
cmx_file = rebase_path("meta/dart_aot${product_suffix}_runner.cmx")
|
||||
|
||||
libraries = common_libs
|
||||
libraries = _common_runner_libs
|
||||
|
||||
resources = []
|
||||
if (!invoker.product) {
|
||||
@ -212,7 +223,7 @@ template("jit_runner_package") {
|
||||
cmx_file = rebase_path("meta/dart_jit${product_suffix}_runner.cmx")
|
||||
cml_file = rebase_path("meta/dart_jit${product_suffix}_runner.cml")
|
||||
|
||||
libraries = common_libs
|
||||
libraries = _common_runner_libs
|
||||
|
||||
resources = [
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"comment:0": "NOTE: THIS FILE IS GENERATED. DO NOT EDIT.",
|
||||
"comment:1": "Instead modify 'shell/platform/fuchsia/dart_runner/kernel/libraries.yaml' and follow the instructions therein.",
|
||||
"comment:1": "Instead modify './flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml' and follow the instructions therein.",
|
||||
"dart_runner": {
|
||||
"libraries": {
|
||||
"_builtin": {
|
||||
@ -152,6 +152,9 @@
|
||||
"zircon": {
|
||||
"uri": "../../dart-pkg/zircon/lib/zircon.dart"
|
||||
},
|
||||
"zircon_ffi": {
|
||||
"uri": "../../dart-pkg/zircon_ffi/lib/zircon_ffi.dart"
|
||||
},
|
||||
"fuchsia": {
|
||||
"uri": "../../dart-pkg/fuchsia/lib/fuchsia.dart"
|
||||
},
|
||||
|
||||
@ -152,6 +152,9 @@ dart_runner:
|
||||
zircon:
|
||||
uri: "../../dart-pkg/zircon/lib/zircon.dart"
|
||||
|
||||
zircon_ffi:
|
||||
uri: "../../dart-pkg/zircon_ffi/lib/zircon_ffi.dart"
|
||||
|
||||
fuchsia:
|
||||
uri: "../../dart-pkg/fuchsia/lib/fuchsia.dart"
|
||||
|
||||
|
||||
@ -151,6 +151,14 @@ runner_sources("flutter_runner_sources_product") {
|
||||
product = true
|
||||
}
|
||||
|
||||
# Loaded via FFI
|
||||
_common_runner_libs = common_libs + [
|
||||
{
|
||||
name = "libzircon_ffi.so"
|
||||
path = rebase_path("$root_out_dir")
|
||||
},
|
||||
]
|
||||
|
||||
# Things that explicitly being excluded:
|
||||
# 1. Kernel snapshot framework mode.
|
||||
# 2. Profiler symbols.
|
||||
@ -195,6 +203,9 @@ template("flutter_runner") {
|
||||
"$fuchsia_sdk_root/pkg:trace-provider-so",
|
||||
] + extra_deps
|
||||
|
||||
# For `libzircon_ffi` see _common_runner_libs.
|
||||
public_deps = [ "../dart-pkg/zircon_ffi:zircon_ffi" ]
|
||||
|
||||
# The flags below are needed so that Dart's CPU profiler can walk the
|
||||
# C++ stack.
|
||||
cflags = [ "-fno-omit-frame-pointer" ]
|
||||
@ -331,7 +342,7 @@ template("jit_runner") {
|
||||
]
|
||||
|
||||
_vulkan_icds = []
|
||||
_libs = common_libs
|
||||
_libs = _common_runner_libs
|
||||
if (enable_vulkan_validation_layers) {
|
||||
_libs += vulkan_validation_libs
|
||||
_vulkan_icds += vulkan_icds
|
||||
@ -389,7 +400,7 @@ template("aot_runner") {
|
||||
}
|
||||
|
||||
_vulkan_icds = []
|
||||
_libs = common_libs
|
||||
_libs = _common_runner_libs
|
||||
if (enable_vulkan_validation_layers) {
|
||||
_libs += vulkan_validation_libs
|
||||
_vulkan_icds += vulkan_icds
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"comment:0": "NOTE: THIS FILE IS GENERATED. DO NOT EDIT.",
|
||||
"comment:1": "Instead modify 'shell/platform/fuchsia/flutter/kernel/libraries.yaml' and follow the instructions therein.",
|
||||
"comment:1": "Instead modify './flutter/shell/platform/fuchsia/flutter/kernel/libraries.yaml' and follow the instructions therein.",
|
||||
"flutter_runner": {
|
||||
"libraries": {
|
||||
"_builtin": {
|
||||
@ -152,6 +152,9 @@
|
||||
"zircon": {
|
||||
"uri": "../../dart-pkg/zircon/lib/zircon.dart"
|
||||
},
|
||||
"zircon_ffi": {
|
||||
"uri": "../../dart-pkg/zircon_ffi/lib/zircon_ffi.dart"
|
||||
},
|
||||
"fuchsia": {
|
||||
"uri": "../../dart-pkg/fuchsia/lib/fuchsia.dart"
|
||||
},
|
||||
|
||||
@ -152,6 +152,9 @@ flutter_runner:
|
||||
zircon:
|
||||
uri: "../../dart-pkg/zircon/lib/zircon.dart"
|
||||
|
||||
zircon_ffi:
|
||||
uri: "../../dart-pkg/zircon_ffi/lib/zircon_ffi.dart"
|
||||
|
||||
fuchsia:
|
||||
uri: "../../dart-pkg/fuchsia/lib/fuchsia.dart"
|
||||
|
||||
|
||||
@ -125,6 +125,10 @@ def CopyFlutterTesterBinIfExists(source, destination):
|
||||
destination_base = os.path.join(destination, 'flutter_binaries')
|
||||
FindFileAndCopyTo('flutter_tester', source_root, destination_base)
|
||||
|
||||
def CopyZirconFFILibIfExists(source, destination):
|
||||
source_root = os.path.join(_out_dir, source)
|
||||
destination_base = os.path.join(destination, 'flutter_binaries')
|
||||
FindFileAndCopyTo('libzircon_ffi.so', source_root, destination_base)
|
||||
|
||||
def CopyToBucketWithMode(source, destination, aot, product, runner_type):
|
||||
mode = 'aot' if aot else 'jit'
|
||||
@ -146,6 +150,7 @@ def CopyToBucketWithMode(source, destination, aot, product, runner_type):
|
||||
CopyPath(patched_sdk_dir, dest_sdk_path)
|
||||
CopyGenSnapshotIfExists(source_root, destination)
|
||||
CopyFlutterTesterBinIfExists(source_root, destination)
|
||||
CopyZirconFFILibIfExists(source_root, destination)
|
||||
|
||||
|
||||
def CopyToBucket(src, dst, product=False):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user