mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Expose C++ TurboModule codegen
Summary: This adjusts the previously unused (but fully working!) `rn_codegen_cxx_modules` rule to be consistent with the other codegen rules and calls it from the `rn_codegen` with the "JSI" suffix to not conflict with the other rules, and to match the convention established by hand-written C++ TurboModules. Changelog: Internal Reviewed By: RSNara Differential Revision: D34451208 fbshipit-source-id: 4d779b068dfa4f7fd73fd3bca354fffe86d01f73
This commit is contained in:
committed by
Facebook GitHub Bot
parent
964e816752
commit
a0a2958cda
@@ -508,7 +508,8 @@ def rn_codegen_components(
|
||||
|
||||
def rn_codegen_cxx_modules(
|
||||
name = "",
|
||||
schema_target = ""):
|
||||
schema_target = "",
|
||||
library_labels = []):
|
||||
generate_fixtures_rule_name = "generate_fixtures_cxx-{}".format(name)
|
||||
generate_module_h_name = "generate_module_h-{}".format(name)
|
||||
generate_module_cpp_name = "generate_module_cpp-{}".format(name)
|
||||
@@ -523,37 +524,36 @@ def rn_codegen_cxx_modules(
|
||||
|
||||
fb_native.genrule(
|
||||
name = generate_module_h_name,
|
||||
cmd = "cp $(location :{})/NativeModules.h $OUT".format(generate_fixtures_rule_name),
|
||||
out = "NativeModules.h",
|
||||
cmd = "cp $(location :{})/{}JSI.h $OUT".format(generate_fixtures_rule_name, name),
|
||||
out = "{}JSI.h".format(name),
|
||||
labels = ["codegen_rule"],
|
||||
)
|
||||
|
||||
fb_native.genrule(
|
||||
name = generate_module_cpp_name,
|
||||
cmd = "cp $(location :{})/NativeModules.cpp $OUT".format(generate_fixtures_rule_name),
|
||||
out = "NativeModules.cpp",
|
||||
cmd = "cp $(location :{})/{}JSI-generated.cpp $OUT".format(generate_fixtures_rule_name, name),
|
||||
out = "{}JSI-generated.cpp".format(name),
|
||||
labels = ["codegen_rule"],
|
||||
)
|
||||
|
||||
if is_running_buck_project():
|
||||
rn_xplat_cxx_library(name = "generated_cxx_modules-{}".format(name))
|
||||
rn_xplat_cxx_library(name = "{}JSI".format(name))
|
||||
else:
|
||||
rn_xplat_cxx_library(
|
||||
name = "generated_cxx_modules-{}".format(name),
|
||||
name = "{}JSI".format(name),
|
||||
srcs = [
|
||||
":{}".format(generate_module_cpp_name),
|
||||
],
|
||||
headers = [
|
||||
":{}".format(generate_module_h_name),
|
||||
],
|
||||
header_namespace = "react/modules/{}".format(name),
|
||||
header_namespace = "",
|
||||
exported_headers = {
|
||||
"NativeModules.cpp": ":{}".format(generate_module_cpp_name),
|
||||
"NativeModules.h": ":{}".format(generate_module_h_name),
|
||||
"{}/{}JSI.h".format(name, name): ":{}".format(generate_module_h_name),
|
||||
},
|
||||
fbobjc_compiler_flags = get_apple_compiler_flags(),
|
||||
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
|
||||
labels = ["codegen_rule"],
|
||||
labels = library_labels + ["codegen_rule"],
|
||||
platforms = (ANDROID, APPLE),
|
||||
preprocessor_flags = [
|
||||
"-DLOG_TAG=\"ReactNative\"",
|
||||
|
||||
@@ -85,7 +85,7 @@ const FileTemplate = ({
|
||||
* ${'@'}generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/${libraryName}/NativeModules.h>
|
||||
#include "${libraryName}JSI.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -221,7 +221,7 @@ module.exports = {
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
const fileName = 'NativeModules.cpp';
|
||||
const fileName = `${libraryName}JSI-generated.cpp`;
|
||||
const replacedTemplate = FileTemplate({
|
||||
modules,
|
||||
libraryName,
|
||||
|
||||
@@ -183,7 +183,7 @@ module.exports = {
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
const fileName = 'NativeModules.h';
|
||||
const fileName = `${libraryName}JSI.h`;
|
||||
const replacedTemplate = FileTemplate({modules});
|
||||
|
||||
return new Map([[fileName, replacedTemplate]]);
|
||||
|
||||
+14
-14
@@ -2,7 +2,7 @@
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture SampleWithUppercaseName 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"SampleWithUppercaseNameJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -11,7 +11,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/SampleWithUppercaseName/NativeModules.h>
|
||||
#include \\"SampleWithUppercaseNameJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -32,7 +32,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture complex_objects 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"complex_objectsJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -41,7 +41,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/complex_objects/NativeModules.h>
|
||||
#include \\"complex_objectsJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -79,7 +79,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture empty_native_modules 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"empty_native_modulesJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -88,7 +88,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/empty_native_modules/NativeModules.h>
|
||||
#include \\"empty_native_modulesJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -109,7 +109,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture native_modules_with_type_aliases 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"native_modules_with_type_aliasesJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -118,7 +118,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/native_modules_with_type_aliases/NativeModules.h>
|
||||
#include \\"native_modules_with_type_aliasesJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -146,7 +146,7 @@ AliasTurboModuleCxxSpecJSI::AliasTurboModuleCxxSpecJSI(std::shared_ptr<CallInvok
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture real_module_example 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"real_module_exampleJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -155,7 +155,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/real_module_example/NativeModules.h>
|
||||
#include \\"real_module_exampleJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -228,7 +228,7 @@ NativeExceptionsManagerCxxSpecJSI::NativeExceptionsManagerCxxSpecJSI(std::shared
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture simple_native_modules 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"simple_native_modulesJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -237,7 +237,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/simple_native_modules/NativeModules.h>
|
||||
#include \\"simple_native_modulesJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -302,7 +302,7 @@ NativeSampleTurboModuleCxxSpecJSI::NativeSampleTurboModuleCxxSpecJSI(std::shared
|
||||
|
||||
exports[`GenerateModuleCpp can generate fixture two_modules_different_files 1`] = `
|
||||
Map {
|
||||
"NativeModules.cpp" => "/**
|
||||
"two_modules_different_filesJSI-generated.cpp" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -311,7 +311,7 @@ Map {
|
||||
* @generated by codegen project: GenerateModuleH.js
|
||||
*/
|
||||
|
||||
#include <react/modules/two_modules_different_files/NativeModules.h>
|
||||
#include \\"two_modules_different_filesJSI.h\\"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
+7
-7
@@ -2,7 +2,7 @@
|
||||
|
||||
exports[`GenerateModuleH can generate fixture SampleWithUppercaseName 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"SampleWithUppercaseNameJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
exports[`GenerateModuleH can generate fixture complex_objects 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"complex_objectsJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -69,7 +69,7 @@ virtual void getArrays(jsi::Runtime &rt, const jsi::Object &options) = 0;
|
||||
|
||||
exports[`GenerateModuleH can generate fixture empty_native_modules 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"empty_native_modulesJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
|
||||
exports[`GenerateModuleH can generate fixture native_modules_with_type_aliases 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"native_modules_with_type_aliasesJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -134,7 +134,7 @@ virtual void cropImage(jsi::Runtime &rt, const jsi::Object &cropData) = 0;
|
||||
|
||||
exports[`GenerateModuleH can generate fixture real_module_example 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"real_module_exampleJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -189,7 +189,7 @@ virtual void dismissRedbox(jsi::Runtime &rt) = 0;
|
||||
|
||||
exports[`GenerateModuleH can generate fixture simple_native_modules 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"simple_native_modulesJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
@@ -231,7 +231,7 @@ virtual jsi::Value getValueWithPromise(jsi::Runtime &rt, bool error) = 0;
|
||||
|
||||
exports[`GenerateModuleH can generate fixture two_modules_different_files 1`] = `
|
||||
Map {
|
||||
"NativeModules.h" => "/**
|
||||
"two_modules_different_filesJSI.h" => "/**
|
||||
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
||||
|
||||
@@ -30,7 +30,7 @@ def rn_codegen(
|
||||
codegen_modules = False,
|
||||
library_labels = [],
|
||||
src_prefix = ""):
|
||||
if (codegen_modules):
|
||||
if codegen_modules:
|
||||
error_header = "rn_codegen(name=\"{}\")".format(name)
|
||||
if not native_module_spec_name:
|
||||
fail("{}: When codegen_modules = True, native_module_spec_name must be specified.".format(error_header))
|
||||
@@ -66,7 +66,13 @@ def rn_codegen(
|
||||
library_labels = library_labels,
|
||||
)
|
||||
|
||||
if (codegen_components):
|
||||
rn_codegen_cxx_modules(
|
||||
name = native_module_spec_name,
|
||||
schema_target = ":{}".format(module_schema_target),
|
||||
library_labels = library_labels,
|
||||
)
|
||||
|
||||
if codegen_components:
|
||||
component_spec_name = native_component_spec_name or name
|
||||
fb_native.genrule(
|
||||
name = "codegen_rn_components_schema_{}".format(component_spec_name),
|
||||
|
||||
Reference in New Issue
Block a user