From 1629b9f0a11f42ff12c6dd06a20afb80067e4958 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Fri, 17 Feb 2023 19:10:41 -0800 Subject: [PATCH] Refactor BUCK file for WebPerformance (use TurboModule plugins) (#36197) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36197 [Changelog][Internal] This turns NativePerformance* module dependencies into "TurboModule plugins", which allows for more streamlined client integration (as it makes them register automatically once the dependency is there). Reviewed By: rubennorte Differential Revision: D43353204 fbshipit-source-id: 01d0089750a4873088dc4aefe34fd48693ee9791 --- BUCK | 23 +++++++++++++------ .../WebPerformance/NativePerformance.cpp | 13 +++++++++-- .../NativePerformanceObserver.cpp | 11 +++++++++ tools/build_defs/oss/rn_defs.bzl | 4 ++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/BUCK b/BUCK index 898094984f338c..c3fd4340e199d7 100644 --- a/BUCK +++ b/BUCK @@ -12,7 +12,6 @@ load( "//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "APPLE", - "CXX", "HERMES_BYTECODE_VERSION", "IOS", "RCT_IMAGE_DATA_DECODER_SOCKET", @@ -20,6 +19,7 @@ load( "RCT_URL_REQUEST_HANDLER_SOCKET", "YOGA_CXX_TARGET", "get_react_native_ios_target_sdk_version", + "react_cxx_module_plugin_provider", "react_fabric_component_plugin_provider", "react_module_plugin_providers", "react_native_root_target", @@ -28,6 +28,7 @@ load( "rn_apple_library", "rn_apple_xplat_cxx_library", "rn_extra_build_flags", + "rn_xplat_cxx_library", "subdir_glob", ) load("//tools/build_defs/third_party:yarn_defs.bzl", "yarn_workspace") @@ -1455,7 +1456,7 @@ rn_apple_xplat_cxx_library( ], ) -rn_apple_xplat_cxx_library( +rn_xplat_cxx_library( name = "RCTWebPerformance", srcs = glob([ "Libraries/WebPerformance/**/*.cpp", @@ -1465,15 +1466,23 @@ rn_apple_xplat_cxx_library( [("Libraries/WebPerformance", "*.h")], prefix = "RCTWebPerformance", ), - fbandroid_compiler_flags = [ - "-fexceptions", - "-frtti", - ], + compiler_flags_enable_exceptions = True, + compiler_flags_enable_rtti = True, labels = [ "depslint_never_remove", "pfh:ReactNative_CommonInfrastructurePlaceholder", ], - platforms = (ANDROID, APPLE, CXX), + platforms = (ANDROID, APPLE), + plugins = [ + react_cxx_module_plugin_provider( + name = "NativePerformanceCxx", + function = "NativePerformanceModuleProvider", + ), + react_cxx_module_plugin_provider( + name = "NativePerformanceObserverCxx", + function = "NativePerformanceObserverModuleProvider", + ), + ], visibility = ["PUBLIC"], deps = [ ":FBReactNativeSpecJSI", diff --git a/Libraries/WebPerformance/NativePerformance.cpp b/Libraries/WebPerformance/NativePerformance.cpp index 94b0f4c5413a07..fdb4a5c3777951 100644 --- a/Libraries/WebPerformance/NativePerformance.cpp +++ b/Libraries/WebPerformance/NativePerformance.cpp @@ -5,11 +5,20 @@ * LICENSE file in the root directory of this source tree. */ -#include "NativePerformance.h" -#include +#include + #include +#include "NativePerformance.h" #include "PerformanceEntryReporter.h" +#include "Plugins.h" + +std::shared_ptr NativePerformanceModuleProvider( + std::shared_ptr jsInvoker) { + return std::make_shared( + std::move(jsInvoker)); +} + namespace facebook::react { NativePerformance::NativePerformance(std::shared_ptr jsInvoker) diff --git a/Libraries/WebPerformance/NativePerformanceObserver.cpp b/Libraries/WebPerformance/NativePerformanceObserver.cpp index 200140fdae1e6b..d1fa750c7eb900 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.cpp +++ b/Libraries/WebPerformance/NativePerformanceObserver.cpp @@ -5,9 +5,20 @@ * LICENSE file in the root directory of this source tree. */ +#include + #include "NativePerformanceObserver.h" #include "PerformanceEntryReporter.h" +#include "Plugins.h" + +std::shared_ptr +NativePerformanceObserverModuleProvider( + std::shared_ptr jsInvoker) { + return std::make_shared( + std::move(jsInvoker)); +} + namespace facebook::react { NativePerformanceObserver::NativePerformanceObserver( diff --git a/tools/build_defs/oss/rn_defs.bzl b/tools/build_defs/oss/rn_defs.bzl index faaa4aea094660..85e088a9f1eb30 100644 --- a/tools/build_defs/oss/rn_defs.bzl +++ b/tools/build_defs/oss/rn_defs.bzl @@ -424,6 +424,10 @@ def react_module_plugin_providers(*args, **kwargs): def react_fabric_component_plugin_provider(name, native_class_func): return None +# C++ TurboModule plugins support (stubbed) +def react_cxx_module_plugin_provider(name, function): + return None + HERMES_BYTECODE_VERSION = -1 RCT_IMAGE_DATA_DECODER_SOCKET = None