Files
react-native/packages/react-native/React-Core.podspec
T
Moti Zilberman b7025fe156 Create stub InstanceTarget, send execution context notifications (#42636)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42636

Changelog: [Internal]

Models the Native instance lifecycle in the modern CDP backend, by:

1. Registering the instance, once created, with `PageTarget`.
2. While an instance is registered, delegating messages from `PageAgent` to an internal `InstanceAgent`.
3. Unregistering the instance once it is invalidated and about to be destroyed.

We use this infrastructure to implement two simple behaviours that will be superseded in future diffs (mainly by delegating work to the JSVM), but that are useful as stubs for testing:

* Sending [`Runtime.executionContextDestroyed`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#event-executionContextDestroyed), [`Runtime.executionContextsCleared`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#event-executionContextsCleared), and [`Runtime.executionContextCreated`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#event-executionContextCreated) events to the frontend when reloading the instance.
* Implementing a toy version of [`Runtime.getHeapUsage`](https://cdpstatus.reactnative.dev/devtools-protocol/tot/Runtime#method-getHeapUsage) (that always reports zero memory usage) to exercise the Page→Instance message dispatching logic.

iOS Bridge/Bridgeless and `PageTargetTest` are the only integrations that exist as of this diff, and are all updated here; Android will follow later.

## Object lifetimes

* PageTarget owns an InstanceTarget that it creates (in `registerInstance`) and destroys (in `unregisterInstance`).
* `registerInstance` returns a raw `InstanceTarget&` reference, which becomes invalid upon calling `unregisterInstance`. It's the caller's responsibility to stop using the reference at the point of calling `unregisterInstance`.
* InstanceTarget holds a raw `InstanceTargetDelegate&` reference. It's the caller's responsibility to keep this reference valid at least until `unregisterInstance` returns.

## Thread safety

* As with PageTarget's constructor and destructor, It's the caller's responsibility to invoke `registerInstance` and `unregisterInstance` on the main thread (or using appropriate synchronisation).
* `InstanceAgent` handles messages on the same thread as `PageAgent` (typically the platform-specific main thread) and receives a copy of the same thread-safe `FrontendChannel` for sending messages back.

Reviewed By: huntie

Differential Revision: D51214056

fbshipit-source-id: 2dc2ff30d2dda6887871831a818aa117ca3e6e91
2024-01-30 08:56:17 -08:00

145 lines
5.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
version = package['version']
source = { :git => 'https://github.com/facebook/react-native.git' }
if version == '1000.0.0'
# This is an unpublished version, use the latest commit hash of the react-native repo, which were presumably in.
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
else
source[:tag] = "v#{version}"
end
folly_config = get_folly_config()
folly_compiler_flags = folly_config[:compiler_flags]
folly_version = folly_config[:version]
socket_rocket_version = '0.7.0'
boost_compiler_flags = '-Wno-documentation'
use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'
use_hermes_flag = use_hermes ? "-DUSE_HERMES=1" : ""
header_subspecs = {
'CoreModulesHeaders' => 'React/CoreModules/**/*.h',
'RCTActionSheetHeaders' => 'Libraries/ActionSheetIOS/*.h',
'RCTAnimationHeaders' => 'Libraries/NativeAnimation/{Drivers/*,Nodes/*,*}.{h}',
'RCTBlobHeaders' => 'Libraries/Blob/{RCTBlobManager,RCTFileReaderModule}.h',
'RCTImageHeaders' => 'Libraries/Image/*.h',
'RCTLinkingHeaders' => 'Libraries/LinkingIOS/*.h',
'RCTNetworkHeaders' => 'Libraries/Network/*.h',
'RCTPushNotificationHeaders' => 'Libraries/PushNotificationIOS/*.h',
'RCTSettingsHeaders' => 'Libraries/Settings/*.h',
'RCTTextHeaders' => 'Libraries/Text/**/*.h',
'RCTVibrationHeaders' => 'Libraries/Vibration/*.h',
}
frameworks_search_paths = []
frameworks_search_paths << "\"$(PODS_CONFIGURATION_BUILD_DIR)/React-hermes\"" if use_hermes
header_search_paths = [
"$(PODS_TARGET_SRCROOT)/ReactCommon",
"$(PODS_ROOT)/boost",
"$(PODS_ROOT)/DoubleConversion",
"$(PODS_ROOT)/fmt/include",
"$(PODS_ROOT)/RCT-Folly",
"${PODS_ROOT}/Headers/Public/FlipperKit",
"$(PODS_ROOT)/Headers/Public/ReactCommon",
].concat(use_hermes ? [
"$(PODS_ROOT)/Headers/Public/React-hermes",
"$(PODS_ROOT)/Headers/Public/hermes-engine"
] : [])
Pod::Spec.new do |s|
s.name = "React-Core"
s.version = version
s.summary = "The core of React Native."
s.homepage = "https://reactnative.dev/"
s.license = package["license"]
s.author = "Meta Platforms, Inc. and its affiliates"
s.platforms = min_supported_versions
s.source = source
s.resource_bundle = { "RCTI18nStrings" => ["React/I18n/strings/*.lproj"]}
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags + ' ' + use_hermes_flag
s.header_dir = "React"
s.framework = "JavaScriptCore"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => header_search_paths,
"DEFINES_MODULE" => "YES",
"GCC_PREPROCESSOR_DEFINITIONS" => "RCT_METRO_PORT=${RCT_METRO_PORT}",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"FRAMEWORK_SEARCH_PATHS" => frameworks_search_paths.join(" ")
}
s.user_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Headers/Private/React-Core\""}
s.default_subspec = "Default"
s.subspec "Default" do |ss|
ss.source_files = "React/**/*.{c,h,m,mm,S,cpp}"
exclude_files = [
"React/CoreModules/**/*",
"React/DevSupport/**/*",
"React/Fabric/**/*",
"React/FBReactNativeSpec/**/*",
"React/Tests/**/*",
"React/Inspector/**/*",
]
# If we are using Hermes (the default is use hermes, so USE_HERMES can be nil), we don't have jsc installed
# So we have to exclude the JSCExecutorFactory
if use_hermes
exclude_files = exclude_files.append("React/CxxBridge/JSCExecutorFactory.{h,mm}")
end
ss.exclude_files = exclude_files
ss.private_header_files = "React/Cxx*/*.h"
end
s.subspec "DevSupport" do |ss|
ss.source_files = "React/DevSupport/*.{h,mm,m}",
"React/Inspector/*.{h,mm,m}"
ss.dependency "React-Core/Default", version
ss.dependency "React-Core/RCTWebSocket", version
ss.private_header_files = "React/Inspector/RCTCxx*.h"
end
s.subspec "RCTWebSocket" do |ss|
ss.source_files = "Libraries/WebSocket/*.{h,m}"
ss.dependency "React-Core/Default", version
end
# Add a subspec containing just the headers for each
# pod that should live under <React/*.h>
header_subspecs.each do |name, headers|
s.subspec name do |ss|
ss.source_files = headers
ss.dependency "React-Core/Default"
end
end
s.dependency "RCT-Folly", folly_version
s.dependency "React-cxxreact"
s.dependency "React-perflogger"
s.dependency "React-jsi"
s.dependency "React-jsiexecutor"
s.dependency "React-utils"
s.dependency "React-featureflags"
s.dependency "SocketRocket", socket_rocket_version
s.dependency "React-runtimescheduler"
s.dependency "Yoga"
s.dependency "glog"
add_dependency(s, "React-jsinspector", :framework_name => 'jsinspector_modern')
add_dependency(s, "RCTDeprecation")
if use_hermes
s.dependency 'React-hermes'
s.dependency 'hermes-engine'
else
s.dependency 'React-jsc'
end
end