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

Example of using Meta's c++ JSI codegen #10745

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

acoates-ms
Copy link
Contributor

@acoates-ms acoates-ms commented Oct 14, 2022

This is a draft PR to show some of the required work and decisions we need to make to support using Meta's C++ JSI codegen in react-native-windows projects.

This shows the required changes to make the SampleLibraryCpp project provide a JSI turbomodule based on Meta's C++ JSI codegen instead of the NM2 codegen.

To do this I added an additional generator to the list of generators that @react-native-windows/codegen runs. -- So that it runs the c++ JSI codegen in addition to the NM2 codegen. If we want to support this, we should decide if we want to always generate that, or have apps opt-in in their codegenConfig.

Then there were changes required in SampleLibraryCPP.vcxproj to allow usage of Folly/boost which is required by the C++ JSI codegen. These changes would probably be something we'd want to generalize and provide to libraries.

Microsoft Reviewers: Open in CodeFlow

* in a way that also verifies at compile time that the native module matches the interface required
* by the TurboModule JS spec.
*/
#pragma once
Copy link
Member

Choose a reason for hiding this comment

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

pragma

This file does not look right yet. I guess it is still a TODO item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whats wrong with it? -- This should be the NM2 spec for the same module. (We happen to be using the c++ JSI spec to implement it in this case rather than this one)

Copy link
Member

Choose a reason for hiding this comment

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

How does it work? I do not see generated code with the custom attributes. The spec cannot be verified if there are no custom attributes.

@vmoroz
Copy link
Member

vmoroz commented Oct 14, 2022

We use this project file as a prototype for our Project templates. Could we duplicate this project to demo the JSI modules? I am not sure if we want to add dependencies on Folly and Boost if we use only NM2.


Refers to: packages/sample-apps/windows/SampleLibraryCPP/SampleLibraryCPP.vcxproj:2 in 8e2b13b. [](commit_id = 8e2b13b, deletion_comment = False)

@@ -0,0 +1,87 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
Copy link
Member

Choose a reason for hiding this comment

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

Meta

Is it out code or Meta?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thats ours... copy/paste error

@acoates-ms
Copy link
Contributor Author

We use this project file as a prototype for our Project templates. Could we duplicate this project to demo the JSI modules? I am not sure if we want to add dependencies on Folly and Boost if we use only NM2.

Refers to: packages/sample-apps/windows/SampleLibraryCPP/SampleLibraryCPP.vcxproj:2 in 8e2b13b. [](commit_id = 8e2b13b, deletion_comment = False)

Yes I agree, I would probably do that when this is for real. But for getting it up and running quickly this was eaiser. -- It also makes it easy to see the missing bits in the vcxproj, whereas having a whole new project it would be harder to see what was different from today to get it running.

@@ -94,7 +95,7 @@ using SwitchShadowNode = ConcreteViewShadowNode<
SwitchProps,
SwitchEventEmitter>;

extern const char UnimplementedNativeViewComponentName[];
JSI_EXPORT extern const char UnimplementedNativeViewComponentName[];
Copy link
Member

Choose a reason for hiding this comment

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

JSI_EXPORT

I am a bit concerned that all these types are going to become as exported types from DLLs. These are not ABI-safe type. By adding this macro we effectively introduce a huge non-ABI safe API surface. Could avoid it? We will never be able to fix later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dont think we export these:

@vmoroz
Copy link
Member

vmoroz commented Oct 14, 2022

Yes, it makes sense. Thanks!


In reply to: 1279342958

namespace facebook {
namespace react {

class JSI_EXPORT NativeMyJsiModuleCxxSpecJSI : public TurboModule {
Copy link
Member

Choose a reason for hiding this comment

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

NativeMyJsiModuleCxxSpecJSI

What is the difference between this NativeMyJsiModuleCxxSpecJSI and NativeMyModuleCxxSpecJSI below? They are both using JSI TurboModules. They look like code duplication to me. The same is in the .cpp file.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, we put generated specs for all modules in a project into one file! It makes sense.

@acoates-ms
Copy link
Contributor Author

Extracted most of this change into #10909. This code should be turned into a separate project that shows an example of a C++ JSI turbomodule without combining it with the other samples.

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.

2 participants