Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert react-native-quick-crypto to Cxx turbo module. #327

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Szymon20000
Copy link
Member

@Szymon20000 Szymon20000 commented May 25, 2024

#Hack alert
I tried to make use of auto linking but turned out that our cmake included in generated autolink cmake was not able to find our deps. most likely because those are our dependencies added in our build Gradle. So For now I just added dummy cmake that is being included and it doesn't contain any symbols that we have in our final so.



RNTQuickCryptoCxx::RNTQuickCryptoCxx(std::shared_ptr<CallInvoker> jsInvoker): NativeQuickCryptoCxxCxxSpec<RNTQuickCryptoCxx>(std::move(jsInvoker)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]



RNTQuickCryptoCxx::RNTQuickCryptoCxx(std::shared_ptr<CallInvoker> jsInvoker): NativeQuickCryptoCxxCxxSpec<RNTQuickCryptoCxx>(std::move(jsInvoker)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]



RNTQuickCryptoCxx::RNTQuickCryptoCxx(std::shared_ptr<CallInvoker> jsInvoker): NativeQuickCryptoCxxCxxSpec<RNTQuickCryptoCxx>(std::move(jsInvoker)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3]

}

double RNTQuickCryptoCxx::install(jsi::Runtime &rt) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]

}

double RNTQuickCryptoCxx::install(jsi::Runtime &rt) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Redundant blank line at the start of a code block should be deleted. [whitespace/blank_line] [2]

auto hostObject = std::static_pointer_cast<jsi::HostObject>(
std::make_shared<::margelo::MGLQuickCryptoHostObject>(this->jsInvoker_, workerQueue));
auto object = jsi::Object::createFromHostObject(rt, hostObject);
rt.global().setProperty(rt, "__QuickCryptoProxy", std::move(object));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Add #include for move [build/include_what_you_use] [4]


#pragma mark - implementation
class RNTQuickCryptoCxx : public NativeQuickCryptoCxxCxxSpec<RNTQuickCryptoCxx> {
public:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
public: should be indented +1 space inside class RNTQuickCryptoCxx [whitespace/indent] [3]

#pragma mark - implementation
class RNTQuickCryptoCxx : public NativeQuickCryptoCxxCxxSpec<RNTQuickCryptoCxx> {
public:
RNTQuickCryptoCxx(std::shared_ptr<CallInvoker> jsInvoker);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Single-parameter constructors should be marked explicit. [runtime/explicit] [5]

public:
RNTQuickCryptoCxx(std::shared_ptr<CallInvoker> jsInvoker);
virtual ~RNTQuickCryptoCxx() = default;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]


double install(jsi::Runtime &rt);
};
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cpplint] reported by reviewdog 🐶
Namespace should be terminated with "// namespace margelo" [readability/namespace] [5]

"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/react-native/ReactCommon/turbomodule/core"
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
"./build/generated/source/codegen/jni/react/renderer/components/RTNQuickCryptoCxxSpec"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's really not a good idea...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something we need to talk to Meta about to hear their opinions.

We depend on OpenSSL and currently install it through Gradle (add the dep to build.gradle), but since a CxxTurboModule doesn't have a build.gradle anymore (it's built through the CodeGen'd CMakeList) we don't have the dependency anymore.
So now we add a build.gradle that builds our CxxTurboModule with externalNativeBuild, adds the OpenSSL prefab, and then additionally we have a dummy CMakeLists just for autolinking... I don't think this is a good idea, and we all agree that this is a temporary hack that we should get rid off asap.

Maybe two questions for different people;

  • @Szymon20000 can we add OpenSSL somehow differently? Then we don't need that dummy CMakeList
  • @philIip / @cortinico do you think that this is the future for all CxxTurboModules? No build.gradle, just only a CMakeLists?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but since a CxxTurboModule doesn't have a build.gradle anymore (it's built through the CodeGen'd CMakeList) we don't have the dependency anymore.

You should be able to configure the react-native.config.js to use your own CMakeLists.txt file + include external dependencies and access them via Prefab.
Using the codegen-ed one is the 'easiest' approach as it saves you from configuring extra build logic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we add the codegen'd specs then?
Do we add that generated path in /build/... to our CMake and assume codegen always generated it into that path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico That's exactly what I tried. I passed my own cmake that relied on codegened Cxx spec and prefab openssl. But because that cmake was build together outside of my build process the prefab wasn't available there.
How we can make prefabs available to autolink_cmake if they are only listed as dependencies in library build.gradle?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But because that cmake was build together outside of my build process the prefab wasn't available there.

that cmake <- Which CMake file are you referring to? Yours or the one generated by Codegen? Yours should have access to the prefab declared in build.gradle. The codegen one should not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey!
Thanks for finding time.
So there are 3 cmakes (in the new approach where we don't build ourselves in build.gradle) that I'm aware of:

  • codegen generated with specs/nodes/props
  • library cmake (it relies on openSSL prefab)
  • autolinking cmake generated by react Gradle plugin
    If I understand correctly in autolinking cmake the plugin includes first 2 cmakes. But the whole build process happens now per application (not per library). After adding openSSL as a prefab in library's build Gradle I got an error that cmake is not able to find openssl prefab.
    I can try it again and post the error that I got here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autolinking cmake generated by react Gradle plugin

There is not entirely correct. The Gradle plugin generates some .cmake files that contains variables used by the App's CMake file (to know which libraries to link against).

Are we able to create a PR against:
https://github.com/cortinico/reproducer-cxx-tm-autolinking

to show me your setup with the link against openssl and I can look into it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants