Skip to content

Commit

Permalink
Remove core modules from the default tmmdelegate (#43939)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43939

## Problem
If we link the default tmmdelegate with our vr apps, we get this issue:

```
ld.lld: error: duplicate symbol: facebook::react::NativeDevLoadingViewSpecJSI::NativeDevLoadingViewSpecJSI(facebook::react::JavaTurboModule::InitParams const&)
>>> defined at firsttimenux_v2AppModulesCodegen-generated.cpp:1367 (buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/arvr/libraries/react-panellib/FirstTimeNux/__firsttimenux_v2AppModulesCodegen-codegen-modules-jni_cpp__/out/firsttimenux_v2AppModulesCodegen-generated.cpp:1367)
>>>            firsttimenux_v2AppModulesCodegen-generated.cpp.pic.o:(facebook::react::NativeDevLoadingViewSpecJSI::NativeDevLoadingViewSpecJSI(facebook::react::JavaTurboModule::InitParams const&)) in archive buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/arvr/libraries/react-panellib/FirstTimeNux/__firsttimenux_v2AppModulesCodegen-jni__/libfirsttimenux_v2AppModulesCodegen-jni.pic.a
>>> defined at rncore-generated.cpp:606 (buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/xplat/js/react-native-github/__rncore-codegen-modules-jni_cpp__/out/rncore-generated.cpp:606)
>>>            rncore-generated.cpp.pic.o:(.text._ZN8facebook5react27NativeDevLoadingViewSpecJSIC2ERKNS0_15JavaTurboModule10InitParamsE+0x0) in archive buck-out/v2/gen/fbsource/bcbe7a50bd5ff29a/xplat/js/react-native-github/__rncore-jniAndroid__/librncore-jniAndroid.pic.a
```

## Cause
My best understanding of the problem:
- Default tmmdelegate links against rncore, which contains codegen for react native's standard library of modules.
- But, the default delegate also pulls in this appmodules.so library. That library also contains codegen for react native's standard library of modules + the app's modules.

So, two so libraries define the same symbols. Hence the build fails.

## Solution
Remove the codegen for react native's standard library of modules from the default tmmdelegate.

Prereq: In open source, also make appmodules.so include the codegen for react native's standard library of modules.

Changelog: [Android][Breaking] - Make the app responsible for returning core turbomodule jsi hostobjects

Reviewed By: cortinico

Differential Revision: D55613024

fbshipit-source-id: 6406a9f388ff9de01288de0e263a78a079e7a0da
  • Loading branch information
RSNara authored and facebook-github-bot committed Apr 6, 2024
1 parent a0d809c commit 7facb32
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <rncli.h>
#include <rncore.h>

#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
#include REACT_NATIVE_APP_CODEGEN_HEADER
Expand Down Expand Up @@ -95,8 +96,17 @@ std::shared_ptr<TurboModule> javaModuleProvider(
}
#endif

// We first try to look up core modules
if (auto module = rncore_ModuleProvider(name, params)) {
return module;
}

// And we fallback to the module providers autolinked by RN CLI
return rncli_ModuleProvider(name, params);
if (auto module = rncli_ModuleProvider(name, params)) {
return module;
}

return nullptr;
}

} // namespace facebook::react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <react/nativemodule/dom/NativeDOM.h>
#include <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
#include <rncore.h>

namespace facebook::react {

Expand Down Expand Up @@ -100,7 +99,8 @@ std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule(
return resolvedModule;
}
}
return rncore_ModuleProvider(name, params);

return nullptr;
}

} // namespace facebook::react
7 changes: 7 additions & 0 deletions packages/rn-tester/android/app/src/main/jni/OnLoad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <ReactCommon/SampleTurboModuleSpec.h>
#include <fbjni/fbjni.h>
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
#include <rncore.h>

#ifdef REACT_NATIVE_APP_CODEGEN_HEADER
#include REACT_NATIVE_APP_CODEGEN_HEADER
Expand Down Expand Up @@ -51,6 +52,12 @@ std::shared_ptr<TurboModule> javaModuleProvider(
return module;
}
#endif

// We first try to look up core modules
if (auto module = rncore_ModuleProvider(name, params)) {
return module;
}

return nullptr;
}

Expand Down

0 comments on commit 7facb32

Please sign in to comment.