From fca0442bc881760d6af599b7dcd9b361a72e3d8a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Wed, 3 Mar 2021 14:12:00 -0800 Subject: [PATCH] Extract ComponentNameRegistry out of Fabric modules Summary: This diff extracts ComponentNameRegistry out of Fabric modules This is necessary to avoid depending on Fabric and regressing APK size for other RN apps (e.g. IG) changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D26765328 fbshipit-source-id: 0a22c4279146f5243473c74a84e78fad7f08f956 --- .../facebook/react/ReactInstanceManager.java | 4 +- .../com/facebook/react/fabric/jni/OnLoad.cpp | 2 - .../java/com/facebook/react/uimanager/BUCK | 2 + .../ComponentNameResolver.java | 2 +- .../ComponentNameResolverManager.java | 9 ++- .../facebook/react/uimanager/jni/Android.mk | 37 ++++++++++++ .../com/facebook/react/uimanager/jni/BUCK | 41 +++++++++++++ .../jni/ComponentNameResolverManager.cpp | 2 +- .../jni/ComponentNameResolverManager.h | 4 +- .../facebook/react/uimanager/jni/OnLoad.cpp | 16 +++++ .../componentregistry/native/Android.mk | 29 ++++++++++ .../renderer/componentregistry/native/BUCK | 58 +++++++++++++++++++ .../NativeComponentRegistryBinding.cpp | 0 .../NativeComponentRegistryBinding.h | 0 14 files changed, 196 insertions(+), 10 deletions(-) rename ReactAndroid/src/main/java/com/facebook/react/{fabric => uimanager}/ComponentNameResolver.java (91%) rename ReactAndroid/src/main/java/com/facebook/react/{fabric => uimanager}/ComponentNameResolverManager.java (82%) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/Android.mk create mode 100644 ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/BUCK rename ReactAndroid/src/main/java/com/facebook/react/{fabric => uimanager}/jni/ComponentNameResolverManager.cpp (96%) rename ReactAndroid/src/main/java/com/facebook/react/{fabric => uimanager}/jni/ComponentNameResolverManager.h (92%) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/OnLoad.cpp create mode 100644 ReactCommon/react/renderer/componentregistry/native/Android.mk create mode 100644 ReactCommon/react/renderer/componentregistry/native/BUCK rename ReactCommon/react/renderer/componentregistry/{ => native}/NativeComponentRegistryBinding.cpp (100%) rename ReactCommon/react/renderer/componentregistry/{ => native}/NativeComponentRegistryBinding.h (100%) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 1cf66fb009863a..b6703a490450d2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -83,8 +83,6 @@ import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener; import com.facebook.react.devsupport.interfaces.DevSupportManager; import com.facebook.react.devsupport.interfaces.PackagerStatusCallback; -import com.facebook.react.fabric.ComponentNameResolver; -import com.facebook.react.fabric.ComponentNameResolverManager; import com.facebook.react.modules.appearance.AppearanceModule; import com.facebook.react.modules.appregistry.AppRegistry; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; @@ -97,6 +95,8 @@ import com.facebook.react.turbomodule.core.TurboModuleManager; import com.facebook.react.turbomodule.core.TurboModuleManagerDelegate; import com.facebook.react.turbomodule.core.interfaces.TurboModuleRegistry; +import com.facebook.react.uimanager.ComponentNameResolver; +import com.facebook.react.uimanager.ComponentNameResolverManager; import com.facebook.react.uimanager.DisplayMetricsHolder; import com.facebook.react.uimanager.ReactRoot; import com.facebook.react.uimanager.UIImplementationProvider; diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/OnLoad.cpp index 745c39cbb5ffad..03005372a658a1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/OnLoad.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/OnLoad.cpp @@ -9,7 +9,6 @@ #include "Binding.h" #include "ComponentFactory.h" -#include "ComponentNameResolverManager.h" #include "CoreComponentsRegistry.h" #include "EventBeatManager.h" #include "EventEmitterWrapper.h" @@ -22,7 +21,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { facebook::react::EventEmitterWrapper::registerNatives(); facebook::react::StateWrapperImpl::registerNatives(); facebook::react::ComponentFactory::registerNatives(); - facebook::react::ComponentNameResolverManager::registerNatives(); facebook::react::CoreComponentsRegistry::registerNatives(); }); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK index 6e8ed014b95f13..72db6f8efc59e8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BUCK @@ -32,10 +32,12 @@ rn_android_library( ":DisplayMetrics", react_native_dep("java/com/facebook/systrace:systrace"), react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"), + react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_target("java/com/facebook/debug/tags:tags"), react_native_target("java/com/facebook/debug/holder:holder"), react_native_target("java/com/facebook/react/bridge:bridge"), + react_native_target("java/com/facebook/react/uimanager/jni:jni"), react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/config:config"), react_native_target("java/com/facebook/react/module/annotations:annotations"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolver.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolver.java similarity index 91% rename from ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolver.java rename to ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolver.java index 0619fa1fe12e96..0146eabe86a1c5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolver.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolver.java @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.fabric; +package com.facebook.react.uimanager; import com.facebook.proguard.annotations.DoNotStrip; diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolverManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolverManager.java similarity index 82% rename from ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolverManager.java rename to ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolverManager.java index a5b5107d61d2bc..acd2ab1900766c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentNameResolverManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ComponentNameResolverManager.java @@ -5,16 +5,17 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.fabric; +package com.facebook.react.uimanager; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; import com.facebook.react.bridge.RuntimeExecutor; +import com.facebook.soloader.SoLoader; public class ComponentNameResolverManager { static { - FabricSoLoader.staticInit(); + staticInit(); } @DoNotStrip @@ -31,4 +32,8 @@ private native HybridData initHybrid( RuntimeExecutor runtimeExecutor, Object componentNameResolver); private native void installJSIBindings(); + + private static void staticInit() { + SoLoader.loadLibrary("uimanagerjni"); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/Android.mk b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/Android.mk new file mode 100644 index 00000000000000..a120aabed5e5c4 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/Android.mk @@ -0,0 +1,37 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := uimanagerjni + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) + +LOCAL_SHARED_LIBRARIES := libyoga libglog libfb libfbjni libglog_init libfolly_json libfolly_futures react_render_componentregistry librrc_native + +LOCAL_STATIC_LIBRARIES := + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/ + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ + +LOCAL_CFLAGS := \ + -DLOG_TAG=\"ReacTNative\" + +LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall + +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,fbgloginit) +$(call import-module,folly) +$(call import-module,fb) +$(call import-module,fbjni) +$(call import-module,yogajni) +$(call import-module,glog) + +$(call import-module,react/renderer/componentregistry) +$(call import-module,react/renderer/componentregistry/native) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/BUCK b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/BUCK new file mode 100644 index 00000000000000..e3d3a0cf7d5767 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/BUCK @@ -0,0 +1,41 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "ANDROID", "FBJNI_TARGET", "react_native_target", "react_native_xplat_target", "rn_xplat_cxx_library", "subdir_glob") + +rn_xplat_cxx_library( + name = "jni", + srcs = glob(["*.cpp"]), + headers = glob(["*.h"]), + header_namespace = "", + exported_headers = subdir_glob( + [ + ("", "**/*.h"), + ], + prefix = "react/uimanager/jni", + ), + compiler_flags = [ + "-fexceptions", + "-frtti", + "-std=c++14", + "-Wall", + ], + fbandroid_allow_jni_merging = True, + labels = ["supermodule:xplat/default/public.react_native.infra"], + platforms = (ANDROID), + preprocessor_flags = [ + "-DLOG_TAG=\"ReactNative\"", + "-DWITH_FBSYSTRACE=1", + ], + soname = "libuimanagerjni.$(ext)", + visibility = ["PUBLIC"], + deps = [ + react_native_xplat_target("runtimeexecutor:runtimeexecutor"), + react_native_xplat_target("react/renderer/componentregistry:componentregistry"), + react_native_xplat_target("react/renderer/componentregistry/native:native"), + react_native_target("jni/react/jni:jni"), + "//xplat/fbsystrace:fbsystrace", + "//xplat/folly:molly", + "//xplat/jsi:JSIDynamic", + "//xplat/jsi:jsi", + "//xplat/third-party/linker_lib:atomic", + FBJNI_TARGET, + ], +) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.cpp b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.cpp similarity index 96% rename from ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.cpp rename to ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.cpp index cbc58f54421a17..1fb8bad94db27e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.cpp @@ -13,7 +13,7 @@ #include "ComponentNameResolverManager.h" -#include +#include namespace facebook { namespace react { diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.h b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.h similarity index 92% rename from ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.h rename to ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.h index 37391305186823..4ae4081509af78 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/ComponentNameResolverManager.h +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/ComponentNameResolverManager.h @@ -26,10 +26,10 @@ class ComponentNameResolverManager : public jni::HybridClass { public: static auto constexpr kJavaDescriptor = - "Lcom/facebook/react/fabric/ComponentNameResolverManager;"; + "Lcom/facebook/react/uimanager/ComponentNameResolverManager;"; constexpr static auto ComponentNameResolverJavaDescriptor = - "com/facebook/react/fabric/ComponentNameResolver"; + "com/facebook/react/uimanager/ComponentNameResolver"; static jni::local_ref initHybrid( jni::alias_ref jThis, diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/OnLoad.cpp new file mode 100644 index 00000000000000..b7167dfbd9cce1 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/jni/OnLoad.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include "ComponentNameResolverManager.h" + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { + return facebook::jni::initialize(vm, [] { + facebook::react::ComponentNameResolverManager::registerNatives(); + }); +} diff --git a/ReactCommon/react/renderer/componentregistry/native/Android.mk b/ReactCommon/react/renderer/componentregistry/native/Android.mk new file mode 100644 index 00000000000000..4d6d72d89f130f --- /dev/null +++ b/ReactCommon/react/renderer/componentregistry/native/Android.mk @@ -0,0 +1,29 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := rrc_native + +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../ + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) + +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../ + +LOCAL_SHARED_LIBRARIES := libjsi libfolly_futures libfolly_json libreact_render_core libreact_render_debug libreact_utils libglog_init libreact_debug + +LOCAL_CFLAGS := \ + -DLOG_TAG=\"Fabric\" + +LOCAL_CFLAGS += -fexceptions -frtti -std=c++14 -Wall + +include $(BUILD_SHARED_LIBRARY) + +$(call import-module,fbgloginit) +$(call import-module,folly) +$(call import-module,jsi) diff --git a/ReactCommon/react/renderer/componentregistry/native/BUCK b/ReactCommon/react/renderer/componentregistry/native/BUCK new file mode 100644 index 00000000000000..6239d64523e457 --- /dev/null +++ b/ReactCommon/react/renderer/componentregistry/native/BUCK @@ -0,0 +1,58 @@ +load( + "//tools/build_defs/oss:rn_defs.bzl", + "ANDROID", + "APPLE", + "CXX", + "get_apple_compiler_flags", + "get_apple_inspector_flags", + "get_preprocessor_flags_for_build_mode", + "rn_xplat_cxx_library", + "subdir_glob", +) + +APPLE_COMPILER_FLAGS = get_apple_compiler_flags() + +rn_xplat_cxx_library( + name = "native", + srcs = glob( + ["**/*.cpp"], + exclude = glob(["tests/**/*.cpp"]), + ), + headers = glob( + ["**/*.h"], + exclude = glob(["tests/**/*.h"]), + ), + header_namespace = "", + exported_headers = subdir_glob( + [ + ("", "*.h"), + ], + prefix = "react/renderer/componentregistry/native", + ), + compiler_flags = [ + "-fexceptions", + "-frtti", + "-std=c++14", + "-Wall", + ], + fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, + fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), + force_static = True, + labels = ["supermodule:xplat/default/public.react_native.infra"], + macosx_tests_override = [], + platforms = (ANDROID, APPLE, CXX), + preprocessor_flags = [ + "-DLOG_TAG=\"ReactNative\"", + "-DWITH_FBSYSTRACE=1", + ], + visibility = ["PUBLIC"], + deps = [ + "//third-party/glog:glog", + "//xplat/fbsystrace:fbsystrace", + "//xplat/folly:headers_only", + "//xplat/folly:memory", + "//xplat/folly:molly", + "//xplat/jsi:JSIDynamic", + "//xplat/jsi:jsi", + ], +) diff --git a/ReactCommon/react/renderer/componentregistry/NativeComponentRegistryBinding.cpp b/ReactCommon/react/renderer/componentregistry/native/NativeComponentRegistryBinding.cpp similarity index 100% rename from ReactCommon/react/renderer/componentregistry/NativeComponentRegistryBinding.cpp rename to ReactCommon/react/renderer/componentregistry/native/NativeComponentRegistryBinding.cpp diff --git a/ReactCommon/react/renderer/componentregistry/NativeComponentRegistryBinding.h b/ReactCommon/react/renderer/componentregistry/native/NativeComponentRegistryBinding.h similarity index 100% rename from ReactCommon/react/renderer/componentregistry/NativeComponentRegistryBinding.h rename to ReactCommon/react/renderer/componentregistry/native/NativeComponentRegistryBinding.h