Skip to content

Commit

Permalink
Move libreact_newarchdefaults.so inside libreactnative.so
Browse files Browse the repository at this point in the history
Summary:
This is a more complex library as I had to introduce a `ReactNativeSoLoader` to handle the internal/oss scenarios.

Changelog:
[Internal] [Changed] - Move libreact_newarchdefaults.so inside libreactnative.so

Differential Revision: D55796933
  • Loading branch information
cortinico authored and facebook-github-bot committed Jul 24, 2024
1 parent 1cad4f8 commit 5a2ed4a
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 18 deletions.
5 changes: 5 additions & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,11 @@ public final class com/facebook/react/common/ReactConstants {
public static final field UNSET I
}

public final class com/facebook/react/common/ReactNativeSoLoader {
public static final field INSTANCE Lcom/facebook/react/common/ReactNativeSoLoader;
public static final fun loadLibrary (Ljava/lang/String;)Z
}

public class com/facebook/react/common/ShakeDetector : android/hardware/SensorEventListener {
public fun <init> (Lcom/facebook/react/common/ShakeDetector$ShakeListener;)V
public fun <init> (Lcom/facebook/react/common/ShakeDetector$ShakeListener;I)V
Expand Down
7 changes: 2 additions & 5 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ val preparePrefab by
listOf(
PrefabPreprocessingEntry(
"turbomodulejsijni", Pair("src/main/jni/react/turbomodule", "")),
PrefabPreprocessingEntry(
"react_newarchdefaults", Pair("src/main/jni/react/newarchdefaults", "")),
PrefabPreprocessingEntry(
"react_render_animations",
Pair("../ReactCommon/react/renderer/animations/", "react/renderer/animations/")),
Expand Down Expand Up @@ -244,6 +242,8 @@ val preparePrefab by
Pair("src/main/jni/react/turbomodule", ""),
// react_codegen_rncore
Pair(File(buildDir, "generated/source/codegen/jni/").absolutePath, ""),
// react_newarchdefaults
Pair("src/main/jni/react/newarchdefaults", ""),
// react_render_componentregistry
Pair(
"../ReactCommon/react/renderer/componentregistry/",
Expand Down Expand Up @@ -723,9 +723,6 @@ android {
create("turbomodulejsijni") {
headers = File(prefabHeadersDir, "turbomodulejsijni").absolutePath
}
create("react_newarchdefaults") {
headers = File(prefabHeadersDir, "react_newarchdefaults").absolutePath
}
create("react_render_animations") {
headers = File(prefabHeadersDir, "react_render_animations").absolutePath
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ add_library(jsi ALIAS ReactAndroid::jsi)
add_library(mapbufferjni ALIAS ReactAndroid::mapbufferjni)
add_library(react_render_mapbuffer ALIAS ReactAndroid::react_render_mapbuffer)
add_library(react_render_textlayoutmanager ALIAS ReactAndroid::react_render_textlayoutmanager)
add_library(react_newarchdefaults ALIAS ReactAndroid::react_newarchdefaults)
add_library(reactnative ALIAS ReactAndroid::reactnative)
add_library(turbomodulejsijni ALIAS ReactAndroid::turbomodulejsijni)
add_library(yoga ALIAS ReactAndroid::yoga)
Expand All @@ -82,7 +81,6 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
mapbufferjni # prefab ready
fbjni # via 3rd party prefab
jsi # prefab ready
react_newarchdefaults # prefab ready
reactnative # prefab ready
turbomodulejsijni # prefab ready
yoga # prefab ready
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.common

import com.facebook.react.BuildConfig
import com.facebook.soloader.SoLoader

public object ReactNativeSoLoader {

private var isReactNativeSoLoaded = false

private fun shouldLoadOnlyReactNativeSo(): Boolean = BuildConfig.IS_INTERNAL_BUILD.not()

@JvmStatic
public fun loadLibrary(shortName: String?): Boolean =
if (shouldLoadOnlyReactNativeSo()) {
if (!isReactNativeSoLoaded) {
// We don't need to use SoLoader at all at this point as we're handling the
// merging of the .so libraries manually.
System.loadLibrary("reactnative")
isReactNativeSoLoaded = true
}
true
} else {
SoLoader.loadLibrary(shortName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

package com.facebook.react.defaults

import com.facebook.react.common.ReactNativeSoLoader
import com.facebook.soloader.SoLoader

internal class DefaultSoLoader {
companion object {
@Synchronized
@JvmStatic
fun maybeLoadSoLibrary() {
SoLoader.loadLibrary("react_newarchdefaults")
ReactNativeSoLoader.loadLibrary("react_newarchdefaults")
try {
SoLoader.loadLibrary("appmodules")
} catch (e: UnsatisfiedLinkError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ endif(CCACHE_FOUND)

# Make sure every shared lib includes a .note.gnu.build-id header
add_link_options(-Wl,--build-id)
add_compile_options(-Wall -Werror -std=c++20)
add_compile_options(-Wall -Werror -std=c++20 -DREACT_NATIVE_OPEN_SOURCE)

function(add_react_android_subdir relative_path)
add_subdirectory(${REACT_ANDROID_DIR}/${relative_path} ReactAndroid/${relative_path})
Expand Down Expand Up @@ -158,6 +158,7 @@ add_library(reactnative
$<TARGET_OBJECTS:react_nativemodule_featureflags>
$<TARGET_OBJECTS:react_nativemodule_idlecallbacks>
$<TARGET_OBJECTS:react_nativemodule_microtasks>
$<TARGET_OBJECTS:react_newarchdefaults>
$<TARGET_OBJECTS:react_render_attributedstring>
$<TARGET_OBJECTS:react_render_componentregistry>
$<TARGET_OBJECTS:react_render_consistency>
Expand Down Expand Up @@ -185,6 +186,7 @@ add_library(reactnative
)
target_link_libraries(reactnative PUBLIC
double-conversion
fabricjni
fbjni
folly_runtime
glog
Expand All @@ -206,6 +208,7 @@ target_include_directories(reactnative
$<TARGET_PROPERTY:react_nativemodule_idlecallbacks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_featureflags,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_nativemodule_microtasks,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_newarchdefaults,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_attributedstring,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_componentregistry,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:react_render_consistency,INTERFACE_INCLUDE_DIRECTORIES>
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/ReactAndroid/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

#include "OnLoad.h"
#include <fbjni/fbjni.h>

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {

});
return facebook::jni::initialize(
vm, [] { facebook::react::OnLoad_react_newarchdefaults(); });
}
14 changes: 14 additions & 0 deletions packages/react-native/ReactAndroid/src/main/jni/OnLoad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <fbjni/fbjni.h>

namespace facebook {
namespace react {
JNIEXPORT void OnLoad_react_newarchdefaults();
}
} // namespace facebook
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ add_compile_options(-fexceptions -frtti -std=c++20 -Wall -DLOG_TAG=\"ReactNative

file(GLOB react_newarchdefaults_SRC CONFIGURE_DEPENDS *.cpp)

add_library(react_newarchdefaults SHARED ${react_newarchdefaults_SRC})
add_library(react_newarchdefaults OBJECT ${react_newarchdefaults_SRC})

target_include_directories(react_newarchdefaults PUBLIC .)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
#include "DefaultComponentsRegistry.h"
#include "DefaultTurboModuleManagerDelegate.h"

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(vm, [] {
facebook::react::DefaultTurboModuleManagerDelegate::registerNatives();
facebook::react::DefaultComponentsRegistry::registerNatives();
});
namespace facebook {
namespace react {
JNIEXPORT void OnLoad_react_newarchdefaults() {
facebook::react::DefaultTurboModuleManagerDelegate::registerNatives();
facebook::react::DefaultComponentsRegistry::registerNatives();
}
} // namespace react
} // namespace facebook

#ifndef REACT_NATIVE_OPEN_SOURCE
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
return facebook::jni::initialize(
vm, [] { facebook::react::OnLoad_react_newarchdefaults(); });
}
#endif

0 comments on commit 5a2ed4a

Please sign in to comment.