diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 8322c3ac1f0b8..7ca5eb91bec4b 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -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 diff --git a/shell/platform/fuchsia/dart-pkg/zircon/BUILD.gn b/shell/platform/fuchsia/dart-pkg/zircon/BUILD.gn index 252203afe43a7..eedfe3495e8a1 100644 --- a/shell/platform/fuchsia/dart-pkg/zircon/BUILD.gn +++ b/shell/platform/fuchsia/dart-pkg/zircon/BUILD.gn @@ -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", ] diff --git a/shell/platform/fuchsia/dart-pkg/zircon/lib/src/init.dart b/shell/platform/fuchsia/dart-pkg/zircon/lib/src/init.dart new file mode 100644 index 0000000000000..c9cdeb5273ecd --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon/lib/src/init.dart @@ -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(); diff --git a/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart b/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart index 71360ab5126ef..5e9eaf614bc10 100644 --- a/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart +++ b/shell/platform/fuchsia/dart-pkg/zircon/lib/src/system.dart @@ -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*/ } diff --git a/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart b/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart index 04db7daf52060..7942d228b2f78 100644 --- a/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart +++ b/shell/platform/fuchsia/dart-pkg/zircon/lib/zircon.dart @@ -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'; diff --git a/shell/platform/fuchsia/dart-pkg/zircon_ffi/BUILD.gn b/shell/platform/fuchsia/dart-pkg/zircon_ffi/BUILD.gn new file mode 100644 index 0000000000000..f791c8f37070b --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon_ffi/BUILD.gn @@ -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", + ] +} diff --git a/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.cc b/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.cc new file mode 100644 index 0000000000000..c396d7763de11 --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.cc @@ -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 + +uint64_t zircon_dart_clock_get_monotonic() { + return zx_clock_get_monotonic(); +} diff --git a/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.h b/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.h new file mode 100644 index 0000000000000..275e6c00eb138 --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon_ffi/clock.h @@ -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 + +#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_ diff --git a/shell/platform/fuchsia/dart-pkg/zircon_ffi/lib/zircon_ffi.dart b/shell/platform/fuchsia/dart-pkg/zircon_ffi/lib/zircon_ffi.dart new file mode 100644 index 0000000000000..aae2a5a5befb7 --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon_ffi/lib/zircon_ffi.dart @@ -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 Function(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 Function(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>( + '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(); diff --git a/shell/platform/fuchsia/dart-pkg/zircon_ffi/pubspec.yaml b/shell/platform/fuchsia/dart-pkg/zircon_ffi/pubspec.yaml new file mode 100644 index 0000000000000..fac6b53c18886 --- /dev/null +++ b/shell/platform/fuchsia/dart-pkg/zircon_ffi/pubspec.yaml @@ -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' diff --git a/shell/platform/fuchsia/dart_runner/BUILD.gn b/shell/platform/fuchsia/dart_runner/BUILD.gn index 6e08b011a84dd..2e9f835b5085e 100644 --- a/shell/platform/fuchsia/dart_runner/BUILD.gn +++ b/shell/platform/fuchsia/dart_runner/BUILD.gn @@ -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 = [ { diff --git a/shell/platform/fuchsia/dart_runner/kernel/libraries.json b/shell/platform/fuchsia/dart_runner/kernel/libraries.json index 7cd220be9bf73..e385f595778b5 100644 --- a/shell/platform/fuchsia/dart_runner/kernel/libraries.json +++ b/shell/platform/fuchsia/dart_runner/kernel/libraries.json @@ -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" }, diff --git a/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml b/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml index cc930a10b3ca6..74af3bdb3c7d1 100644 --- a/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml +++ b/shell/platform/fuchsia/dart_runner/kernel/libraries.yaml @@ -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" diff --git a/shell/platform/fuchsia/flutter/BUILD.gn b/shell/platform/fuchsia/flutter/BUILD.gn index 5c4efcaba3cd5..bed2393d1384e 100644 --- a/shell/platform/fuchsia/flutter/BUILD.gn +++ b/shell/platform/fuchsia/flutter/BUILD.gn @@ -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 diff --git a/shell/platform/fuchsia/flutter/kernel/libraries.json b/shell/platform/fuchsia/flutter/kernel/libraries.json index c770f3b1e2455..77ea8972e26c9 100644 --- a/shell/platform/fuchsia/flutter/kernel/libraries.json +++ b/shell/platform/fuchsia/flutter/kernel/libraries.json @@ -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" }, diff --git a/shell/platform/fuchsia/flutter/kernel/libraries.yaml b/shell/platform/fuchsia/flutter/kernel/libraries.yaml index a6c85a970abcd..37f480d71da68 100644 --- a/shell/platform/fuchsia/flutter/kernel/libraries.yaml +++ b/shell/platform/fuchsia/flutter/kernel/libraries.yaml @@ -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" diff --git a/tools/fuchsia/build_fuchsia_artifacts.py b/tools/fuchsia/build_fuchsia_artifacts.py index 42bbe2639726e..a954230bc4c27 100755 --- a/tools/fuchsia/build_fuchsia_artifacts.py +++ b/tools/fuchsia/build_fuchsia_artifacts.py @@ -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):