From 658d7dd52e3e5fcae86f48d72192c5c24e3d5d99 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 07:45:17 -0800 Subject: [PATCH 01/12] RNGP - Correctly Support Gradle Configuration Cache (#35455) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35455 This little change allows to support Gradle Configuration cache in user projects: https://docs.gradle.org/current/userguide/configuration_cache.html It allows to save several seconds on the build time. We'll keep it disabled for now, but Gradle plans to enable it by default for everyone in the future, so this changes makes us ready for it. Changelog: [Internal] [Changed] - RNGP - Correctly Support Gradle Configuration Cache Reviewed By: cipolleschi Differential Revision: D41519506 fbshipit-source-id: 6252546e811deb0777c0aab5332291368be7fa8f --- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 8538eaa9941d48..b6523cdf607c1b 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -96,7 +96,8 @@ class ReactPlugin : Plugin { // Please note that appNeedsCodegen is triggering a read of the package.json at // configuration time as we need to feed the onlyIf condition of this task. // Therefore, the appNeedsCodegen needs to be invoked inside this lambda. - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(extension) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We create the task to produce schema from JS files. @@ -120,7 +121,8 @@ class ReactPlugin : Plugin { } else { it.jsRootDir.set(extension.jsRootDir) } - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(parsedPackageJson) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We create the task to generate Java code from schema. @@ -139,7 +141,8 @@ class ReactPlugin : Plugin { // Please note that appNeedsCodegen is triggering a read of the package.json at // configuration time as we need to feed the onlyIf condition of this task. // Therefore, the appNeedsCodegen needs to be invoked inside this lambda. - it.onlyIf { isLibrary || project.needsCodegenFromPackageJson(extension) } + val needsCodegenFromPackageJson = project.needsCodegenFromPackageJson(extension) + it.onlyIf { isLibrary || needsCodegenFromPackageJson } } // We update the android configuration to include the generated sources. From b1bf8c51d0befc9538ccf6c24e208894a0443eed Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 08:45:15 -0800 Subject: [PATCH 02/12] Consolidate hermes-executor-debug and -release inside a single target (#35454) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35454 Historically, we used to have hermes-executor debug and release as separate dynamic libraries. This makes it impossible to prefab this library, so I have to reconcile it into a single library. This will also help keep the setup consistent with the internal (BUCK) where we have a single target. Changelog: [Internal] [Changed] - Consolidate hermes-executor-debug and -release inside a single target Reviewed By: cipolleschi Differential Revision: D41519119 fbshipit-source-id: d9ddc30b72164daa29c735836ea433fd4d917fc8 --- ReactAndroid/build.gradle | 19 +----- .../com/facebook/hermes/reactexecutor/BUCK | 1 + .../hermes/reactexecutor/HermesExecutor.java | 9 +-- .../react/hermes/reactexecutor/CMakeLists.txt | 17 ++---- .../com/facebook/react/TaskConfiguration.kt | 3 +- .../react/utils/NdkConfiguratorUtils.kt | 19 ++---- .../react/utils/NdkConfiguratorUtilsTest.kt | 58 +++---------------- 7 files changed, 24 insertions(+), 102 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index d43535934995e3..f14aa4d2352e99 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -404,6 +404,7 @@ android { targets "reactnativejni", "jscexecutor", + "hermes-executor", "jsijniprofiler", "reactnativeblob", "reactperfloggerjni", @@ -434,24 +435,6 @@ android { } } - buildTypes { - debug { - externalNativeBuild { - cmake { - targets "hermes-executor-debug" - } - } - } - - release { - externalNativeBuild { - cmake { - targets "hermes-executor-release" - } - } - } - } - externalNativeBuild { cmake { path "src/main/jni/CMakeLists.txt" diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK index 0c00d480eddb44..2c954374c38dcf 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/BUCK @@ -17,6 +17,7 @@ rn_android_library( react_native_target("java/com/facebook/hermes/instrumentation:instrumentation"), react_native_target("java/com/facebook/hermes/instrumentation:hermes_samplingprofiler"), react_native_target("java/com/facebook/react/bridge:bridge"), + react_native_target("java/com/facebook/react/common:common"), react_native_target("jni/react/hermes/reactexecutor:jni"), ":runtimeconfig", ], diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java index 48eaaa4c0668ba..e72bca607c1c96 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java @@ -9,6 +9,7 @@ import com.facebook.jni.HybridData; import com.facebook.react.bridge.JavaScriptExecutor; +import com.facebook.react.common.build.ReactBuildConfig; import com.facebook.soloader.SoLoader; import javax.annotation.Nullable; @@ -23,11 +24,11 @@ public static void loadLibrary() throws UnsatisfiedLinkError { if (mode_ == null) { // libhermes must be loaded explicitly to invoke its JNI_OnLoad. SoLoader.loadLibrary("hermes"); - try { - SoLoader.loadLibrary("hermes-executor-debug"); + SoLoader.loadLibrary("hermes-executor"); + // libhermes-executor is built differently for Debug & Release so we load the proper mode. + if (ReactBuildConfig.DEBUG == true) { mode_ = "Debug"; - } catch (UnsatisfiedLinkError e) { - SoLoader.loadLibrary("hermes-executor-release"); + } else { mode_ = "Release"; } } diff --git a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt index d446141c7ed92d..15b4a6aed6f25d 100644 --- a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt @@ -8,28 +8,19 @@ set(CMAKE_VERBOSE_MAKEFILE on) file(GLOB_RECURSE hermes_executor_SRC CONFIGURE_DEPENDS *.cpp) -if(${CMAKE_BUILD_TYPE} MATCHES Debug) - set(HERMES_TARGET_SUFFIX debug) -else() - set(HERMES_TARGET_SUFFIX release) -endif() - -set(HERMES_TARGET_NAME hermes-executor-${HERMES_TARGET_SUFFIX}) - -add_library( - ${HERMES_TARGET_NAME} +add_library(hermes-executor SHARED ${hermes_executor_SRC} ) target_compile_options( - ${HERMES_TARGET_NAME} + hermes-executor PRIVATE $<$:-DHERMES_ENABLE_DEBUGGER=1> -fexceptions ) -target_include_directories(${HERMES_TARGET_NAME} PRIVATE .) +target_include_directories(hermes-executor PRIVATE .) target_link_libraries( - ${HERMES_TARGET_NAME} + hermes-executor hermes-executor-common jsireact fb diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt index bb3699d58df095..a2b60f425794d8 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/TaskConfiguration.kt @@ -46,8 +46,7 @@ internal fun Project.configureReactTasks(variant: Variant, config: ReactExtensio config.debuggableVariants.get().any { it.equals(variant.name, ignoreCase = true) } configureNewArchPackagingOptions(project, variant) - configureJsEnginePackagingOptions( - config, variant, isHermesEnabledInThisVariant, isDebuggableVariant) + configureJsEnginePackagingOptions(config, variant, isHermesEnabledInThisVariant) if (!isDebuggableVariant) { val bundleTask = diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt index 479c3f742eda99..13bbb3ab8c51dd 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt @@ -112,36 +112,25 @@ internal object NdkConfiguratorUtils { config: ReactExtension, variant: Variant, hermesEnabled: Boolean, - debuggableVariant: Boolean ) { if (config.enableSoCleanup.get()) { - val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled, debuggableVariant) + val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled) variant.packaging.jniLibs.excludes.addAll(excludes) variant.packaging.jniLibs.pickFirsts.addAll(includes) } } - fun getPackagingOptionsForVariant( - hermesEnabled: Boolean, - debuggableVariant: Boolean - ): Pair, List> { + fun getPackagingOptionsForVariant(hermesEnabled: Boolean): Pair, List> { val excludes = mutableListOf() val includes = mutableListOf() if (hermesEnabled) { excludes.add("**/libjsc.so") excludes.add("**/libjscexecutor.so") includes.add("**/libhermes.so") - if (debuggableVariant) { - excludes.add("**/libhermes-executor-release.so") - includes.add("**/libhermes-executor-debug.so") - } else { - excludes.add("**/libhermes-executor-debug.so") - includes.add("**/libhermes-executor-release.so") - } + includes.add("**/libhermes-executor.so") } else { excludes.add("**/libhermes.so") - excludes.add("**/libhermes-executor-debug.so") - excludes.add("**/libhermes-executor-release.so") + excludes.add("**/libhermes-executor.so") includes.add("**/libjsc.so") includes.add("**/libjscexecutor.so") } diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt index 2d0093c6a565d2..41d498b23dccec 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt @@ -15,70 +15,28 @@ import org.junit.Test class NdkConfiguratorUtilsTest { @Test - fun getPackagingOptionsForVariant_withHermesEnabled_andDebuggableVariant() { - val (excludes, includes) = - getPackagingOptionsForVariant(hermesEnabled = true, debuggableVariant = true) + fun getPackagingOptionsForVariant_withHermesEnabled() { + val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = true) assertTrue("**/libjsc.so" in excludes) assertTrue("**/libjscexecutor.so" in excludes) - assertTrue("**/libhermes-executor-release.so" in excludes) assertFalse("**/libjsc.so" in includes) assertFalse("**/libjscexecutor.so" in includes) - assertFalse("**/libhermes-executor-release.so" in includes) assertTrue("**/libhermes.so" in includes) - assertTrue("**/libhermes-executor-debug.so" in includes) + assertTrue("**/libhermes-executor.so" in includes) assertFalse("**/libhermes.so" in excludes) - assertFalse("**/libhermes-executor-debug.so" in excludes) + assertFalse("**/libhermes-executor.so" in excludes) } @Test - fun getPackagingOptionsForVariant_withHermesEnabled_andNonDebuggableVariant() { - val (excludes, includes) = - getPackagingOptionsForVariant(hermesEnabled = true, debuggableVariant = false) - - assertTrue("**/libjsc.so" in excludes) - assertTrue("**/libjscexecutor.so" in excludes) - assertTrue("**/libhermes-executor-debug.so" in excludes) - assertFalse("**/libjsc.so" in includes) - assertFalse("**/libjscexecutor.so" in includes) - assertFalse("**/libhermes-executor-debug.so" in includes) - - assertTrue("**/libhermes.so" in includes) - assertTrue("**/libhermes-executor-release.so" in includes) - assertFalse("**/libhermes.so" in excludes) - assertFalse("**/libhermes-executor-release.so" in excludes) - } - - @Test - fun getPackagingOptionsForVariant_withHermesDisabled_andDebuggableVariant() { - val (excludes, includes) = - getPackagingOptionsForVariant(hermesEnabled = false, debuggableVariant = true) - - assertTrue("**/libhermes.so" in excludes) - assertTrue("**/libhermes-executor-debug.so" in excludes) - assertTrue("**/libhermes-executor-release.so" in excludes) - assertFalse("**/libhermes.so" in includes) - assertFalse("**/libhermes-executor-debug.so" in includes) - assertFalse("**/libhermes-executor-release.so" in includes) - - assertTrue("**/libjsc.so" in includes) - assertTrue("**/libjscexecutor.so" in includes) - assertFalse("**/libjsc.so" in excludes) - assertFalse("**/libjscexecutor.so" in excludes) - } - - @Test - fun getPackagingOptionsForVariant_withHermesDisabled_andNonDebuggableVariant() { - val (excludes, includes) = - getPackagingOptionsForVariant(hermesEnabled = false, debuggableVariant = false) + fun getPackagingOptionsForVariant_withHermesDisabled() { + val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = false) assertTrue("**/libhermes.so" in excludes) - assertTrue("**/libhermes-executor-debug.so" in excludes) - assertTrue("**/libhermes-executor-release.so" in excludes) + assertTrue("**/libhermes-executor.so" in excludes) assertFalse("**/libhermes.so" in includes) - assertFalse("**/libhermes-executor-debug.so" in includes) - assertFalse("**/libhermes-executor-release.so" in includes) + assertFalse("**/libhermes-executor.so" in includes) assertTrue("**/libjsc.so" in includes) assertTrue("**/libjscexecutor.so" in includes) From b89efc8473a37d053e5931c9dbd9dac0e104afe7 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 08:45:15 -0800 Subject: [PATCH 03/12] Expose `hermes-executor` to be consumed via prefab (#35457) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35457 This exposes `hermes-executor` to be consumed via prefab so that libraries can depend on it and use its symbols if needed (Expo and Reanimated need it). Changelog: [Internal] [Changed] - Expose `hermes-executor` to be consumed via prefab Reviewed By: cipolleschi Differential Revision: D41520019 fbshipit-source-id: d590a043ea89fdd8ff41b0ed20900c9cf381a1e4 --- ReactAndroid/build.gradle | 14 ++++++++++++-- ReactCommon/hermes/executor/CMakeLists.txt | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index f14aa4d2352e99..1bf06ae88265f6 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -174,6 +174,13 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa "rrc_image", new Pair("../ReactCommon/react/renderer/components/image/", "react/renderer/components/image/") ), + // This prefab target is used by Expo & Reanimated to load a new instance of Hermes + new PrefabPreprocessingEntry( + "hermes-executor", + // "hermes-executor" is statically linking agaisnt "hermes-executor-common" + // and "hermes-inspector". Here we expose only the headers that we know are needed. + new Pair("../ReactCommon/hermes/inspector/", "hermes/inspector/") + ), ] ) it.outputDir.set(prefabHeadersDir) @@ -404,7 +411,6 @@ android { targets "reactnativejni", "jscexecutor", - "hermes-executor", "jsijniprofiler", "reactnativeblob", "reactperfloggerjni", @@ -427,7 +433,8 @@ android { "yoga", "folly_runtime", "react_nativemodule_core", - "react_render_imagemanager" + "react_render_imagemanager", + "hermes-executor" } } ndk { @@ -532,6 +539,9 @@ android { react_render_imagemanager { headers(new File(prefabHeadersDir, "react_render_imagemanager").absolutePath) } + "hermes-executor" { + headers(new File(prefabHeadersDir, "hermes-executor").absolutePath) + } } publishing { diff --git a/ReactCommon/hermes/executor/CMakeLists.txt b/ReactCommon/hermes/executor/CMakeLists.txt index a6d8bbac1ddf01..f05d3bfc0e36a7 100644 --- a/ReactCommon/hermes/executor/CMakeLists.txt +++ b/ReactCommon/hermes/executor/CMakeLists.txt @@ -17,7 +17,8 @@ target_link_libraries(hermes-executor-common jsireact hermes-engine::libhermes jsi - debug hermes-inspector + debug + hermes-inspector ) if(${CMAKE_BUILD_TYPE} MATCHES Debug) From f27947431ba723bf6e5340cd62d2200eeb36b19d Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 08:45:15 -0800 Subject: [PATCH 04/12] Add prefab for _uimanager _scheduler and _mounting (#35458) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35458 We're adding prefab support for those modules as they're needed by Reanimated and we're exposing headers for them as well. Changelog: [Internal] [Changed] - Add prefab for _uimanager _scheduler and _mounting Reviewed By: cipolleschi Differential Revision: D41520606 fbshipit-source-id: 76f3c81705e99057b92cd9b86d0601a2b1410f95 --- ReactAndroid/build.gradle | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 1bf06ae88265f6..74051746fc7208 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -181,6 +181,18 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa // and "hermes-inspector". Here we expose only the headers that we know are needed. new Pair("../ReactCommon/hermes/inspector/", "hermes/inspector/") ), + new PrefabPreprocessingEntry( + "react_render_uimanager", + new Pair("../ReactCommon/react/renderer/uimanager/", "react/renderer/uimanager/"), + ), + new PrefabPreprocessingEntry( + "react_render_scheduler", + new Pair("../ReactCommon/react/renderer/scheduler/", "react/renderer/scheduler/"), + ), + new PrefabPreprocessingEntry( + "react_render_mounting", + new Pair("../ReactCommon/react/renderer/mounting/", "react/renderer/mounting/"), + ), ] ) it.outputDir.set(prefabHeadersDir) @@ -434,6 +446,9 @@ android { "folly_runtime", "react_nativemodule_core", "react_render_imagemanager", + "react_render_uimanager", + "react_render_scheduler", + "react_render_mounting", "hermes-executor" } } @@ -539,6 +554,15 @@ android { react_render_imagemanager { headers(new File(prefabHeadersDir, "react_render_imagemanager").absolutePath) } + react_render_uimanager { + headers(new File(prefabHeadersDir, "react_render_uimanager").absolutePath) + } + react_render_scheduler { + headers(new File(prefabHeadersDir, "react_render_scheduler").absolutePath) + } + react_render_mounting { + headers(new File(prefabHeadersDir, "react_render_mounting").absolutePath) + } "hermes-executor" { headers(new File(prefabHeadersDir, "hermes-executor").absolutePath) } From 9628e5612585888c11c14634dafe9b9857e2c0cb Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 08:45:15 -0800 Subject: [PATCH 05/12] Add missing headers to `react_nativemodule_core` prefab module (#35460) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35460 Reanimated reported that `react_nativemodule_core` was missing some headers. Specifically the one from ReactAndroid::react_debug, ReactAndroid::react_render_core, ReactAndroid::glog, and ReactAndroid::react_render_debug. I'm adding them here so they get included in the shipped headers for `react_nativemodule_core` Changelog: [Internal] [Changed] - Add missing headers to `react_nativemodule_core` prefab module Reviewed By: cipolleschi Differential Revision: D41520751 fbshipit-source-id: 4627a2d0f880d4bb3ff2f0e43cd735cf9a3f2f9a --- ReactAndroid/build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 74051746fc7208..e4f28debed1481 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -144,6 +144,7 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa new Pair(new File(buildDir, "third-party-ndk/boost/boost_1_76_0/").absolutePath, ""), new Pair(new File(buildDir, "third-party-ndk/double-conversion/").absolutePath, ""), new Pair(new File(buildDir, "third-party-ndk/folly/").absolutePath, ""), + new Pair(new File(buildDir, "third-party-ndk/glog/exported/").absolutePath, ""), new Pair("../ReactCommon/butter/", "butter/"), new Pair("../ReactCommon/callinvoker/", ""), new Pair("../ReactCommon/react/bridging/", "react/bridging/"), @@ -152,6 +153,8 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa new Pair("../ReactCommon/react/nativemodule/core/platform/android/", ""), new Pair("../ReactCommon/react/renderer/componentregistry/", "react/renderer/componentregistry/"), new Pair("../ReactCommon/react/renderer/components/root/", "react/renderer/components/root/"), + new Pair("../ReactCommon/react/renderer/core/", "react/renderer/core/"), + new Pair("../ReactCommon/react/renderer/debug/", "react/renderer/debug/"), new Pair("../ReactCommon/react/renderer/leakchecker/", "react/renderer/leakchecker/"), new Pair("../ReactCommon/react/renderer/mapbuffer/", "react/renderer/mapbuffer/"), new Pair("../ReactCommon/react/renderer/mounting/", "react/renderer/mounting/"), @@ -159,6 +162,7 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa new Pair("../ReactCommon/react/renderer/scheduler/", "react/renderer/scheduler/"), new Pair("../ReactCommon/react/renderer/telemetry/", "react/renderer/telemetry/"), new Pair("../ReactCommon/react/renderer/uimanager/", "react/renderer/uimanager/"), + new Pair("../ReactCommon/react/debug/", "react/debug/"), new Pair("../ReactCommon/react/utils/", "react/utils/"), new Pair("src/main/jni/react/jni", "react/jni/"), ] From 804d2b5bf1dedef721a0eea55b327b8eac3a4a71 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 08:45:15 -0800 Subject: [PATCH 06/12] Allow `reactnativejni` to be consumed via prefab (#35461) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35461 This is another library which is adding prefab support as it's needed by Expo libraries and Reanimated. Changelog: [Internal] [Changed] - Allow `reactnativejni` to be consumed via prefab Reviewed By: cipolleschi Differential Revision: D41520801 fbshipit-source-id: 91142a5b5051cfba478d93a2475a178eed6fbb29 --- ReactAndroid/build.gradle | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index e4f28debed1481..041f546c668f6e 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -197,6 +197,10 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa "react_render_mounting", new Pair("../ReactCommon/react/renderer/mounting/", "react/renderer/mounting/"), ), + new PrefabPreprocessingEntry( + "reactnativejni", + new Pair("src/main/jni/react/jni", "react/jni/"), + ), ] ) it.outputDir.set(prefabHeadersDir) @@ -425,12 +429,12 @@ android { "-DANDROID_TOOLCHAIN=clang", "-DANDROID_PLATFORM=android-21" - targets "reactnativejni", - "jscexecutor", + targets "jscexecutor", "jsijniprofiler", "reactnativeblob", "reactperfloggerjni", // prefab targets + "reactnativejni", "react_render_debug", "turbomodulejsijni", "runtimeexecutor", @@ -567,6 +571,9 @@ android { react_render_mounting { headers(new File(prefabHeadersDir, "react_render_mounting").absolutePath) } + reactnativejni { + headers(new File(prefabHeadersDir, "reactnativejni").absolutePath) + } "hermes-executor" { headers(new File(prefabHeadersDir, "hermes-executor").absolutePath) } From 5cffb4fa009e70edaa274e7d3ebb3eb4bc1a3d13 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Thu, 24 Nov 2022 09:18:36 -0800 Subject: [PATCH 07/12] Bump AGP to 7.4.x (#35456) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35456 Fixes #35439 There is a bug in AGP 7.3.x which is causing assets to don't be copied properly inside the final artifact: issuetracker.google.com/issues/237421684 As AGP 7.4.x is really close to release (is in Beta5, should be released stable in the next weeks) we should be fine by bumping to beta5. This also requires a bump of RNGP Changelog: [Android] [Changed] - Bump AGP to 7.4.x allow-large-files Reviewed By: cipolleschi Differential Revision: D41519549 fbshipit-source-id: 60d568a3e49798a23f1d7bf4839ab58bd5549aba --- packages/react-native-gradle-plugin/build.gradle.kts | 6 +++--- .../src/main/kotlin/com/facebook/react/ReactPlugin.kt | 6 ++++-- template/android/build.gradle | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/react-native-gradle-plugin/build.gradle.kts b/packages/react-native-gradle-plugin/build.gradle.kts index dd9a08ae099193..b1b2dd61012c83 100644 --- a/packages/react-native-gradle-plugin/build.gradle.kts +++ b/packages/react-native-gradle-plugin/build.gradle.kts @@ -33,7 +33,7 @@ group = "com.facebook.react" dependencies { implementation(gradleApi()) - implementation("com.android.tools.build:gradle:7.3.1") + implementation("com.android.tools.build:gradle:7.4.0-beta05") implementation("com.google.code.gson:gson:2.8.9") implementation("com.google.guava:guava:31.0.1-jre") implementation("com.squareup:javapoet:1.13.0") @@ -50,8 +50,8 @@ dependencies { } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 } tasks.withType { diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index b6523cdf607c1b..152a7667e4ca03 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -47,8 +47,10 @@ class ReactPlugin : Plugin { configureBuildConfigFields(project) configureDevPorts(project) - project.extensions.getByType(AndroidComponentsExtension::class.java).onVariants { variant -> - project.configureReactTasks(variant = variant, config = extension) + project.extensions.getByType(AndroidComponentsExtension::class.java).apply { + onVariants(selector().all()) { variant -> + project.configureReactTasks(variant = variant, config = extension) + } } configureCodegen(project, extension, isLibrary = false) } diff --git a/template/android/build.gradle b/template/android/build.gradle index 4631930d4a5c42..baa44e144bbac1 100644 --- a/template/android/build.gradle +++ b/template/android/build.gradle @@ -15,7 +15,7 @@ buildscript { mavenCentral() } dependencies { - classpath("com.android.tools.build:gradle:7.3.1") + classpath("com.android.tools.build:gradle:7.4.0-beta05") classpath("com.facebook.react:react-native-gradle-plugin") } } From f283877c21da253e3a2a0a828747489733843f88 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Mon, 28 Nov 2022 04:13:55 -0800 Subject: [PATCH 08/12] Move JSCRuntime into its own folder (#35482) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35482 This change moves the JSCRuntime.h/cpp into a `jsc` folder. This change is required for several reasons: 1. on iOS, the new `jsi`, `jsidynamic` and `jsc` setup is breaking the `use_frameworks!` with `:linkage => :static` option with the old architecture. So it is a regression. 2. JSCRuntime is required by some libraries and needs to be exposed as a prefab and the current setup makes it hard to achieve. allow-large-files [General][Changed] - Move JSCRuntime into a separate pod/prefab Reviewed By: cortinico Differential Revision: D41533778 fbshipit-source-id: 642240c93a6c124280430d4f196049cb67cb130b --- BUCK | 2 +- React/CxxBridge/JSCExecutorFactory.mm | 2 +- .../src/main/jni/react/jscexecutor/BUCK | 2 +- .../src/main/jni/react/jscexecutor/OnLoad.cpp | 2 +- ReactCommon/jsc/.clang-tidy | 6 ++++ ReactCommon/jsc/BUCK | 34 +++++++++++++++++++ ReactCommon/jsc/CMakeLists.txt | 30 ++++++++++++++++ ReactCommon/{jsi => jsc}/JSCRuntime.cpp | 0 ReactCommon/{jsi => jsc}/JSCRuntime.h | 0 ReactCommon/{jsi => jsc}/React-jsc.podspec | 6 +--- ReactCommon/jsi/BUCK | 32 +---------------- .../RNTesterPods.xcodeproj/project.pbxproj | 19 +++++++++++ scripts/cocoapods/__tests__/jsengine-test.rb | 6 ++-- scripts/cocoapods/jsengine.rb | 4 +-- 14 files changed, 100 insertions(+), 45 deletions(-) create mode 100644 ReactCommon/jsc/.clang-tidy create mode 100644 ReactCommon/jsc/BUCK create mode 100644 ReactCommon/jsc/CMakeLists.txt rename ReactCommon/{jsi => jsc}/JSCRuntime.cpp (100%) rename ReactCommon/{jsi => jsc}/JSCRuntime.h (100%) rename ReactCommon/{jsi => jsc}/React-jsc.podspec (94%) diff --git a/BUCK b/BUCK index 084c651442d027..4325eaa291eae9 100644 --- a/BUCK +++ b/BUCK @@ -115,7 +115,7 @@ rn_xplat_cxx_library2( react_native_root_target("React/CoreModules:CoreModules"), react_native_xplat_target("cxxreact:bridge"), react_native_xplat_target("cxxreact:jsbigstring"), - react_native_xplat_target("jsi:JSCRuntime"), + react_native_xplat_target("jsc:JSCRuntime"), react_native_xplat_target("jsiexecutor:jsiexecutor"), react_native_xplat_target("reactperflogger:reactperflogger"), ], diff --git a/React/CxxBridge/JSCExecutorFactory.mm b/React/CxxBridge/JSCExecutorFactory.mm index 4d8a1ba1b2940e..78584cd4e6c121 100644 --- a/React/CxxBridge/JSCExecutorFactory.mm +++ b/React/CxxBridge/JSCExecutorFactory.mm @@ -7,7 +7,7 @@ #include "JSCExecutorFactory.h" -#import +#import #import diff --git a/ReactAndroid/src/main/jni/react/jscexecutor/BUCK b/ReactAndroid/src/main/jni/react/jscexecutor/BUCK index 7719f27dbc9601..8b3e82eb665f94 100644 --- a/ReactAndroid/src/main/jni/react/jscexecutor/BUCK +++ b/ReactAndroid/src/main/jni/react/jscexecutor/BUCK @@ -16,7 +16,7 @@ rn_xplat_cxx_library( deps = [ FBJNI_TARGET, react_native_target("jni/react/jni:jni"), - react_native_xplat_target("jsi:JSCRuntime"), + react_native_xplat_target("jsc:JSCRuntime"), react_native_xplat_target("jsiexecutor:jsiexecutor"), ], ) diff --git a/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp b/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp index 60450b5c404b33..9d38412d1cb9cd 100644 --- a/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp +++ b/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include #include diff --git a/ReactCommon/jsc/.clang-tidy b/ReactCommon/jsc/.clang-tidy new file mode 100644 index 00000000000000..9f33ef5a06d828 --- /dev/null +++ b/ReactCommon/jsc/.clang-tidy @@ -0,0 +1,6 @@ +--- +Checks: '> +clang-diagnostic-*, +' +InheritParentConfig: true +... diff --git a/ReactCommon/jsc/BUCK b/ReactCommon/jsc/BUCK new file mode 100644 index 00000000000000..3981ca830a7bbc --- /dev/null +++ b/ReactCommon/jsc/BUCK @@ -0,0 +1,34 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "APPLE", "IOS", "MACOSX", "get_apple_compiler_flags", "get_apple_inspector_flags", "get_preprocessor_flags_for_build_mode", "react_native_xplat_dep", "rn_xplat_cxx_library") + +APPLE_COMPILER_FLAGS = get_apple_compiler_flags() + +rn_xplat_cxx_library( + name = "JSCRuntime", + srcs = [ + "JSCRuntime.cpp", + ], + header_namespace = "jsc", + exported_headers = [ + "JSCRuntime.h", + ], + apple_sdks = (IOS, MACOSX), + compiler_flags_pedantic = True, + fbobjc_compiler_flags = APPLE_COMPILER_FLAGS + [ + "-Os", + ], + fbobjc_frameworks = [ + "$SDKROOT/System/Library/Frameworks/JavaScriptCore.framework", + ], + fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), + labels = [ + "pfh:ReactNative_CommonInfrastructurePlaceholder", + ], + platforms = APPLE, + visibility = ["PUBLIC"], + xplat_mangled_args = { + "soname": "libjscjsi.$(ext)", + }, + exported_deps = [ + react_native_xplat_dep("jsi:jsi"), + ], +) diff --git a/ReactCommon/jsc/CMakeLists.txt b/ReactCommon/jsc/CMakeLists.txt new file mode 100644 index 00000000000000..52188407ea55e4 --- /dev/null +++ b/ReactCommon/jsc/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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. + +################## +### jscruntime ### +################## + +cmake_minimum_required(VERSION 3.13) +set(CMAKE_VERBOSE_MAKEFILE on) + +add_compile_options( + -fexceptions + -frtti + -O3 + -Wno-unused-lambda-capture + -DLOG_TAG=\"ReactNative\") + +add_library(jscruntime STATIC + JSCRuntime.h + JSCRuntime.cpp) + +target_include_directories(jscruntime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(jscruntime folly_runtime jsc glog) + +# TODO: Remove this flag when ready. +# Android has this enabled by default, but the flag is still needed for iOS. +target_compile_options(jscruntime PRIVATE -DRN_FABRIC_ENABLED) diff --git a/ReactCommon/jsi/JSCRuntime.cpp b/ReactCommon/jsc/JSCRuntime.cpp similarity index 100% rename from ReactCommon/jsi/JSCRuntime.cpp rename to ReactCommon/jsc/JSCRuntime.cpp diff --git a/ReactCommon/jsi/JSCRuntime.h b/ReactCommon/jsc/JSCRuntime.h similarity index 100% rename from ReactCommon/jsi/JSCRuntime.h rename to ReactCommon/jsc/JSCRuntime.h diff --git a/ReactCommon/jsi/React-jsc.podspec b/ReactCommon/jsc/React-jsc.podspec similarity index 94% rename from ReactCommon/jsi/React-jsc.podspec rename to ReactCommon/jsc/React-jsc.podspec index ce59f0e69e6ac9..6bb2347e57edcc 100644 --- a/ReactCommon/jsi/React-jsc.podspec +++ b/ReactCommon/jsc/React-jsc.podspec @@ -28,12 +28,8 @@ Pod::Spec.new do |s| s.source_files = "JSCRuntime.{cpp,h}" s.exclude_files = "**/test/*" s.framework = "JavaScriptCore" - s.dependency "React-jsi", version - s.default_subspec = "Default" - s.subspec "Default" do - # no-op - end + s.dependency "React-jsi", version s.subspec "Fabric" do |ss| ss.pod_target_xcconfig = { "OTHER_CFLAGS" => "$(inherited) -DRN_FABRIC_ENABLED" } diff --git a/ReactCommon/jsi/BUCK b/ReactCommon/jsi/BUCK index 2d5e68fe3de0b6..72d8a39190def5 100644 --- a/ReactCommon/jsi/BUCK +++ b/ReactCommon/jsi/BUCK @@ -1,4 +1,4 @@ -load("//tools/build_defs/oss:rn_defs.bzl", "APPLE", "IOS", "MACOSX", "react_native_xplat_dep", "rn_xplat_cxx_library") +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_xplat_dep", "rn_xplat_cxx_library") rn_xplat_cxx_library( name = "jsi", @@ -56,33 +56,3 @@ rn_xplat_cxx_library( react_native_xplat_dep("jsi:jsi"), ], ) - -rn_xplat_cxx_library( - name = "JSCRuntime", - srcs = [ - "JSCRuntime.cpp", - ], - header_namespace = "jsi", - exported_headers = [ - "JSCRuntime.h", - ], - apple_sdks = (IOS, MACOSX), - compiler_flags_pedantic = True, - fbobjc_compiler_flags = [ - "-Os", - ], - fbobjc_frameworks = [ - "$SDKROOT/System/Library/Frameworks/JavaScriptCore.framework", - ], - labels = [ - "pfh:ReactNative_CommonInfrastructurePlaceholder", - ], - platforms = APPLE, - visibility = ["PUBLIC"], - xplat_mangled_args = { - "soname": "libjscjsi.$(ext)", - }, - exported_deps = [ - react_native_xplat_dep("jsi:jsi"), - ], -) diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 73488e795ff4e0..6ed49246169050 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -412,6 +412,7 @@ 5CF0FD27207FC6EC00C13D65 /* Start Metro */, 2FCDFB64B37634EC8EC3139B /* [CP] Embed Pods Frameworks */, A8DE6393E2BB72D8FBBF6C27 /* [CP] Copy Pods Resources */, + 992FB5A50F2847F7EB2C285C /* [RN] Copy Hermes Framework */, ); buildRules = ( ); @@ -696,6 +697,24 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTesterIntegrationTests/Pods-RNTesterIntegrationTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; + 992FB5A50F2847F7EB2C285C /* [RN] Copy Hermes Framework */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "[RN] Copy Hermes Framework"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = ". ../../sdks/hermes-engine/utils/copy-hermes-xcode.sh"; + }; 9A596313B3964A4DEB794409 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/scripts/cocoapods/__tests__/jsengine-test.rb b/scripts/cocoapods/__tests__/jsengine-test.rb index 14c76d0c6d810c..ef18a72c6be0fb 100644 --- a/scripts/cocoapods/__tests__/jsengine-test.rb +++ b/scripts/cocoapods/__tests__/jsengine-test.rb @@ -44,7 +44,7 @@ def test_setupJsc_installsPods # Assert assert_equal($podInvocationCount, 2) assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") - assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") + assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsc") end def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled @@ -57,8 +57,8 @@ def test_setupJsc_installsPods_installsFabricSubspecWhenFabricEnabled # Assert assert_equal($podInvocationCount, 3) assert_equal($podInvocation["React-jsi"][:path], "../../ReactCommon/jsi") - assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsi") - assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsi") + assert_equal($podInvocation["React-jsc"][:path], "../../ReactCommon/jsc") + assert_equal($podInvocation["React-jsc/Fabric"][:path], "../../ReactCommon/jsc") end # ================== # diff --git a/scripts/cocoapods/jsengine.rb b/scripts/cocoapods/jsengine.rb index 48a20e6a156307..7f941c127ccbfa 100644 --- a/scripts/cocoapods/jsengine.rb +++ b/scripts/cocoapods/jsengine.rb @@ -11,9 +11,9 @@ # @parameter fabric_enabled: whether Fabirc is enabled def setup_jsc!(react_native_path: "../node_modules/react-native", fabric_enabled: false) pod 'React-jsi', :path => "#{react_native_path}/ReactCommon/jsi" - pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsi" + pod 'React-jsc', :path => "#{react_native_path}/ReactCommon/jsc" if fabric_enabled - pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsi" + pod 'React-jsc/Fabric', :path => "#{react_native_path}/ReactCommon/jsc" end end From a7a43f8445e720779a4cbf2959ae4f9b01fae4d1 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 28 Nov 2022 04:13:55 -0800 Subject: [PATCH 09/12] Expose `jscruntime` to be consumed via Prefab Summary: This is the last library that we should expose via Prefab. Thanks to cipolleschi 's work here moving the file to `/ReactCommon/jsc` folder we can easily expose it to be consumed by third parties. Changelog: [Internal] [Changed] - Expose `jscruntime` to be consumed via Prefab Reviewed By: cipolleschi Differential Revision: D41534564 fbshipit-source-id: fb4b2d801def8caf71638dcb74eb87f8230984d4 --- ReactAndroid/build.gradle | 10 ++++++++-- ReactAndroid/src/main/jni/CMakeLists.txt | 1 + ReactCommon/jsc/CMakeLists.txt | 9 +++++++-- ReactCommon/jsi/CMakeLists.txt | 16 ---------------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 041f546c668f6e..3f285029101ac3 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -178,13 +178,19 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa "rrc_image", new Pair("../ReactCommon/react/renderer/components/image/", "react/renderer/components/image/") ), - // This prefab target is used by Expo & Reanimated to load a new instance of Hermes + // These prefab targets are used by Expo & Reanimated new PrefabPreprocessingEntry( "hermes-executor", - // "hermes-executor" is statically linking agaisnt "hermes-executor-common" + // "hermes-executor" is statically linking against "hermes-executor-common" // and "hermes-inspector". Here we expose only the headers that we know are needed. new Pair("../ReactCommon/hermes/inspector/", "hermes/inspector/") ), + new PrefabPreprocessingEntry( + "jscexecutor", + // "jscexecutor" is statically linking against "jscruntime" + // Here we expose only the headers that we know are needed. + new Pair("../ReactCommon/jsc/", "jsc/") + ), new PrefabPreprocessingEntry( "react_render_uimanager", new Pair("../ReactCommon/react/renderer/uimanager/", "react/renderer/uimanager/"), diff --git a/ReactAndroid/src/main/jni/CMakeLists.txt b/ReactAndroid/src/main/jni/CMakeLists.txt index 420794146092e8..c7ee6155e9cc5a 100644 --- a/ReactAndroid/src/main/jni/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/CMakeLists.txt @@ -56,6 +56,7 @@ add_react_common_subdir(reactperflogger) add_react_common_subdir(logger) add_react_common_subdir(jsiexecutor) add_react_common_subdir(cxxreact) +add_react_common_subdir(jsc) add_react_common_subdir(jsi) add_react_common_subdir(butter) add_react_common_subdir(callinvoker) diff --git a/ReactCommon/jsc/CMakeLists.txt b/ReactCommon/jsc/CMakeLists.txt index 52188407ea55e4..2f387fa996f644 100644 --- a/ReactCommon/jsc/CMakeLists.txt +++ b/ReactCommon/jsc/CMakeLists.txt @@ -17,13 +17,18 @@ add_compile_options( -Wno-unused-lambda-capture -DLOG_TAG=\"ReactNative\") -add_library(jscruntime STATIC +add_library(jscruntime + STATIC JSCRuntime.h JSCRuntime.cpp) target_include_directories(jscruntime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(jscruntime folly_runtime jsc glog) +target_link_libraries(jscruntime + folly_runtime + jsc + jsi + glog) # TODO: Remove this flag when ready. # Android has this enabled by default, but the flag is still needed for iOS. diff --git a/ReactCommon/jsi/CMakeLists.txt b/ReactCommon/jsi/CMakeLists.txt index 3f2a8c15d3faaa..0967a7d7ee69b1 100644 --- a/ReactCommon/jsi/CMakeLists.txt +++ b/ReactCommon/jsi/CMakeLists.txt @@ -25,19 +25,3 @@ target_include_directories(jsi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(jsi folly_runtime glog) - -################## -### jscruntime ### -################## - -add_library(jscruntime STATIC - JSCRuntime.h - JSCRuntime.cpp) - -target_include_directories(jscruntime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(jscruntime folly_runtime jsc glog) - -# TODO: Remove this flag when ready. -# Android has this enabled by default, but the flag is still needed for iOS. -target_compile_options(jscruntime PRIVATE -DRN_FABRIC_ENABLED) From 67b74e7a9b929abdfcf2f1ee637f6c7a4eb81acb Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 29 Nov 2022 02:56:35 -0800 Subject: [PATCH 10/12] RNGP - Various improvements needed for 3rd party libs (#35496) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35496 This commit includes a series of fixes needed for better integration with libraries for 0.71: - I've added an `android/README.md` file as some libraries were failing the build if the folder was missing - RNGP now applies dep substitution on app and all the libraries project - RNGP now adds repositories on app and all the libraries project - I've removed the maven local repo to the `/android` folder as now is empty - I've fixed the path for the JSC repo for Windows users - I've added a bit of backward compat by re-adding an empty `project.react.ext` block that libraries might read from. - I've removed `codegenDir` from the `GenerateCodegenArtifactsTask` which was unused. Changelog: [Internal] [Changed] - RNGP - Various improvements needed for 3rd party libs Reviewed By: cipolleschi Differential Revision: D41549489 fbshipit-source-id: 2252da0180ac24fd3fe5a55300527da6781f0f8c --- .gitignore | 3 +- android/README.md | 21 ++++++ .../kotlin/com/facebook/react/ReactPlugin.kt | 3 +- .../tasks/GenerateCodegenArtifactsTask.kt | 6 -- .../react/utils/BackwardCompatUtils.kt | 48 ++++++++++++ .../facebook/react/utils/DependencyUtils.kt | 73 ++++++++++-------- .../tasks/GenerateCodegenArtifactsTaskTest.kt | 18 +---- .../react/utils/BackwardCompatUtilsTest.kt | 43 +++++++++++ .../react/utils/DependencyUtilsTest.kt | 74 +++++++++++++++---- 9 files changed, 220 insertions(+), 69 deletions(-) create mode 100644 android/README.md create mode 100644 packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt create mode 100644 packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt diff --git a/.gitignore b/.gitignore index fadf52a7f1c187..01027b3802aef0 100644 --- a/.gitignore +++ b/.gitignore @@ -64,7 +64,8 @@ buck-out .gradle local.properties *.iml -/android/ +/android/* +!/android/README.md # Node node_modules diff --git a/android/README.md b/android/README.md new file mode 100644 index 00000000000000..613d9a3f28392f --- /dev/null +++ b/android/README.md @@ -0,0 +1,21 @@ +# The `/android` folder inside `react-native` + +Starting from React Native 0.71, we're not shipping the `/android` folder inside the React Native NPM package +anymore due to sizing constraints on NPM. The Android artifacts are distributed via Maven Central. +You can read more about it in this RFC: +https://github.com/react-native-community/discussions-and-proposals/pull/508 + +If you're a library author and you're manipulating the React Native .aar files, to extract headers, +extract `.so` files or do anything with it, you're probably doing something wrong. React Native +0.71 ships with all the necessary logic to let you consume it transparently by just using: + +``` +implementation("com.facebook.react:react-android") +// or to keep backward compatibility with older versions of React Native: +implementation("com.facebook.react:react-native:+") +``` + +You should consider refactoring your library code not to unzip/manipulate the React Native .aar files. + +This README.md file is kept in this folder as some libraries are checking the existence of the `/android` folder +and failing user builds if the folder is missing. diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt index 152a7667e4ca03..af47458d37f50a 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/ReactPlugin.kt @@ -14,6 +14,7 @@ import com.facebook.react.tasks.GenerateCodegenArtifactsTask import com.facebook.react.tasks.GenerateCodegenSchemaTask import com.facebook.react.utils.AgpConfiguratorUtils.configureBuildConfigFields import com.facebook.react.utils.AgpConfiguratorUtils.configureDevPorts +import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap import com.facebook.react.utils.DependencyUtils.configureDependencies import com.facebook.react.utils.DependencyUtils.configureRepositories import com.facebook.react.utils.DependencyUtils.readVersionString @@ -46,6 +47,7 @@ class ReactPlugin : Plugin { configureReactNativeNdk(project, extension) configureBuildConfigFields(project) configureDevPorts(project) + configureBackwardCompatibilityReactMap(project) project.extensions.getByType(AndroidComponentsExtension::class.java).apply { onVariants(selector().all()) { variant -> @@ -134,7 +136,6 @@ class ReactPlugin : Plugin { it.dependsOn(generateCodegenSchemaTask) it.reactNativeDir.set(extension.reactNativeDir) it.nodeExecutableAndArgs.set(extension.nodeExecutableAndArgs) - it.codegenDir.set(extension.codegenDir) it.generatedSrcDir.set(generatedSrcDir) it.packageJsonFile.set(findPackageJsonFile(project, extension)) it.codegenJavaPackageName.set(extension.codegenJavaPackageName) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt index 12830982d0cabe..b6003eeb5e14e6 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTask.kt @@ -26,8 +26,6 @@ abstract class GenerateCodegenArtifactsTask : Exec() { @get:Internal abstract val reactNativeDir: DirectoryProperty - @get:Internal abstract val codegenDir: DirectoryProperty - @get:Internal abstract val generatedSrcDir: DirectoryProperty @get:InputFile abstract val packageJsonFile: RegularFileProperty @@ -38,10 +36,6 @@ abstract class GenerateCodegenArtifactsTask : Exec() { @get:Input abstract val libraryName: Property - @get:InputFile - val combineJsToSchemaCli: Provider = - codegenDir.file("lib/cli/combine/combine-js-to-schema-cli.js") - @get:InputFile val generatedSchemaFile: Provider = generatedSrcDir.file("schema.json") diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt new file mode 100644 index 00000000000000..5c39266900f61c --- /dev/null +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/BackwardCompatUtils.kt @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package com.facebook.react.utils + +import java.util.* +import org.gradle.api.Project + +internal object BackwardCompatUtils { + + fun configureBackwardCompatibilityReactMap(project: Project) { + if (project.extensions.extraProperties.has("react")) { + @Suppress("UNCHECKED_CAST") + val reactMap = + project.extensions.extraProperties.get("react") as? Map ?: mapOf() + if (reactMap.isNotEmpty()) { + project.logger.error( + """ + ******************************************************************************** + + ERROR: Using old project.ext.react configuration. + We identified that your project is using a old configuration block as: + + project.ext.react = [ + // ... + ] + + You should migrate to the new configuration: + + react { + // ... + } + You can find documentation inside `android/app/build.gradle` on how to use it. + + ******************************************************************************** + """ + .trimIndent()) + } + } + + // We set an empty react[] map so if a library is reading it, they will find empty values. + project.extensions.extraProperties.set("react", mapOf()) + } +} diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt index d11199ed2cdcf4..68480b6016bc7e 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt @@ -15,44 +15,57 @@ import org.gradle.api.artifacts.repositories.MavenArtifactRepository internal object DependencyUtils { + /** + * This method takes care of configuring the repositories{} block for both the app and all the 3rd + * party libraries which are auto-linked. + */ fun configureRepositories(project: Project, reactNativeDir: File) { - with(project) { - if (hasProperty("REACT_NATIVE_MAVEN_LOCAL_REPO")) { - mavenRepoFromUrl("file://${property("REACT_NATIVE_MAVEN_LOCAL_REPO")}") + project.rootProject.allprojects { eachProject -> + with(eachProject) { + if (hasProperty("REACT_NATIVE_MAVEN_LOCAL_REPO")) { + mavenRepoFromUrl("file://${property("REACT_NATIVE_MAVEN_LOCAL_REPO")}") + } + // We add the snapshot for users on nightlies. + mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") + repositories.mavenCentral() + // Android JSC is installed from npm + mavenRepoFromUrl( + "file://${reactNativeDir}${File.separator}..${File.separator}jsc-android${File.separator}dist") + repositories.google() + mavenRepoFromUrl("https://www.jitpack.io") } - // We add the snapshot for users on nightlies. - mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") - repositories.mavenCentral() - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - mavenRepoFromUrl("file://${reactNativeDir}/android") - // Android JSC is installed from npm - mavenRepoFromUrl("file://${reactNativeDir}/../jsc-android/dist") - repositories.google() - mavenRepoFromUrl("https://www.jitpack.io") } } + /** + * This method takes care of configuring the resolution strategy for both the app and all the 3rd + * party libraries which are auto-linked. Specifically it takes care of: + * - Forcing the react-android/hermes-android version to the one specified in the package.json + * - Substituting `react-native` with `react-android` and `hermes-engine` with `hermes-android`. + */ fun configureDependencies(project: Project, versionString: String) { if (versionString.isBlank()) return - project.configurations.all { configuration -> - // Here we set a dependencySubstitution for both react-native and hermes-engine as those - // coordinates are voided due to https://github.com/facebook/react-native/issues/35210 - // This allows users to import libraries that are still using - // implementation("com.facebook.react:react-native:+") and resolve the right dependency. - configuration.resolutionStrategy.dependencySubstitution { - it.substitute(it.module("com.facebook.react:react-native")) - .using(it.module("com.facebook.react:react-android:${versionString}")) - .because( - "The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.") - it.substitute(it.module("com.facebook.react:hermes-engine")) - .using(it.module("com.facebook.react:hermes-android:${versionString}")) - .because( - "The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.") + project.rootProject.allprojects { eachProject -> + eachProject.configurations.all { configuration -> + // Here we set a dependencySubstitution for both react-native and hermes-engine as those + // coordinates are voided due to https://github.com/facebook/react-native/issues/35210 + // This allows users to import libraries that are still using + // implementation("com.facebook.react:react-native:+") and resolve the right dependency. + configuration.resolutionStrategy.dependencySubstitution { + it.substitute(it.module("com.facebook.react:react-native")) + .using(it.module("com.facebook.react:react-android:${versionString}")) + .because( + "The react-native artifact was deprecated in favor of react-android due to https://github.com/facebook/react-native/issues/35210.") + it.substitute(it.module("com.facebook.react:hermes-engine")) + .using(it.module("com.facebook.react:hermes-android:${versionString}")) + .because( + "The hermes-engine artifact was deprecated in favor of hermes-android due to https://github.com/facebook/react-native/issues/35210.") + } + configuration.resolutionStrategy.force( + "com.facebook.react:react-android:${versionString}", + "com.facebook.react:hermes-android:${versionString}", + ) } - configuration.resolutionStrategy.force( - "com.facebook.react:react-android:${versionString}", - "com.facebook.react:hermes-android:${versionString}", - ) } } diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt index 86f45fec3207d8..e188e47c849525 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/tasks/GenerateCodegenArtifactsTaskTest.kt @@ -29,28 +29,16 @@ class GenerateCodegenArtifactsTaskTest { val codegenDir = tempFolder.newFolder("codegen") val outputDir = tempFolder.newFolder("output") - val task = - createTestTask { - it.codegenDir.set(codegenDir) - it.generatedSrcDir.set(outputDir) - } + val task = createTestTask { it.generatedSrcDir.set(outputDir) } - assertEquals( - File(codegenDir, "lib/cli/combine/combine-js-to-schema-cli.js"), - task.combineJsToSchemaCli.get().asFile) assertEquals(File(outputDir, "schema.json"), task.generatedSchemaFile.get().asFile) } @Test fun generateCodegenSchema_outputFile_isSetCorrectly() { - val codegenDir = tempFolder.newFolder("codegen") val outputDir = tempFolder.newFolder("output") - val task = - createTestTask { - it.codegenDir.set(codegenDir) - it.generatedSrcDir.set(outputDir) - } + val task = createTestTask { it.generatedSrcDir.set(outputDir) } assertEquals(File(outputDir, "java"), task.generatedJavaFiles.get().asFile) assertEquals(File(outputDir, "jni"), task.generatedJniFiles.get().asFile) @@ -80,13 +68,11 @@ class GenerateCodegenArtifactsTaskTest { @WithOs(OS.LINUX) fun setupCommandLine_willSetupCorrectly() { val reactNativeDir = tempFolder.newFolder("node_modules/react-native/") - val codegenDir = tempFolder.newFolder("codegen") val outputDir = tempFolder.newFolder("output") val task = createTestTask { it.reactNativeDir.set(reactNativeDir) - it.codegenDir.set(codegenDir) it.generatedSrcDir.set(outputDir) it.nodeExecutableAndArgs.set(listOf("--verbose")) } diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt new file mode 100644 index 00000000000000..da08d88ad06a71 --- /dev/null +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/BackwardCompatUtilsTest.kt @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package com.facebook.react.utils + +import com.facebook.react.tests.createProject +import com.facebook.react.utils.BackwardCompatUtils.configureBackwardCompatibilityReactMap +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +class BackwardCompatUtilsTest { + + @get:Rule val tempFolder = TemporaryFolder() + + @Test + fun configureBackwardCompatibilityReactMap_addsEmptyReactMap() { + val project = createProject() + + configureBackwardCompatibilityReactMap(project) + + assertTrue(project.extensions.extraProperties.has("react")) + @Suppress("UNCHECKED_CAST") + assertTrue((project.extensions.extraProperties.get("react") as Map).isEmpty()) + } + + @Test + fun configureBackwardCompatibilityReactMap_withExistingMapSetByUser_wipesTheMap() { + val project = createProject() + project.extensions.extraProperties.set("react", mapOf("enableHermes" to true)) + + configureBackwardCompatibilityReactMap(project) + + assertTrue(project.extensions.extraProperties.has("react")) + @Suppress("UNCHECKED_CAST") + assertTrue((project.extensions.extraProperties.get("react") as Map).isEmpty()) + } +} diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt index 4386e33233d36e..70fba6e60972a9 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt @@ -14,6 +14,7 @@ import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl import com.facebook.react.utils.DependencyUtils.readVersionString import java.net.URI import org.gradle.api.artifacts.repositories.MavenArtifactRepository +import org.gradle.testfixtures.ProjectBuilder import org.junit.Assert.* import org.junit.Rule import org.junit.Test @@ -51,21 +52,6 @@ class DependencyUtilsTest { }) } - @Test - fun configureRepositories_containsReactNativeNpmLocalMavenRepo() { - val projectFolder = tempFolder.newFolder() - val reactNativeDir = tempFolder.newFolder("react-native") - val repositoryURI = URI.create("file://${reactNativeDir}/android") - val project = createProject(projectFolder) - - configureRepositories(project, reactNativeDir) - - assertNotNull( - project.repositories.firstOrNull { - it is MavenArtifactRepository && it.url == repositoryURI - }) - } - @Test fun configureRepositories_containsJscLocalMavenRepo() { val projectFolder = tempFolder.newFolder() @@ -161,6 +147,46 @@ class DependencyUtilsTest { assertTrue(indexOfSnapshotRepo < indexOfMavenCentral) } + @Test + fun configureRepositories_appliesToAllProjects() { + val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/") + val rootProject = ProjectBuilder.builder().build() + val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build() + val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build() + + configureRepositories(appProject, tempFolder.root) + + assertNotNull( + appProject.repositories.firstOrNull { + it is MavenArtifactRepository && it.url == repositoryURI + }) + assertNotNull( + libProject.repositories.firstOrNull { + it is MavenArtifactRepository && it.url == repositoryURI + }) + } + + @Test + fun configureRepositories_withPreviousExclusionRulesOnMavenCentral_appliesCorrectly() { + val repositoryURI = URI.create("https://repo.maven.apache.org/maven2/") + val rootProject = ProjectBuilder.builder().build() + val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build() + val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build() + + // Let's emulate a library which set an `excludeGroup` on `com.facebook.react` for Central. + libProject.repositories.mavenCentral { repo -> + repo.content { content -> content.excludeGroup("com.facebook.react") } + } + + configureRepositories(appProject, tempFolder.root) + + // We need to make sure we have Maven Central defined twice, one by the library, + // and another is the override by RNGP. + assertEquals( + 2, + libProject.repositories.count { it is MavenArtifactRepository && it.url == repositoryURI }) + } + @Test fun configureDependencies_withEmptyVersion_doesNothing() { val project = createProject() @@ -181,6 +207,24 @@ class DependencyUtilsTest { assertTrue(forcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }) } + @Test + fun configureDependencies_withVersionString_appliesOnAllProjects() { + val rootProject = ProjectBuilder.builder().build() + val appProject = ProjectBuilder.builder().withName("app").withParent(rootProject).build() + val libProject = ProjectBuilder.builder().withName("lib").withParent(rootProject).build() + appProject.plugins.apply("com.android.application") + libProject.plugins.apply("com.android.library") + + configureDependencies(appProject, "1.2.3") + + val appForcedModules = appProject.configurations.first().resolutionStrategy.forcedModules + val libForcedModules = libProject.configurations.first().resolutionStrategy.forcedModules + assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" }) + assertTrue(appForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }) + assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:react-android:1.2.3" }) + assertTrue(libForcedModules.any { it.toString() == "com.facebook.react:hermes-android:1.2.3" }) + } + @Test fun readVersionString_withCorrectVersionString_returnsIt() { val propertiesFile = From 89cac880282a1fa739fd60eac0f9563187d75347 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 29 Nov 2022 10:43:54 -0800 Subject: [PATCH 11/12] Rename hermes-* target to don't use dashes (#35506) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35506 In our build we had a mixture of `_` and `-` to separate targets. Dashes don't play well with Gradle + as we expose them now via Prefab, let's stick to use only underscores Changelog: [Internal] [Changed] - Rename target to don't use dashes Reviewed By: cipolleschi Differential Revision: D41578938 fbshipit-source-id: 8aa44aa2dc7bf4822b45e5044532837b989817d2 --- ReactAndroid/build.gradle | 12 ++++++------ .../hermes/reactexecutor/HermesExecutor.java | 4 ++-- .../src/main/jni/react/hermes/reactexecutor/BUCK | 2 +- .../jni/react/hermes/reactexecutor/CMakeLists.txt | 10 +++++----- ReactCommon/hermes/executor/CMakeLists.txt | 10 +++++----- ReactCommon/hermes/inspector/CMakeLists.txt | 8 ++++---- .../com/facebook/react/utils/NdkConfiguratorUtils.kt | 4 ++-- .../facebook/react/utils/NdkConfiguratorUtilsTest.kt | 8 ++++---- react.gradle | 4 ++-- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 3f285029101ac3..72f5b7c6ce2ac3 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -180,9 +180,9 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa ), // These prefab targets are used by Expo & Reanimated new PrefabPreprocessingEntry( - "hermes-executor", - // "hermes-executor" is statically linking against "hermes-executor-common" - // and "hermes-inspector". Here we expose only the headers that we know are needed. + "hermes_executor", + // "hermes_executor" is statically linking against "hermes_executor_common" + // and "hermes_inspector". Here we expose only the headers that we know are needed. new Pair("../ReactCommon/hermes/inspector/", "hermes/inspector/") ), new PrefabPreprocessingEntry( @@ -463,7 +463,7 @@ android { "react_render_uimanager", "react_render_scheduler", "react_render_mounting", - "hermes-executor" + "hermes_executor" } } ndk { @@ -580,8 +580,8 @@ android { reactnativejni { headers(new File(prefabHeadersDir, "reactnativejni").absolutePath) } - "hermes-executor" { - headers(new File(prefabHeadersDir, "hermes-executor").absolutePath) + hermes_executor { + headers(new File(prefabHeadersDir, "hermes_executor").absolutePath) } } diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java index e72bca607c1c96..b0e4f24d10d912 100644 --- a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java @@ -24,8 +24,8 @@ public static void loadLibrary() throws UnsatisfiedLinkError { if (mode_ == null) { // libhermes must be loaded explicitly to invoke its JNI_OnLoad. SoLoader.loadLibrary("hermes"); - SoLoader.loadLibrary("hermes-executor"); - // libhermes-executor is built differently for Debug & Release so we load the proper mode. + SoLoader.loadLibrary("hermes_executor"); + // libhermes_executor is built differently for Debug & Release so we load the proper mode. if (ReactBuildConfig.DEBUG == true) { mode_ = "Debug"; } else { diff --git a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/BUCK b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/BUCK index 94229f186158e8..e292584fa62864 100644 --- a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/BUCK +++ b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/BUCK @@ -14,6 +14,6 @@ rn_xplat_cxx_library( headers = [], header_namespace = "", compiler_flags = ["-fexceptions"], - soname = "libhermes-executor.$(ext)", + soname = "libhermes_executor.$(ext)", visibility = ["PUBLIC"], ) diff --git a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt index 15b4a6aed6f25d..550b324e821950 100644 --- a/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt +++ b/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt @@ -8,20 +8,20 @@ set(CMAKE_VERBOSE_MAKEFILE on) file(GLOB_RECURSE hermes_executor_SRC CONFIGURE_DEPENDS *.cpp) -add_library(hermes-executor +add_library(hermes_executor SHARED ${hermes_executor_SRC} ) target_compile_options( - hermes-executor + hermes_executor PRIVATE $<$:-DHERMES_ENABLE_DEBUGGER=1> -fexceptions ) -target_include_directories(hermes-executor PRIVATE .) +target_include_directories(hermes_executor PRIVATE .) target_link_libraries( - hermes-executor - hermes-executor-common + hermes_executor + hermes_executor_common jsireact fb fbjni diff --git a/ReactCommon/hermes/executor/CMakeLists.txt b/ReactCommon/hermes/executor/CMakeLists.txt index f05d3bfc0e36a7..10cf67f5f0e78d 100644 --- a/ReactCommon/hermes/executor/CMakeLists.txt +++ b/ReactCommon/hermes/executor/CMakeLists.txt @@ -8,22 +8,22 @@ set(CMAKE_VERBOSE_MAKEFILE on) file(GLOB_RECURSE hermes_executor_SRC CONFIGURE_DEPENDS *.cpp) add_library( - hermes-executor-common + hermes_executor_common STATIC ${hermes_executor_SRC} ) -target_include_directories(hermes-executor-common PUBLIC .) -target_link_libraries(hermes-executor-common +target_include_directories(hermes_executor_common PUBLIC .) +target_link_libraries(hermes_executor_common jsireact hermes-engine::libhermes jsi debug - hermes-inspector + hermes_inspector ) if(${CMAKE_BUILD_TYPE} MATCHES Debug) target_compile_options( - hermes-executor-common + hermes_executor_common PRIVATE -DHERMES_ENABLE_DEBUGGER=1 ) diff --git a/ReactCommon/hermes/inspector/CMakeLists.txt b/ReactCommon/hermes/inspector/CMakeLists.txt index 14f6f1ce263900..1b4c6a3b59f4ad 100644 --- a/ReactCommon/hermes/inspector/CMakeLists.txt +++ b/ReactCommon/hermes/inspector/CMakeLists.txt @@ -8,20 +8,20 @@ set(CMAKE_VERBOSE_MAKEFILE on) file(GLOB hermesinspector_SRC CONFIGURE_DEPENDS *.cpp detail/*.cpp chrome/*.cpp) -add_library(hermes-inspector +add_library(hermes_inspector STATIC ${hermesinspector_SRC}) target_compile_options( - hermes-inspector + hermes_inspector PRIVATE -DHERMES_ENABLE_DEBUGGER=1 -DHERMES_INSPECTOR_FOLLY_KLUDGE=1 -fexceptions ) -target_include_directories(hermes-inspector PUBLIC ${REACT_COMMON_DIR}) -target_link_libraries(hermes-inspector +target_include_directories(hermes_inspector PUBLIC ${REACT_COMMON_DIR}) +target_link_libraries(hermes_inspector jsinspector fb fbjni diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt index 13bbb3ab8c51dd..9d0e6b9740c8e4 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/NdkConfiguratorUtils.kt @@ -127,10 +127,10 @@ internal object NdkConfiguratorUtils { excludes.add("**/libjsc.so") excludes.add("**/libjscexecutor.so") includes.add("**/libhermes.so") - includes.add("**/libhermes-executor.so") + includes.add("**/libhermes_executor.so") } else { excludes.add("**/libhermes.so") - excludes.add("**/libhermes-executor.so") + excludes.add("**/libhermes_executor.so") includes.add("**/libjsc.so") includes.add("**/libjscexecutor.so") } diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt index 41d498b23dccec..bf2f27926ab357 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/NdkConfiguratorUtilsTest.kt @@ -24,9 +24,9 @@ class NdkConfiguratorUtilsTest { assertFalse("**/libjscexecutor.so" in includes) assertTrue("**/libhermes.so" in includes) - assertTrue("**/libhermes-executor.so" in includes) + assertTrue("**/libhermes_executor.so" in includes) assertFalse("**/libhermes.so" in excludes) - assertFalse("**/libhermes-executor.so" in excludes) + assertFalse("**/libhermes_executor.so" in excludes) } @Test @@ -34,9 +34,9 @@ class NdkConfiguratorUtilsTest { val (excludes, includes) = getPackagingOptionsForVariant(hermesEnabled = false) assertTrue("**/libhermes.so" in excludes) - assertTrue("**/libhermes-executor.so" in excludes) + assertTrue("**/libhermes_executor.so" in excludes) assertFalse("**/libhermes.so" in includes) - assertFalse("**/libhermes-executor.so" in includes) + assertFalse("**/libhermes_executor.so" in includes) assertTrue("**/libjsc.so" in includes) assertTrue("**/libjscexecutor.so" in includes) diff --git a/react.gradle b/react.gradle index da5505975a0c78..250299bb78359f 100644 --- a/react.gradle +++ b/react.gradle @@ -442,11 +442,11 @@ afterEvaluate { if (cleanup) { // Reduce size by deleting the debugger/inspector - include '**/libhermes-executor-debug.so' + include '**/libhermes_executor_debug.so' } else { // Release libs take precedence and must be removed // to allow debugging - include '**/libhermes-executor-release.so' + include '**/libhermes_executor_release.so' } } else { // For JSC, delete all the libhermes* files From e108e9ebf1e6c52b6eeffeb6c41f842ad95baa0d Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 29 Nov 2022 11:21:12 -0800 Subject: [PATCH 12/12] RNGP - Fix DependencyUtils for Windows support (#35508) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35508 It turns out that my previous diff hasn't really solved the Windows support. The problem is that we're not escaping the URI of the Maven Local repository properly on Windows. To overcome this, I'll instead use the `toURI()` Api of File to properly create a valid URI for a given folder. Changelog: [Internal] [Changed] - RNGP - Fix DependencyUtils for Windows support Reviewed By: cipolleschi Differential Revision: D41581849 fbshipit-source-id: 7905073c6daaf7c6a97405b3e6fb94b8f382234a --- .../facebook/react/utils/DependencyUtils.kt | 9 ++++++--- .../react/utils/DependencyUtilsTest.kt | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt index 68480b6016bc7e..c8760f644d8dbe 100644 --- a/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt +++ b/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt @@ -23,14 +23,14 @@ internal object DependencyUtils { project.rootProject.allprojects { eachProject -> with(eachProject) { if (hasProperty("REACT_NATIVE_MAVEN_LOCAL_REPO")) { - mavenRepoFromUrl("file://${property("REACT_NATIVE_MAVEN_LOCAL_REPO")}") + val mavenLocalRepoPath = property("REACT_NATIVE_MAVEN_LOCAL_REPO") as String + mavenRepoFromURI(File(mavenLocalRepoPath).toURI()) } // We add the snapshot for users on nightlies. mavenRepoFromUrl("https://oss.sonatype.org/content/repositories/snapshots/") repositories.mavenCentral() // Android JSC is installed from npm - mavenRepoFromUrl( - "file://${reactNativeDir}${File.separator}..${File.separator}jsc-android${File.separator}dist") + mavenRepoFromURI(File(reactNativeDir, "../jsc-android/dist").toURI()) repositories.google() mavenRepoFromUrl("https://www.jitpack.io") } @@ -83,4 +83,7 @@ internal object DependencyUtils { fun Project.mavenRepoFromUrl(url: String): MavenArtifactRepository = project.repositories.maven { it.url = URI.create(url) } + + fun Project.mavenRepoFromURI(uri: URI): MavenArtifactRepository = + project.repositories.maven { it.url = uri } } diff --git a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt index 70fba6e60972a9..1b7c728cc4b4f6 100644 --- a/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt +++ b/packages/react-native-gradle-plugin/src/test/kotlin/com/facebook/react/utils/DependencyUtilsTest.kt @@ -10,6 +10,7 @@ package com.facebook.react.utils import com.facebook.react.tests.createProject import com.facebook.react.utils.DependencyUtils.configureDependencies import com.facebook.react.utils.DependencyUtils.configureRepositories +import com.facebook.react.utils.DependencyUtils.mavenRepoFromURI import com.facebook.react.utils.DependencyUtils.mavenRepoFromUrl import com.facebook.react.utils.DependencyUtils.readVersionString import java.net.URI @@ -27,9 +28,9 @@ class DependencyUtilsTest { @Test fun configureRepositories_withProjectPropertySet_configuresMavenLocalCorrectly() { val localMaven = tempFolder.newFolder("m2") - val localMavenURI = URI.create("file://$localMaven/") + val localMavenURI = localMaven.toURI() val project = createProject() - project.extensions.extraProperties.set("REACT_NATIVE_MAVEN_LOCAL_REPO", localMaven) + project.extensions.extraProperties.set("REACT_NATIVE_MAVEN_LOCAL_REPO", localMaven.absolutePath) configureRepositories(project, tempFolder.root) @@ -110,10 +111,10 @@ class DependencyUtilsTest { @Test fun configureRepositories_withProjectPropertySet_hasHigherPriorityThanMavenCentral() { val localMaven = tempFolder.newFolder("m2") - val localMavenURI = URI.create("file://$localMaven/") + val localMavenURI = localMaven.toURI() val mavenCentralURI = URI.create("https://repo.maven.apache.org/maven2/") val project = createProject() - project.extensions.extraProperties.set("REACT_NATIVE_MAVEN_LOCAL_REPO", localMaven) + project.extensions.extraProperties.set("REACT_NATIVE_MAVEN_LOCAL_REPO", localMaven.absolutePath) configureRepositories(project, tempFolder.root) @@ -297,4 +298,13 @@ class DependencyUtilsTest { assertEquals(URI.create("https://hello.world"), mavenRepo.url) } + + @Test + fun mavenRepoFromURI_worksCorrectly() { + val process = createProject() + val repoFolder = tempFolder.newFolder("maven-repo") + val mavenRepo = process.mavenRepoFromURI(repoFolder.toURI()) + + assertEquals(repoFolder.toURI(), mavenRepo.url) + } }