From 184646e49169110842bafa6c02e52f6eec1e0ffa Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Mon, 12 Aug 2024 15:29:39 -0700 Subject: [PATCH] remove cxx TM autolinking (#45967) Summary: Changelog: [iOS][Android][Breaking] Pull Request resolved: https://github.com/facebook/react-native/pull/45967 this was a meaningful exploration, but since we have support in TM for jsi runtime access and that's been widely advertised and accepted, let's get rid of this. it's a bit hacky and hard to use (shown by no one using it), so i want to stop any possibility of its usage. if interested in accessing jsi::Runtime via a native module, please consider the following options: - [Android] BindingsInstaller: https://github.com/facebook/react-native/pull/44526 - [iOS] RCTTurboModuleWithJSIBindings: https://github.com/facebook/react-native/pull/44486 - C++ TurboModules (no autolinking): https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules-xplat.md Reviewed By: christophpurrer Differential Revision: D61059182 fbshipit-source-id: da5d74e2b6161ea7e8dd5f664ae0eb927bb1e2c3 --- .../ReactCommon/TurboModuleManager.cpp | 9 --- .../core/ReactCommon/CxxTurboModuleUtils.cpp | 32 --------- .../core/ReactCommon/CxxTurboModuleUtils.h | 67 ------------------- .../ios/ReactCommon/RCTTurboModuleManager.mm | 9 --- 4 files changed, 117 deletions(-) delete mode 100644 packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp delete mode 100644 packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp index 20a47db010e274..5d792fb2c669a7 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -169,14 +168,6 @@ std::shared_ptr TurboModuleManager::getTurboModule( return cxxModule; } - auto& cxxTurboModuleMapProvider = globalExportedCxxTurboModuleMap(); - auto it = cxxTurboModuleMapProvider.find(name); - if (it != cxxTurboModuleMapProvider.end()) { - auto turboModule = it->second(jsCallInvoker_); - turboModuleCache_.insert({name, turboModule}); - return turboModule; - } - static auto getTurboJavaModule = javaPart->getClass() ->getMethod(const std::string&)>( diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp deleted file mode 100644 index 4ddafa742addc9..00000000000000 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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. - */ - -#include "CxxTurboModuleUtils.h" - -namespace facebook::react { - -std::unordered_map< - std::string, - std::function< - std::shared_ptr(std::shared_ptr jsInvoker)>>& -globalExportedCxxTurboModuleMap() { - static std::unordered_map< - std::string, - std::function( - std::shared_ptr jsInvoker)>> - map; - return map; -} - -void registerCxxModuleToGlobalModuleMap( - std::string name, - std::function( - std::shared_ptr jsInvoker)> moduleProviderFunc) { - globalExportedCxxTurboModuleMap()[name] = moduleProviderFunc; -} - -} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h b/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h deleted file mode 100644 index 64c5cf3eb46fe2..00000000000000 --- a/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/CxxTurboModuleUtils.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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. - */ - -#pragma once - -#include -#include - -#include -#include - -namespace facebook::react { - -std::unordered_map< - std::string, - std::function< - std::shared_ptr(std::shared_ptr jsInvoker)>>& -globalExportedCxxTurboModuleMap(); - -void registerCxxModuleToGlobalModuleMap( - std::string name, - std::function( - std::shared_ptr jsInvoker)> moduleProviderFunc); - -} // namespace facebook::react - -/* - * You can use this macro to register your C++ TurboModule in your .cpp - * implementation if you do not have access to getTurboModule:jsInvoker: - * callback. This will register the module before main() is called, - * so it will incur a startup cost. - * - * RCT_EXPORT_CXX_MODULE_EXPERIMENTAL(ModuleExample) becomes: - * - * #pragma clang diagnostic push - * #pragma clang diagnostic ignored "-Wglobal-constructors" - * struct ModuleExampleLoad { - * ModuleExampleLoad() { - * facebook::react::registerCxxModule(name, - * [&](std::shared_ptr jsInvoker) { - * return - * std::make_shared(jsInvoker); - * }); - * } - * }; - * static ModuleExampleLoad moduleExampleLoad; - * #pragma clang diagnostic pop - * - */ -#define RCT_EXPORT_CXX_MODULE_EXPERIMENTAL(name) \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") struct \ - name##Load { \ - name##Load() { \ - facebook::react::registerCxxModuleToGlobalModuleMap( \ - #name, \ - [&](std::shared_ptr jsInvoker) { \ - return std::make_shared(jsInvoker); \ - }); \ - } \ - }; \ - static name##Load _##name##Load; \ - _Pragma("clang diagnostic pop") diff --git a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm index d113d52eedd31e..9fb81c3f91414c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +++ b/packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm @@ -29,7 +29,6 @@ #import #import #import -#import #import #import #import @@ -329,14 +328,6 @@ - (instancetype)initWithBridgeProxy:(RCTBridgeProxy *)bridgeProxy TurboModulePerfLogger::moduleCreateFail(moduleName, moduleId); } - auto &cxxTurboModuleMapProvider = globalExportedCxxTurboModuleMap(); - auto it = cxxTurboModuleMapProvider.find(moduleName); - if (it != cxxTurboModuleMapProvider.end()) { - auto turboModule = it->second(_jsInvoker); - _turboModuleCache.insert({moduleName, turboModule}); - return turboModule; - } - /** * Step 2: Look for platform-specific modules. */