Skip to content

Commit

Permalink
Refactor BUCK file for WebPerformance (use TurboModule plugins) (#36197)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
rshest authored and facebook-github-bot committed Feb 18, 2023
1 parent bcf493f commit 1629b9f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
23 changes: 16 additions & 7 deletions BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ load(
"//tools/build_defs/oss:rn_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
"HERMES_BYTECODE_VERSION",
"IOS",
"RCT_IMAGE_DATA_DECODER_SOCKET",
"RCT_IMAGE_URL_LOADER_SOCKET",
"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",
Expand All @@ -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")
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions Libraries/WebPerformance/NativePerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

#include "NativePerformance.h"
#include <glog/logging.h>
#include <memory>

#include <jsi/instrumentation.h>
#include "NativePerformance.h"
#include "PerformanceEntryReporter.h"

#include "Plugins.h"

std::shared_ptr<facebook::react::TurboModule> NativePerformanceModuleProvider(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativePerformance>(
std::move(jsInvoker));
}

namespace facebook::react {

NativePerformance::NativePerformance(std::shared_ptr<CallInvoker> jsInvoker)
Expand Down
11 changes: 11 additions & 0 deletions Libraries/WebPerformance/NativePerformanceObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

#include <memory>

#include "NativePerformanceObserver.h"
#include "PerformanceEntryReporter.h"

#include "Plugins.h"

std::shared_ptr<facebook::react::TurboModule>
NativePerformanceObserverModuleProvider(
std::shared_ptr<facebook::react::CallInvoker> jsInvoker) {
return std::make_shared<facebook::react::NativePerformanceObserver>(
std::move(jsInvoker));
}

namespace facebook::react {

NativePerformanceObserver::NativePerformanceObserver(
Expand Down
4 changes: 4 additions & 0 deletions tools/build_defs/oss/rn_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1629b9f

Please sign in to comment.