From f1c614bd0e8625bc246aa953e93b9c9f1940ea15 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 6 Jun 2022 08:07:14 -0700 Subject: [PATCH] Build RN Tester with CMake (#33937) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/33937 This moves the build of RNTester from Unix Make to CMake This will serve as a blueprint for users that are looking into using CMake end-to-end in their buildls. In order to make this possible I had to: * Add an `Android-prebuilt.cmake` file that works similar to the `Android-prebuilt.mk` for feeding prebuilt .so files to the consumer build. * Update the codegen to use `JSI_EXPORT` on several objects/classes as CMake has stricter visibility rules than Make * Update the sample native module in `nativemodule/samples/platform/android/` to use CMake instead of Make Changelog: [Internal] [Changed] - Build RN Tester with CMake Reviewed By: cipolleschi Differential Revision: D36760309 fbshipit-source-id: b99449a4b824b6c0064e833d4bcd5969b141df70 --- .../cmake-utils/Android-prebuilt.cmake | 231 ++++++++++++++++++ .../samples/platform/android/Android.mk | 23 -- .../samples/platform/android/CMakeLists.txt | 19 ++ .../GenerateEventEmitterH-test.js.snap | 22 +- .../__snapshots__/GeneratePropsH-test.js.snap | 48 ++-- .../GenerateShadowNodeH-test.js.snap | 46 ++-- .../components/GenerateEventEmitterH.js | 3 +- .../generators/components/GeneratePropsH.js | 3 +- .../components/GenerateShadowNodeH.js | 3 +- .../GenerateEventEmitterH-test.js.snap | 34 ++- .../__snapshots__/GeneratePropsH-test.js.snap | 82 ++++--- .../GenerateShadowNodeH-test.js.snap | 78 ++++-- .../generators/modules/GenerateModuleJniH.js | 2 + .../GenerateModuleJniH-test.js.snap | 16 ++ packages/rn-tester/android/app/build.gradle | 30 +-- .../android/app/src/main/jni/Android.mk | 46 ---- .../android/app/src/main/jni/CMakeLists.txt | 40 +++ 17 files changed, 545 insertions(+), 181 deletions(-) create mode 100644 ReactAndroid/cmake-utils/Android-prebuilt.cmake delete mode 100644 ReactCommon/react/nativemodule/samples/platform/android/Android.mk create mode 100644 ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt delete mode 100644 packages/rn-tester/android/app/src/main/jni/Android.mk create mode 100644 packages/rn-tester/android/app/src/main/jni/CMakeLists.txt diff --git a/ReactAndroid/cmake-utils/Android-prebuilt.cmake b/ReactAndroid/cmake-utils/Android-prebuilt.cmake new file mode 100644 index 00000000000000..03be4be02aa8c2 --- /dev/null +++ b/ReactAndroid/cmake-utils/Android-prebuilt.cmake @@ -0,0 +1,231 @@ +# 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. + +# This configuration provides access to most common React Native prebuilt .so files +# to avoid recompiling each of the libraries outside of ReactAndroid NDK compilation. +# Hosting app's/library's CMakeLists.txt can include this Android-prebuilt.cmake file to +# get access to those libraries to depend on. +# NOTES: +# * Currently, it assumes building React Native from source. +# * Not every .so is listed here (yet). +# * Static libs are not covered here (yet). + +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE on) + +# FIRST_PARTY_NDK_DIR contains vendored source code from other FB frameworks +# like Yoga, FBJNI, etc. +set(FIRST_PARTY_NDK_DIR ${REACT_ANDROID_DIR}/src/main/jni/first-party) +# THIRD_PARTY_NDK_DIR is where we're downloading third-party native +# frameworks such as libevent, boost, etc. +set(THIRD_PARTY_NDK_DIR ${REACT_ANDROID_BUILD_DIR}/third-party-ndk) +# REACT_ANDROID_SRC_DIR is the root of ReactAndroid source code (Java & JNI) +set(REACT_ANDROID_SRC_DIR ${REACT_ANDROID_DIR}/src/main) +# REACT_COMMON_DIR is the root of ReactCommon source code (C++ only) +set(REACT_COMMON_DIR ${REACT_ANDROID_DIR}/../ReactCommon) +# REACT_GENERATED_SRC_DIR is the folder where the codegen for rncore will output +set(REACT_GENERATED_SRC_DIR ${REACT_ANDROID_BUILD_DIR}/generated/source) +# REACT_NDK_EXPORT_DIR is the folder where the .so will be copied for being inported +# in the local project by the packageReactDebugNdkLibs/packageReactReleaseNdkLibs +set(REACT_NDK_EXPORT_DIR ${PROJECT_BUILD_DIR}/react-ndk/exported) + +## fb +add_library(fb SHARED IMPORTED GLOBAL) +set_target_properties(fb + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfb.so) +target_include_directories(fb + INTERFACE + ${FIRST_PARTY_NDK_DIR}/fb/include) + +## folly_runtime +add_library(folly_runtime SHARED IMPORTED GLOBAL) +set_target_properties(folly_runtime + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfolly_runtime.so) +target_include_directories(folly_runtime + INTERFACE + ${THIRD_PARTY_NDK_DIR}/boost/boost_1_76_0 + ${THIRD_PARTY_NDK_DIR}/double-conversion + ${THIRD_PARTY_NDK_DIR}/folly) +target_compile_options(folly_runtime + INTERFACE + -DFOLLY_NO_CONFIG=1 + -DFOLLY_HAVE_CLOCK_GETTIME=1 + -DFOLLY_HAVE_MEMRCHR=1 + -DFOLLY_USE_LIBCPP=1 + -DFOLLY_MOBILE=1 + -DFOLLY_HAVE_XSI_STRERROR_R=1) + +## glog +add_library(glog SHARED IMPORTED GLOBAL) +set_target_properties(glog + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libglog.so) +target_include_directories(glog INTERFACE ${THIRD_PARTY_NDK_DIR}/glog/exported) + +## yoga +add_library(yoga SHARED IMPORTED GLOBAL) +set_target_properties(yoga + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libyoga.so) +target_include_directories(yoga + INTERFACE + ${FIRST_PARTY_NDK_DIR}/yogajni/jni + ${REACT_COMMON_DIR}/yoga) +target_compile_options(yoga + INTERFACE + -fvisibility=hidden + -fexceptions + -frtti + -O3) +target_link_libraries(yoga INTERFACE log android) + +## react_nativemodule_core +add_library(react_nativemodule_core SHARED IMPORTED GLOBAL) +set_target_properties(react_nativemodule_core + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_nativemodule_core.so) +target_include_directories(react_nativemodule_core + INTERFACE + ${REACT_ANDROID_SRC_DIR}/jni + ${REACT_COMMON_DIR} + ${REACT_COMMON_DIR}/callinvoker + ${REACT_COMMON_DIR}/jsi + ${REACT_COMMON_DIR}/react/nativemodule/core + ${REACT_COMMON_DIR}/react/nativemodule/core/platform/android) +target_link_libraries(react_nativemodule_core INTERFACE folly_runtime) + +## turbomodulejsijni +add_library(turbomodulejsijni SHARED IMPORTED GLOBAL) +set_target_properties(turbomodulejsijni + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libturbomodulejsijni.so) +target_include_directories(turbomodulejsijni + INTERFACE + ${REACT_ANDROID_SRC_DIR}/java/com/facebook/react/turbomodule/core/jni) + +## react_render_core +add_library(react_render_core SHARED IMPORTED GLOBAL) +set_target_properties(react_render_core + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_core.so) +target_include_directories(react_render_core + INTERFACE + ${REACT_COMMON_DIR} + ${REACT_COMMON_DIR}/react/renderer/core) + +## react_render_debug +add_library(react_render_debug SHARED IMPORTED GLOBAL) +set_target_properties(react_render_debug + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_debug.so) +target_include_directories(react_render_debug INTERFACE ${REACT_COMMON_DIR}/react/renderer/debug) + +## react_debug +add_library(react_debug SHARED IMPORTED GLOBAL) +set_target_properties(react_debug + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_debug.so) +target_include_directories(react_debug INTERFACE ${REACT_COMMON_DIR}/react/debug) +target_link_libraries(react_nativemodule_core INTERFACE folly_runtime) + +## react_render_graphics +add_library(react_render_graphics SHARED IMPORTED GLOBAL) +set_target_properties(react_render_graphics + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_graphics.so) +target_include_directories(react_render_graphics + INTERFACE + ${REACT_COMMON_DIR}/react/renderer/graphics + ${REACT_COMMON_DIR}/react/renderer/graphics/platform/cxx) + +## react_render_imagemanager +add_library(react_render_imagemanager SHARED IMPORTED GLOBAL) +set_target_properties(react_render_imagemanager + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_imagemanager.so) +target_include_directories(react_render_imagemanager + INTERFACE + ${REACT_COMMON_DIR}/react/renderer/imagemanager + ${REACT_COMMON_DIR}/react/renderer/imagemanager/platform/cxx) + +## react_render_mounting +add_library(react_render_mounting SHARED IMPORTED GLOBAL) +set_target_properties(react_render_mounting + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_mounting.so) +target_include_directories(react_render_mounting INTERFACE ${REACT_COMMON_DIR}/react/renderer/mounting) + +## react_render_mapbuffer +add_library(react_render_mapbuffer SHARED IMPORTED GLOBAL) +set_target_properties(react_render_mapbuffer + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_mapbuffer.so) +target_include_directories(react_render_mapbuffer INTERFACE ${REACT_COMMON_DIR}/react/renderer/mapbuffer) + +## rrc_view +add_library(rrc_view SHARED IMPORTED GLOBAL) +set_target_properties(rrc_view + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/librrc_view.so) +target_include_directories(rrc_view INTERFACE ${REACT_COMMON_DIR}/react/renderer/components/view) + +## fabricjni +add_library(fabricjni SHARED IMPORTED GLOBAL) +set_target_properties(fabricjni + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfabricjni.so) +target_include_directories(fabricjni INTERFACE ${REACT_ANDROID_SRC_DIR}/java/com/facebook/react/fabric/jni) + +## react_render_componentregistry +add_library(react_render_componentregistry SHARED IMPORTED GLOBAL) +set_target_properties(react_render_componentregistry + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_componentregistry.so) +target_include_directories(react_render_componentregistry INTERFACE ${REACT_COMMON_DIR}/react/renderer/componentregistry) + +## jsi +add_library(jsi SHARED IMPORTED GLOBAL) +set_target_properties(jsi + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libjsi.so) +target_include_directories(jsi INTERFACE ${REACT_COMMON_DIR}/jsi) + +## react_codegen_rncore +add_library(react_codegen_rncore SHARED IMPORTED GLOBAL) +set_target_properties(react_codegen_rncore + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_codegen_rncore.so) +target_include_directories(react_codegen_rncore INTERFACE ${REACT_GENERATED_SRC_DIR}/codegen/jni) + +## runtimeexecutor +add_library(runtimeexecutor SHARED IMPORTED GLOBAL) +set_target_properties(runtimeexecutor + PROPERTIES + IMPORTED_LOCATION + ${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libruntimeexecutor.so) +target_include_directories(runtimeexecutor INTERFACE ${REACT_COMMON_DIR}/runtimeexecutor) + +## fbjni +add_subdirectory(${FIRST_PARTY_NDK_DIR}/fbjni fbjni_build) diff --git a/ReactCommon/react/nativemodule/samples/platform/android/Android.mk b/ReactCommon/react/nativemodule/samples/platform/android/Android.mk deleted file mode 100644 index 5c4458ec82a8f2..00000000000000 --- a/ReactCommon/react/nativemodule/samples/platform/android/Android.mk +++ /dev/null @@ -1,23 +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. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -LOCAL_MODULE := sampleturbomodule -LOCAL_C_INCLUDES := $(LOCAL_PATH) -LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/ReactCommon/*.cpp) -LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) -LOCAL_SHARED_LIBRARIES := \ - libfbjni \ - libjsi \ - libreact_nativemodule_core - -LOCAL_CFLAGS := \ - -DLOG_TAG=\"ReactNative\" -LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall - -include $(BUILD_STATIC_LIBRARY) diff --git a/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt b/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt new file mode 100644 index 00000000000000..84d080c08398a6 --- /dev/null +++ b/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt @@ -0,0 +1,19 @@ +# 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. + +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE on) + +add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"ReactNative\") + +file(GLOB sampleturbomodule_SRC CONFIGURE_DEPENDS ReactCommon/*.cpp) +add_library(sampleturbomodule STATIC ${sampleturbomodule_SRC}) + +target_include_directories(sampleturbomodule PUBLIC .) + +target_link_libraries(sampleturbomodule + fbjni + jsi + react_nativemodule_core) diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap index 32980f779ae3c1..8ea473f15a6833 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -14,6 +14,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -40,6 +41,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -66,6 +68,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -92,6 +95,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -118,6 +122,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -144,11 +149,12 @@ Object { #pragma once #include +#include namespace facebook { namespace react { -class EventNestedObjectPropsNativeComponentViewEventEmitter : public ViewEventEmitter { +class JSI_EXPORT EventNestedObjectPropsNativeComponentViewEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -189,11 +195,12 @@ Object { #pragma once #include +#include namespace facebook { namespace react { -class EventPropsNativeComponentViewEventEmitter : public ViewEventEmitter { +class JSI_EXPORT EventPropsNativeComponentViewEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -269,6 +276,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -295,6 +303,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -321,6 +330,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -347,11 +357,12 @@ Object { #pragma once #include +#include namespace facebook { namespace react { -class InterfaceOnlyNativeComponentViewEventEmitter : public ViewEventEmitter { +class JSI_EXPORT InterfaceOnlyNativeComponentViewEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -382,6 +393,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -408,6 +420,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -434,6 +447,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -460,6 +474,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { @@ -486,6 +501,7 @@ Object { #pragma once #include +#include namespace facebook { namespace react { diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap index 80ecae521eca0c..ba79b2cf4149fb 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap @@ -14,6 +14,7 @@ Object { #pragma once #include +#include #include #include #include @@ -105,7 +106,7 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -class ArrayPropsNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT ArrayPropsNativeComponentViewProps final : public ViewProps { public: ArrayPropsNativeComponentViewProps() = default; ArrayPropsNativeComponentViewProps(const PropsParserContext& context, const ArrayPropsNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -142,13 +143,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class BooleanPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT BooleanPropNativeComponentViewProps final : public ViewProps { public: BooleanPropNativeComponentViewProps() = default; BooleanPropNativeComponentViewProps(const PropsParserContext& context, const BooleanPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -178,6 +180,7 @@ Object { */ #pragma once +#include #include #include #include @@ -185,7 +188,7 @@ Object { namespace facebook { namespace react { -class ColorPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT ColorPropNativeComponentViewProps final : public ViewProps { public: ColorPropNativeComponentViewProps() = default; ColorPropNativeComponentViewProps(const PropsParserContext& context, const ColorPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -214,13 +217,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class EdgeInsetsPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT EdgeInsetsPropNativeComponentViewProps final : public ViewProps { public: EdgeInsetsPropNativeComponentViewProps() = default; EdgeInsetsPropNativeComponentViewProps(const PropsParserContext& context, const EdgeInsetsPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -249,6 +253,7 @@ Object { */ #pragma once +#include #include #include @@ -303,7 +308,7 @@ static inline std::string toString(const EnumPropNativeComponentViewIntervals &v } } -class EnumPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT EnumPropNativeComponentViewProps final : public ViewProps { public: EnumPropNativeComponentViewProps() = default; EnumPropNativeComponentViewProps(const PropsParserContext& context, const EnumPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -333,13 +338,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class EventNestedObjectPropsNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT EventNestedObjectPropsNativeComponentViewProps final : public ViewProps { public: EventNestedObjectPropsNativeComponentViewProps() = default; EventNestedObjectPropsNativeComponentViewProps(const PropsParserContext& context, const EventNestedObjectPropsNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -368,13 +374,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class EventPropsNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT EventPropsNativeComponentViewProps final : public ViewProps { public: EventPropsNativeComponentViewProps() = default; EventPropsNativeComponentViewProps(const PropsParserContext& context, const EventPropsNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -403,13 +410,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class FloatPropsNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT FloatPropsNativeComponentViewProps final : public ViewProps { public: FloatPropsNativeComponentViewProps() = default; FloatPropsNativeComponentViewProps(const PropsParserContext& context, const FloatPropsNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -444,6 +452,7 @@ Object { */ #pragma once +#include #include #include #include @@ -451,7 +460,7 @@ Object { namespace facebook { namespace react { -class ImagePropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT ImagePropNativeComponentViewProps final : public ViewProps { public: ImagePropNativeComponentViewProps() = default; ImagePropNativeComponentViewProps(const PropsParserContext& context, const ImagePropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -480,13 +489,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class IntegerPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT IntegerPropNativeComponentViewProps final : public ViewProps { public: IntegerPropNativeComponentViewProps() = default; IntegerPropNativeComponentViewProps(const PropsParserContext& context, const IntegerPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -517,13 +527,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class InterfaceOnlyNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT InterfaceOnlyNativeComponentViewProps final : public ViewProps { public: InterfaceOnlyNativeComponentViewProps() = default; InterfaceOnlyNativeComponentViewProps(const PropsParserContext& context, const InterfaceOnlyNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -552,6 +563,7 @@ Object { */ #pragma once +#include #include #include #include @@ -561,7 +573,7 @@ Object { namespace facebook { namespace react { -class MultiNativePropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT MultiNativePropNativeComponentViewProps final : public ViewProps { public: MultiNativePropNativeComponentViewProps() = default; MultiNativePropNativeComponentViewProps(const PropsParserContext& context, const MultiNativePropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -593,13 +605,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class NoPropsNoEventsNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT NoPropsNoEventsNativeComponentViewProps final : public ViewProps { public: NoPropsNoEventsNativeComponentViewProps() = default; NoPropsNoEventsNativeComponentViewProps(const PropsParserContext& context, const NoPropsNoEventsNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -628,6 +641,7 @@ Object { */ #pragma once +#include #include #include #include @@ -762,7 +776,7 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu static inline std::string toString(const ObjectPropsNativeComponentObjectPrimitiveRequiredPropStruct &value) { return \\"[Object ObjectPropsNativeComponentObjectPrimitiveRequiredPropStruct]\\"; } -class ObjectPropsNativeComponentProps final : public ViewProps { +class JSI_EXPORT ObjectPropsNativeComponentProps final : public ViewProps { public: ObjectPropsNativeComponentProps() = default; ObjectPropsNativeComponentProps(const PropsParserContext& context, const ObjectPropsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -793,6 +807,7 @@ Object { */ #pragma once +#include #include #include #include @@ -800,7 +815,7 @@ Object { namespace facebook { namespace react { -class PointPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT PointPropNativeComponentViewProps final : public ViewProps { public: PointPropNativeComponentViewProps() = default; PointPropNativeComponentViewProps(const PropsParserContext& context, const PointPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); @@ -829,13 +844,14 @@ Object { */ #pragma once +#include #include #include namespace facebook { namespace react { -class StringPropNativeComponentViewProps final : public ViewProps { +class JSI_EXPORT StringPropNativeComponentViewProps final : public ViewProps { public: StringPropNativeComponentViewProps() = default; StringPropNativeComponentViewProps(const PropsParserContext& context, const StringPropNativeComponentViewProps &sourceProps, const RawProps &rawProps); diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap index 6faa170602375f..84724fbf4bd807 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -16,11 +16,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char ArrayPropsNativeComponentViewComponentName[]; +JSI_EXPORT extern const char ArrayPropsNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -51,11 +52,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char BooleanPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char BooleanPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -86,11 +88,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char ColorPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char ColorPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -121,11 +124,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char EdgeInsetsPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char EdgeInsetsPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -156,11 +160,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char EnumPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char EnumPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -192,11 +197,12 @@ Object { #include #include #include +#include namespace facebook { namespace react { -extern const char EventNestedObjectPropsNativeComponentViewComponentName[]; +JSI_EXPORT extern const char EventNestedObjectPropsNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -229,11 +235,12 @@ Object { #include #include #include +#include namespace facebook { namespace react { -extern const char EventPropsNativeComponentViewComponentName[]; +JSI_EXPORT extern const char EventPropsNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -265,11 +272,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char FloatPropsNativeComponentViewComponentName[]; +JSI_EXPORT extern const char FloatPropsNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -300,11 +308,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char ImagePropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char ImagePropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -335,11 +344,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char IntegerPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char IntegerPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -370,6 +380,7 @@ Object { #include #include +#include namespace facebook { namespace react { @@ -398,11 +409,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char MultiNativePropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char MultiNativePropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -433,11 +445,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char NoPropsNoEventsNativeComponentViewComponentName[]; +JSI_EXPORT extern const char NoPropsNoEventsNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -468,11 +481,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char ObjectPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char ObjectPropsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -503,11 +517,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char PointPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char PointPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. @@ -538,11 +553,12 @@ Object { #include #include +#include namespace facebook { namespace react { -extern const char StringPropNativeComponentViewComponentName[]; +JSI_EXPORT extern const char StringPropNativeComponentViewComponentName[]; /* * \`ShadowNode\` for component. diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js index c3637b02bbc643..8eba4d79f6ab2c 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js @@ -48,6 +48,7 @@ const FileTemplate = ({componentEmitters}: {componentEmitters: string}) => ` #pragma once #include +#include namespace facebook { namespace react { @@ -68,7 +69,7 @@ const ComponentTemplate = ({ events: string, }) => ` -class ${className}EventEmitter : public ViewEventEmitter { +class JSI_EXPORT ${className}EventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; diff --git a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js index df4d37abb02ade..fc8202a1c09e7e 100644 --- a/packages/react-native-codegen/src/generators/components/GeneratePropsH.js +++ b/packages/react-native-codegen/src/generators/components/GeneratePropsH.js @@ -76,7 +76,7 @@ const ClassTemplate = ({ ` ${enums} ${structs} -class ${className} final${extendClasses} { +class JSI_EXPORT ${className} final${extendClasses} { public: ${className}() = default; ${className}(const PropsParserContext& context, const ${className} &sourceProps, const RawProps &rawProps); @@ -538,6 +538,7 @@ function getExtendsImports( const imports: Set = new Set(); imports.add('#include '); + imports.add('#include '); extendsProps.forEach(extendProps => { switch (extendProps.type) { diff --git a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js index f661afa9e857d5..5159bd6168568a 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js @@ -37,6 +37,7 @@ const FileTemplate = ({ ${imports}#include #include +#include namespace facebook { namespace react { @@ -55,7 +56,7 @@ const ComponentTemplate = ({ eventEmitter: string, }) => ` -extern const char ${className}ComponentName[]; +JSI_EXPORT extern const char ${className}ComponentName[]; /* * \`ShadowNode\` for <${className}> component. diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap index f04e069ca25311..942ca4c88eadae 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -14,6 +14,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -40,6 +41,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -66,6 +68,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -92,6 +95,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -118,6 +122,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -144,6 +149,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -170,6 +176,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -196,11 +203,12 @@ Map { #pragma once #include +#include namespace facebook { namespace react { -class EventsNestedObjectNativeComponentEventEmitter : public ViewEventEmitter { +class JSI_EXPORT EventsNestedObjectNativeComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -241,11 +249,12 @@ Map { #pragma once #include +#include namespace facebook { namespace react { -class EventsNativeComponentEventEmitter : public ViewEventEmitter { +class JSI_EXPORT EventsNativeComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -305,11 +314,12 @@ Map { #pragma once #include +#include namespace facebook { namespace react { -class InterfaceOnlyComponentEventEmitter : public ViewEventEmitter { +class JSI_EXPORT InterfaceOnlyComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -346,6 +356,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -372,6 +383,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -398,6 +410,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -424,6 +437,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -450,6 +464,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -476,6 +491,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -502,6 +518,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -528,11 +545,12 @@ Map { #pragma once #include +#include namespace facebook { namespace react { -class InterfaceOnlyComponentEventEmitter : public ViewEventEmitter { +class JSI_EXPORT InterfaceOnlyComponentEventEmitter : public ViewEventEmitter { public: using ViewEventEmitter::ViewEventEmitter; @@ -563,6 +581,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -589,6 +608,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -615,6 +635,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -641,6 +662,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -667,6 +689,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -693,6 +716,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -719,6 +743,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { @@ -745,6 +770,7 @@ Map { #pragma once #include +#include namespace facebook { namespace react { diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap index f739b225fc0f55..bdede2c33e8793 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GeneratePropsH-test.js.snap @@ -14,6 +14,7 @@ Map { #pragma once #include +#include #include #include #include @@ -190,7 +191,7 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -class ArrayPropsNativeComponentProps final : public ViewProps { +class JSI_EXPORT ArrayPropsNativeComponentProps final : public ViewProps { public: ArrayPropsNativeComponentProps() = default; ArrayPropsNativeComponentProps(const PropsParserContext& context, const ArrayPropsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -229,6 +230,7 @@ Map { */ #pragma once +#include #include #include #include @@ -276,7 +278,7 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu } } -class ArrayPropsNativeComponentProps final : public ViewProps { +class JSI_EXPORT ArrayPropsNativeComponentProps final : public ViewProps { public: ArrayPropsNativeComponentProps() = default; ArrayPropsNativeComponentProps(const PropsParserContext& context, const ArrayPropsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -305,13 +307,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class BooleanPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT BooleanPropNativeComponentProps final : public ViewProps { public: BooleanPropNativeComponentProps() = default; BooleanPropNativeComponentProps(const PropsParserContext& context, const BooleanPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -340,6 +343,7 @@ Map { */ #pragma once +#include #include #include #include @@ -347,7 +351,7 @@ Map { namespace facebook { namespace react { -class ColorPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT ColorPropNativeComponentProps final : public ViewProps { public: ColorPropNativeComponentProps() = default; ColorPropNativeComponentProps(const PropsParserContext& context, const ColorPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -376,13 +380,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class CommandNativeComponentProps final : public ViewProps { +class JSI_EXPORT CommandNativeComponentProps final : public ViewProps { public: CommandNativeComponentProps() = default; CommandNativeComponentProps(const PropsParserContext& context, const CommandNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -411,13 +416,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class CommandNativeComponentProps final : public ViewProps { +class JSI_EXPORT CommandNativeComponentProps final : public ViewProps { public: CommandNativeComponentProps() = default; CommandNativeComponentProps(const PropsParserContext& context, const CommandNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -446,13 +452,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class DoublePropNativeComponentProps final : public ViewProps { +class JSI_EXPORT DoublePropNativeComponentProps final : public ViewProps { public: DoublePropNativeComponentProps() = default; DoublePropNativeComponentProps(const PropsParserContext& context, const DoublePropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -486,13 +493,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class EventsNestedObjectNativeComponentProps final : public ViewProps { +class JSI_EXPORT EventsNestedObjectNativeComponentProps final : public ViewProps { public: EventsNestedObjectNativeComponentProps() = default; EventsNestedObjectNativeComponentProps(const PropsParserContext& context, const EventsNestedObjectNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -521,13 +529,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class EventsNativeComponentProps final : public ViewProps { +class JSI_EXPORT EventsNativeComponentProps final : public ViewProps { public: EventsNativeComponentProps() = default; EventsNativeComponentProps(const PropsParserContext& context, const EventsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -556,13 +565,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class InterfaceOnlyComponentProps final : public ViewProps { +class JSI_EXPORT InterfaceOnlyComponentProps final : public ViewProps { public: InterfaceOnlyComponentProps() = default; InterfaceOnlyComponentProps(const PropsParserContext& context, const InterfaceOnlyComponentProps &sourceProps, const RawProps &rawProps); @@ -591,13 +601,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class ExcludedAndroidComponentProps final : public ViewProps { +class JSI_EXPORT ExcludedAndroidComponentProps final : public ViewProps { public: ExcludedAndroidComponentProps() = default; ExcludedAndroidComponentProps(const PropsParserContext& context, const ExcludedAndroidComponentProps &sourceProps, const RawProps &rawProps); @@ -626,13 +637,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class ExcludedAndroidIosComponentProps final : public ViewProps { +class JSI_EXPORT ExcludedAndroidIosComponentProps final : public ViewProps { public: ExcludedAndroidIosComponentProps() = default; ExcludedAndroidIosComponentProps(const PropsParserContext& context, const ExcludedAndroidIosComponentProps &sourceProps, const RawProps &rawProps); @@ -661,13 +673,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class FloatPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT FloatPropNativeComponentProps final : public ViewProps { public: FloatPropNativeComponentProps() = default; FloatPropNativeComponentProps(const PropsParserContext& context, const FloatPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -701,6 +714,7 @@ Map { */ #pragma once +#include #include #include #include @@ -708,7 +722,7 @@ Map { namespace facebook { namespace react { -class ImagePropNativeComponentProps final : public ViewProps { +class JSI_EXPORT ImagePropNativeComponentProps final : public ViewProps { public: ImagePropNativeComponentProps() = default; ImagePropNativeComponentProps(const PropsParserContext& context, const ImagePropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -737,6 +751,7 @@ Map { */ #pragma once +#include #include #include #include @@ -744,7 +759,7 @@ Map { namespace facebook { namespace react { -class InsetsPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT InsetsPropNativeComponentProps final : public ViewProps { public: InsetsPropNativeComponentProps() = default; InsetsPropNativeComponentProps(const PropsParserContext& context, const InsetsPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -773,6 +788,7 @@ Map { */ #pragma once +#include #include #include @@ -806,7 +822,7 @@ static inline std::string toString(const Int32EnumPropsNativeComponentMaxInterva } } -class Int32EnumPropsNativeComponentProps final : public ViewProps { +class JSI_EXPORT Int32EnumPropsNativeComponentProps final : public ViewProps { public: Int32EnumPropsNativeComponentProps() = default; Int32EnumPropsNativeComponentProps(const PropsParserContext& context, const Int32EnumPropsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -835,13 +851,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class IntegerPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT IntegerPropNativeComponentProps final : public ViewProps { public: IntegerPropNativeComponentProps() = default; IntegerPropNativeComponentProps(const PropsParserContext& context, const IntegerPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -872,13 +889,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class InterfaceOnlyComponentProps final : public ViewProps { +class JSI_EXPORT InterfaceOnlyComponentProps final : public ViewProps { public: InterfaceOnlyComponentProps() = default; InterfaceOnlyComponentProps(const PropsParserContext& context, const InterfaceOnlyComponentProps &sourceProps, const RawProps &rawProps); @@ -907,6 +925,7 @@ Map { */ #pragma once +#include #include #include #include @@ -916,7 +935,7 @@ Map { namespace facebook { namespace react { -class ImageColorPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT ImageColorPropNativeComponentProps final : public ViewProps { public: ImageColorPropNativeComponentProps() = default; ImageColorPropNativeComponentProps(const PropsParserContext& context, const ImageColorPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -948,13 +967,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class NoPropsNoEventsComponentProps final : public ViewProps { +class JSI_EXPORT NoPropsNoEventsComponentProps final : public ViewProps { public: NoPropsNoEventsComponentProps() = default; NoPropsNoEventsComponentProps(const PropsParserContext& context, const NoPropsNoEventsComponentProps &sourceProps, const RawProps &rawProps); @@ -983,6 +1003,7 @@ Map { */ #pragma once +#include #include #include #include @@ -1209,7 +1230,7 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu static inline std::string toString(const ObjectPropsObjectPropStruct &value) { return \\"[Object ObjectPropsObjectPropStruct]\\"; } -class ObjectPropsProps final : public ViewProps { +class JSI_EXPORT ObjectPropsProps final : public ViewProps { public: ObjectPropsProps() = default; ObjectPropsProps(const PropsParserContext& context, const ObjectPropsProps &sourceProps, const RawProps &rawProps); @@ -1238,6 +1259,7 @@ Map { */ #pragma once +#include #include #include #include @@ -1245,7 +1267,7 @@ Map { namespace facebook { namespace react { -class PointPropNativeComponentProps final : public ViewProps { +class JSI_EXPORT PointPropNativeComponentProps final : public ViewProps { public: PointPropNativeComponentProps() = default; PointPropNativeComponentProps(const PropsParserContext& context, const PointPropNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -1274,6 +1296,7 @@ Map { */ #pragma once +#include #include #include @@ -1298,7 +1321,7 @@ static inline std::string toString(const StringEnumPropsNativeComponentAlignment } } -class StringEnumPropsNativeComponentProps final : public ViewProps { +class JSI_EXPORT StringEnumPropsNativeComponentProps final : public ViewProps { public: StringEnumPropsNativeComponentProps() = default; StringEnumPropsNativeComponentProps(const PropsParserContext& context, const StringEnumPropsNativeComponentProps &sourceProps, const RawProps &rawProps); @@ -1327,13 +1350,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class StringPropComponentProps final : public ViewProps { +class JSI_EXPORT StringPropComponentProps final : public ViewProps { public: StringPropComponentProps() = default; StringPropComponentProps(const PropsParserContext& context, const StringPropComponentProps &sourceProps, const RawProps &rawProps); @@ -1363,13 +1387,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class MultiFile1NativeComponentProps final : public ViewProps { +class JSI_EXPORT MultiFile1NativeComponentProps final : public ViewProps { public: MultiFile1NativeComponentProps() = default; MultiFile1NativeComponentProps(const PropsParserContext& context, const MultiFile1NativeComponentProps &sourceProps, const RawProps &rawProps); @@ -1379,7 +1404,7 @@ class MultiFile1NativeComponentProps final : public ViewProps { bool disabled{false}; }; -class MultiFile2NativeComponentProps final : public ViewProps { +class JSI_EXPORT MultiFile2NativeComponentProps final : public ViewProps { public: MultiFile2NativeComponentProps() = default; MultiFile2NativeComponentProps(const PropsParserContext& context, const MultiFile2NativeComponentProps &sourceProps, const RawProps &rawProps); @@ -1408,13 +1433,14 @@ Map { */ #pragma once +#include #include #include namespace facebook { namespace react { -class MultiComponent1NativeComponentProps final : public ViewProps { +class JSI_EXPORT MultiComponent1NativeComponentProps final : public ViewProps { public: MultiComponent1NativeComponentProps() = default; MultiComponent1NativeComponentProps(const PropsParserContext& context, const MultiComponent1NativeComponentProps &sourceProps, const RawProps &rawProps); @@ -1424,7 +1450,7 @@ class MultiComponent1NativeComponentProps final : public ViewProps { bool disabled{false}; }; -class MultiComponent2NativeComponentProps final : public ViewProps { +class JSI_EXPORT MultiComponent2NativeComponentProps final : public ViewProps { public: MultiComponent2NativeComponentProps() = default; MultiComponent2NativeComponentProps(const PropsParserContext& context, const MultiComponent2NativeComponentProps &sourceProps, const RawProps &rawProps); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index d70c0fe1a5ec1d..25deb9ca84275e 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -16,11 +16,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ArrayPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -51,11 +52,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ArrayPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -86,11 +88,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char BooleanPropNativeComponentComponentName[]; +JSI_EXPORT extern const char BooleanPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -121,11 +124,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ColorPropNativeComponentComponentName[]; +JSI_EXPORT extern const char ColorPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -156,11 +160,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char CommandNativeComponentComponentName[]; +JSI_EXPORT extern const char CommandNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -191,11 +196,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char CommandNativeComponentComponentName[]; +JSI_EXPORT extern const char CommandNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -226,11 +232,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char DoublePropNativeComponentComponentName[]; +JSI_EXPORT extern const char DoublePropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -262,11 +269,12 @@ Map { #include #include #include +#include namespace facebook { namespace react { -extern const char EventsNestedObjectNativeComponentComponentName[]; +JSI_EXPORT extern const char EventsNestedObjectNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -299,11 +307,12 @@ Map { #include #include #include +#include namespace facebook { namespace react { -extern const char EventsNativeComponentComponentName[]; +JSI_EXPORT extern const char EventsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -335,6 +344,7 @@ Map { #include #include +#include namespace facebook { namespace react { @@ -363,11 +373,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ExcludedAndroidComponentComponentName[]; +JSI_EXPORT extern const char ExcludedAndroidComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -398,11 +409,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ExcludedAndroidIosComponentComponentName[]; +JSI_EXPORT extern const char ExcludedAndroidIosComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -433,11 +445,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char FloatPropNativeComponentComponentName[]; +JSI_EXPORT extern const char FloatPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -468,11 +481,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ImagePropNativeComponentComponentName[]; +JSI_EXPORT extern const char ImagePropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -503,11 +517,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char InsetsPropNativeComponentComponentName[]; +JSI_EXPORT extern const char InsetsPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -538,11 +553,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char Int32EnumPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char Int32EnumPropsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -573,11 +589,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char IntegerPropNativeComponentComponentName[]; +JSI_EXPORT extern const char IntegerPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -608,6 +625,7 @@ Map { #include #include +#include namespace facebook { namespace react { @@ -636,11 +654,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ImageColorPropNativeComponentComponentName[]; +JSI_EXPORT extern const char ImageColorPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -671,11 +690,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char NoPropsNoEventsComponentComponentName[]; +JSI_EXPORT extern const char NoPropsNoEventsComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -706,11 +726,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char ObjectPropsComponentName[]; +JSI_EXPORT extern const char ObjectPropsComponentName[]; /* * \`ShadowNode\` for component. @@ -741,11 +762,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char PointPropNativeComponentComponentName[]; +JSI_EXPORT extern const char PointPropNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -776,11 +798,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char StringEnumPropsNativeComponentComponentName[]; +JSI_EXPORT extern const char StringEnumPropsNativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -811,11 +834,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char StringPropComponentComponentName[]; +JSI_EXPORT extern const char StringPropComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -846,11 +870,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char MultiFile1NativeComponentComponentName[]; +JSI_EXPORT extern const char MultiFile1NativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -859,7 +884,7 @@ using MultiFile1NativeComponentShadowNode = ConcreteViewShadowNode< MultiFile1NativeComponentComponentName, MultiFile1NativeComponentProps>; -extern const char MultiFile2NativeComponentComponentName[]; +JSI_EXPORT extern const char MultiFile2NativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -890,11 +915,12 @@ Map { #include #include +#include namespace facebook { namespace react { -extern const char MultiComponent1NativeComponentComponentName[]; +JSI_EXPORT extern const char MultiComponent1NativeComponentComponentName[]; /* * \`ShadowNode\` for component. @@ -903,7 +929,7 @@ using MultiComponent1NativeComponentShadowNode = ConcreteViewShadowNode< MultiComponent1NativeComponentComponentName, MultiComponent1NativeComponentProps>; -extern const char MultiComponent2NativeComponentComponentName[]; +JSI_EXPORT extern const char MultiComponent2NativeComponentComponentName[]; /* * \`ShadowNode\` for component. diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js index 30f3aa2e12493f..146e39b46774a9 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js @@ -54,6 +54,7 @@ namespace react { ${modules} +JSI_EXPORT std::shared_ptr ${libraryName}_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -131,6 +132,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi ${libraryName !== 'rncore' ? 'react_codegen_rncore' : ''} react_debug react_nativemodule_core diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap index 9f39609d66e8a8..0a84dc885c4fa7 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap @@ -30,6 +30,7 @@ public: }; +JSI_EXPORT std::shared_ptr SampleWithUppercaseName_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -85,6 +86,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -139,6 +141,7 @@ public: }; +JSI_EXPORT std::shared_ptr complex_objects_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -194,6 +197,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -241,6 +245,7 @@ namespace react { +JSI_EXPORT std::shared_ptr cxx_only_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -296,6 +301,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -350,6 +356,7 @@ public: }; +JSI_EXPORT std::shared_ptr empty_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -405,6 +412,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -459,6 +467,7 @@ public: }; +JSI_EXPORT std::shared_ptr native_modules_with_type_aliases_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -514,6 +523,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -576,6 +586,7 @@ public: }; +JSI_EXPORT std::shared_ptr real_module_example_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -631,6 +642,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -685,6 +697,7 @@ public: }; +JSI_EXPORT std::shared_ptr simple_native_modules_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -740,6 +753,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core @@ -802,6 +816,7 @@ public: }; +JSI_EXPORT std::shared_ptr two_modules_different_files_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); } // namespace react @@ -857,6 +872,7 @@ target_link_libraries( fbjni folly_runtime glog + jsi react_codegen_rncore react_debug react_nativemodule_core diff --git a/packages/rn-tester/android/app/build.gradle b/packages/rn-tester/android/app/build.gradle index 06c914e763f8c5..ef1c2b59b3631a 100644 --- a/packages/rn-tester/android/app/build.gradle +++ b/packages/rn-tester/android/app/build.gradle @@ -263,24 +263,20 @@ if (enableCodegen) { android { defaultConfig { externalNativeBuild { - ndkBuild { - arguments "APP_PLATFORM=android-21", - "APP_STL=c++_shared", - "NDK_TOOLCHAIN_VERSION=clang", - // The following paths assume building React Native from source. - "GENERATED_SRC_DIR=$buildDir/generated/source", - "PROJECT_BUILD_DIR=$buildDir", - "REACT_ANDROID_DIR=$reactAndroidProjectDir", - "REACT_ANDROID_BUILD_DIR=$reactAndroidBuildDir" - cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" - cppFlags "-std=c++17" + cmake { + arguments "-DGENERATED_SRC_DIR=$buildDir/generated/source", + "-DPROJECT_BUILD_DIR=$buildDir", + "-DREACT_ANDROID_DIR=$reactAndroidProjectDir", + "-DREACT_ANDROID_BUILD_DIR=$reactAndroidBuildDir", + "-DANDROID_STL=c++_shared" + targets "rntester_appmodules" } } } externalNativeBuild { - ndkBuild { - path "$projectDir/src/main/jni/Android.mk" + cmake { + path "src/main/jni/CMakeLists.txt" } } } @@ -302,19 +298,19 @@ if (enableCodegen) { afterEvaluate { reactNativeArchitectures().each { architecture -> - tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { + tasks.findByName("configureCMakeDebug[${architecture}]")?.configure { dependsOn("preHermesDebugBuild") dependsOn("preJscDebugBuild") } - tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { + tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure { dependsOn("preHermesReleaseBuild") dependsOn("preJscReleaseBuild") } } - configureNdkBuildRelease.dependsOn(packageReactReleaseNdkLibs) + configureCMakeRelWithDebInfo.dependsOn(packageReactReleaseNdkLibs) preHermesReleaseBuild.dependsOn(packageReactReleaseNdkLibs) preJscReleaseBuild.dependsOn(packageReactReleaseNdkLibs) - configureNdkBuildDebug.dependsOn(packageReactDebugNdkLibs) + configureCMakeDebug.dependsOn(packageReactDebugNdkLibs) preHermesDebugBuild.dependsOn(packageReactDebugNdkLibs) preJscDebugBuild.dependsOn(packageReactDebugNdkLibs) } diff --git a/packages/rn-tester/android/app/src/main/jni/Android.mk b/packages/rn-tester/android/app/src/main/jni/Android.mk deleted file mode 100644 index ec6991cfb589cd..00000000000000 --- a/packages/rn-tester/android/app/src/main/jni/Android.mk +++ /dev/null @@ -1,46 +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. - -THIS_DIR := $(call my-dir) - -include $(REACT_ANDROID_DIR)/Android-prebuilt.mk - -# SampleNativeModule -include $(REACT_COMMON_DIR)/react/nativemodule/samples/platform/android/Android.mk -include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk - -LOCAL_PATH := $(THIS_DIR) - -include $(CLEAR_VARS) -LOCAL_MODULE := rntester_appmodules -# Note: We are linking against react_codegen_AppSpecs hence no need to built the react-native-codegen output. -LOCAL_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni -LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) -LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) -LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(GENERATED_SRC_DIR)/codegen/jni -LOCAL_SHARED_LIBRARIES := \ - libfabricjni \ - libfbjni \ - libfolly_runtime \ - libglog \ - libreact_codegen_rncore \ - libreact_codegen_AppSpecs \ - libreact_debug \ - libreact_nativemodule_core \ - libreact_render_componentregistry \ - libreact_render_core \ - libreact_render_debug \ - libreact_render_graphics \ - librrc_view \ - libruntimeexecutor \ - libturbomodulejsijni \ - libyoga - -LOCAL_STATIC_LIBRARIES := libsampleturbomodule - -LOCAL_CFLAGS := \ - -DLOG_TAG=\"ReactNative\" -LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall -include $(BUILD_SHARED_LIBRARY) diff --git a/packages/rn-tester/android/app/src/main/jni/CMakeLists.txt b/packages/rn-tester/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 00000000000000..6a31f280cf5e85 --- /dev/null +++ b/packages/rn-tester/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,40 @@ +# 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. + +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE on) + +# Define the library name here. +project(rntester_appmodules) + +include(${REACT_ANDROID_DIR}/cmake-utils/Android-prebuilt.cmake) +add_subdirectory(${PROJECT_BUILD_DIR}/generated/source/codegen/jni/ codegen_build) +add_subdirectory(${REACT_COMMON_DIR}/react/nativemodule/samples/platform/android/ sampleturbomodule_build) + +file(GLOB input_SRC CONFIGURE_DEPENDS *.cpp) +add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC}) + +target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE -Wall -Werror -fexceptions -frtti -std=c++17 -DWITH_INSPECTOR=1 -DLOG_TAG=\"ReactNative\") + +target_link_libraries(${CMAKE_PROJECT_NAME} + fabricjni + fbjni + folly_runtime + glog + jsi + react_codegen_AppSpecs + react_codegen_rncore + react_debug + react_nativemodule_core + react_render_componentregistry + react_render_core + react_render_debug + react_render_graphics + rrc_view + runtimeexecutor + sampleturbomodule + turbomodulejsijni + yoga)