react-native-community / discussions-and-proposals

Discussions and proposals related to the main React Native project
https://reactnative.dev
1.68k stars 126 forks source link

C++-only TurboModules library creation and AutoLinking #698

Open ShamKarthik-TA opened 1 year ago

ShamKarthik-TA commented 1 year ago

Introduction

C++ pure turbo modules library

Details

I have seen the pure C++ Turbo modules implementation of the react in the react documentation https://reactnative.dev/docs/the-new-architecture/cxx-cxxturbomodules

lets say I am using a existing C++ library with the C++ pure Turbo module

Discussion points

How can we create a isolated library without tm folder tightly coupling the logic ?

cortinico commented 1 year ago

How can we create a isolated library without tm folder tightly coupling the logic ?

Sorry can you clarify your question?

ShamKarthik-TA commented 1 year ago

this is the file structure we have to follow but we can see the tm folder is within the react native project but I want to maintain it as a separate library which can be installed as a independent package like react-native-mmkv

but as far as I have seen the react-native-mmkv implementation it is having a dependency with java and it needs java folder in android

and I want a library which should not have java implementation with jni instead use c++ implementation as mentioned in https://reactnative.dev/docs/the-new-architecture/cxx-cxxturbomodules to create library

CxxTurboModulesGuide
├── android
│   └── app
│       │── src
│       │   └── main
│       │       └── jni
│       │           ├── CMakeLists.txt
│       │           └── OnLoad.cpp
│       └── build.gradle (updated)
├── ios
│   └── CxxTurboModulesGuide
│       └── AppDelegate.mm (updated)
├── js
│   └── App.tsx|jsx (updated)
└── tm
    ├── CMakeLists.txt
    ├── NativeSampleModule.h
    ├── NativeSampleModule.cpp
    ├── NativeSampleModule.ts|js
    └── TurboModules.podspec
cortinico commented 1 year ago

I understand. What you're asking for today is quite advanced and we don't have a guide for it. Practically is possible to create a library that has only js and c++ code, but it won't be autolinked automatically (you'll have to tell to your users how to do it, edit the CMakeLists.txt file and so on).

This has already been requested in the past and we'll probably look into it in the future.