Commit Graph

901 Commits

Author SHA1 Message Date
Dmitry Rykun ccd3b04770 Add Float and Int type support for Android modules (#42126)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42126

This diff changes how numeric types are generated for Android native modules.
Before this diff:
|Codegen Type|Java Type|
| -- | -- |
|number|double|
|Float|double|
|Double|double|
|Int32|double|
After this diff:
|Codegen Type|Java Type|
| -- | -- |
|number|double|
|Float|**float**|
|Double|double|
|Int32|**int**|

Changelog: [Android][Breaking] - Codegen: mapping for numeric types is changed for Android native modules. `Float` -> `float`; `Int32` -> `int`.

Reviewed By: cipolleschi

Differential Revision: D52420921

fbshipit-source-id: 32b3bbdf5fd24db8d7ac12c262bab5fde4e1f2bc
2024-01-05 02:47:17 -08:00
Dmitry Rykun 5aa425c086 Add Float and Int type support for iOS modules (#42125)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42125

This diff changes how numeric types are generated for Objective-C native modules.
Before this diff:
|Codegen Type|Objective-C Type|
| -- | -- |
|number|double|
|Float|double|
|Double|double|
|Int32|double|
After this diff:
|Codegen Type|Objective-C Type|
| -- | -- |
|number|double|
|Float|**float**|
|Double|double|
|Int32|**NSInteger**|

Changelog: [iOS][Breaking] - Codegen: mapping for numeric types is changed for Objective-C native modules. `Float` -> `float`; `Int32` -> `NSInteger`.

Reviewed By: cipolleschi

Differential Revision: D52479442

fbshipit-source-id: 1b2e101a9593a75c7c19b0da3a01a0e592a35ba5
2024-01-04 05:41:51 -08:00
Dmitry Rykun 82f8cf1836 Introduce TypeUtils (#42122)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42122

This diff introduces the `TypeUtils` directory where we can put platform-specific, context-independent type transformations.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D52291837

fbshipit-source-id: 561b9c494aab5bfee3b3c668d3346bbd320e5266
2024-01-03 08:58:30 -08:00
Dmitry Rykun dae4a11e90 Introduce "headerPrefix" codegen option (#41956)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41956

By default, generated Cxx sources for components all end up in same directory. However the include declarations in them look like this:
```
#include <react/renderer/components/${libraryName}/ShadowNodes.h>
```
And not like this:
```
#include "ShadowNodes.h"
```
This works fine with Buck because it supports header prefixes.
To get this working with CocoaPods we define additional `HEADER_SEARCH_PATHS` for our `React-Codegen` pod.
This approach will not work if we want to generate code at the library level and check in the artifacts. That's because we don't have control over the Podspec there, and can't inject those additional `HEADER_SEARCH_PATHS`.

This diff adds the `headerPrefix` argument to the codegen entry point. It is `react/renderer/components/${libraryName}` by default, but can become empty if we want to generate code at the library level, and don't want to deal with this nested header structure.

*Note:* `RNCodegen` runs all the generators [in a loop](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/generators/RNCodegen.js#L263-L275), assuming that the all have same function signature So I had to add the `headerPrefix` argument to all the generators, even to the ones that don't really need it.

Changelog: [General][Added] - Introduce "headerPrefix" codegen option.

Reviewed By: zeyap

Differential Revision: D51811596

fbshipit-source-id: c5c3e1e571c7c4ea2f5354eb9a7b0df6b917fc0c
2023-12-20 09:25:05 -08:00
Alex Taylor (alta) e730fdff50 Update hermes-parser and related packages in fbsource to 0.18.2 (#42003)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42003

Bump hermes-parser and related packages to [0.18.2](https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/CHANGELOG.md).

Changelog: [internal]

Reviewed By: pieterv

Differential Revision: D52303145

fbshipit-source-id: 1b2b07c16bf55879ecb3b6611cbd53faa1ecc012
2023-12-19 20:48:44 -08:00
Dmitry Rykun c45c13f1b1 Replace utils.parseArgs with yargs (#41924)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41924

`utils.parseArgs` are only available in Node >=18.3, we can't use this function because we target Node >=18.0.
This diff replaces `utils.parseArgs` with `yargs`.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D52117818

fbshipit-source-id: 79223997874b6cfdea2ce38243b615a0dbb704a6
2023-12-19 04:43:37 -08:00
Zeya Peng c52af32042 support Array param for native component command (#41899)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41899

Changelog: [Internal]

Reviewed By: dmytrorykun

Differential Revision: D52046165

fbshipit-source-id: b8276b3db54b3f88b90f16a3275d591decfa5fb3
2023-12-14 13:47:33 -08:00
Christoph Purrer 8183afeb81 Use enum classes in C++ Turbo Modules (#41923)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41923

Changelog: [Internal][BREAKING] Use C++ enum classes in C++ Turbo Modules

Problem:
Using **C styles** `enums` can easily cause compiliation errors if symbol names collide. This code does not compile:
```
enum CustomEnumInt { A = 23, B = 42 };

static int A = 22;
```

This **C++ code**, using `enum classes` compiles:
```
enum class CustomEnumInt : int32_t { A = 23, B = 42 };

static int A = 22;
```

Reviewed By: rshest

Differential Revision: D52098598

fbshipit-source-id: c919bd2e41970c83a032fec91b0537cd6fae8397
2023-12-14 06:54:49 -08:00
Zeya Peng c848bf9545 support Array param for native component command in codegen (#41894)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41894

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51866557

fbshipit-source-id: 595de8d49c0654b36d70a2c8872173fd6232a2be
2023-12-12 18:48:47 -08:00
Christoph Purrer 4187a8c71c Throw parser error in case direct recursive types are not nullable (#41866)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41866

Direct recursive member types require infinite memory and aren't possible with current hardware.

Throw parser error to make this visible.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51999832

fbshipit-source-id: 671f87325f33dd24f70ff3e2229c9d0b888d7445
2023-12-12 03:28:41 -08:00
Christoph Purrer db609ff0c6 Add function properties to C++ TM complex datatyes (#41810)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41810

Changelog: [Internal]

Reviewed By: zeyap

Differential Revision: D51858746

fbshipit-source-id: e45ee68fc40e8b7ae3388ecdcedfec646d022e19
2023-12-05 23:27:06 -08:00
Christoph Purrer 19420b7e68 Use C++17 namespace for compoments (#41791)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41791

Same as https://github.com/facebook/react-native/pull/41771 - but this time for compoments

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D51804740

fbshipit-source-id: 87f4db5dabfce4639f16fdcb1b1df0fee338a555
2023-12-05 07:31:57 -08:00
Christoph Purrer b101dd0e34 Use C++17 namespace (#41771)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41771

Changelog: [Internal]

Since we are already enforcing C++20 (and 17), we can set the namespace declaration to the C++17 style

Reviewed By: NickGerleman

Differential Revision: D51789991

fbshipit-source-id: 165d7d4e652d60ab200e2355e084010a02f470a4
2023-12-04 19:07:51 -08:00
Christoph Purrer 974e584891 Update GenerateModuleH fixture (#41780)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41780

This updates our test fixture with more concrete examples from:
https://github.com/facebook/react-native/blob/main/packages/rn-tester/NativeCxxModuleExample/NativeCxxModuleExample.js

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51804559

fbshipit-source-id: 3290bc5447e0b47551ad73f5b041e332443e71c6
2023-12-04 14:50:46 -08:00
Christoph Purrer 749b8dd2d4 Add logic to generate recursive TM members (#41768)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41768

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51572375

fbshipit-source-id: e4ce0726c457ea02a7710ea1d21bbd697e35848a
2023-12-04 08:56:42 -08:00
Christoph Purrer ead73de464 Add a BinaryTreeNode example for Cxx TMs (#41767)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41767

Changelog: [Internal]

Adds a simple example showing a direct recursive node in a Cxx TM.

Currently we can't auto-generate [the necessary C++ Types](https://reactnative.dev/docs/next/the-new-architecture/cxx-custom-types#struct-generator) - but we can add it later if this scenarios becomes really common.

Direct recursive nodes, can't be value types - it would require infinite memory. Hence they are nullable and managed by a smart pointer.

Reviewed By: rshest

Differential Revision: D51784136

fbshipit-source-id: f6f0710d03583bdf1e6e72ba42d8df7f8ff8d915
2023-12-04 05:54:50 -08:00
Alex Taylor (alta) c98fa9ce8b Update hermes-parser and related packages in fbsource to 0.18.0 (#41689)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41689

Bump hermes-parser and related packages to 0.18.0.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D51642821

fbshipit-source-id: b7abde7d3e0de195c18a5cb18d4cdd0a1d435127
2023-11-30 10:35:12 -08:00
Christoph Purrer ef9c164f5f Simplify C++ TM struct generation (#41645)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41645

Right now, when defining concrete structs and Bridging headers for Cxx TMs we need to define their member types twice:
```
using ConstantsStruct =
    NativeCxxModuleExampleCxxBaseConstantsStruct<bool, int32_t, std::string>;

template <>
struct Bridging<ConstantsStruct>
    : NativeCxxModuleExampleCxxBaseConstantsStructBridging<
          bool,
          int32_t,
          std::string> {};
```
Now we only need to define those once
```
using ConstantsStruct =
    NativeCxxModuleExampleCxxConstantsStruct<bool, int32_t, std::string>;

template <>
struct Bridging<ConstantsStruct>
    : NativeCxxModuleExampleCxxConstantsStructBridging<ConstantsStruct> {};
```

This change keeps the existing base types untouched - but they will be removed in the next RN version.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51571453

fbshipit-source-id: 2783bd48bf786ffa80d322d06456b5d6f2d7ba8a
2023-11-27 03:43:28 -08:00
Ramanpreet Nara 4e92016a09 Remove hard-coded SampleTurboModule exclude (#41574)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41574

The codegen scripts hard-code to exclude NativeSampleTurboModule.

This diff modifies the codegen infra (i.e: combine-js-to-schema-cli.js) to accept an argument: --exclude <regex>.

Auxiliary changes:
- Refactor argument parsing to rely on node's util.parseArgs

Changelog: [Internal]

Reviewed By: javache, dmytrorykun

Differential Revision: D51471526

fbshipit-source-id: 98b88058f8c4b6fa4d776d96a1eb0f15144906a8
2023-11-22 13:52:51 -08:00
Ramanpreet Nara 3ee4b8f5a1 Create genrule to generate appmodules.so (#41466)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41466

## Context
In open source, all apps use the same turbomodulemanager delegate (i.e: the default delegate).

This diff introduces the buck infra that makes the oss default delegate work for meta apps.

Concretely, we are going to make React Native use the same  delegate for **all** Meta apps.

Each Meta app will:
1. At build time, generate a unique TMProvider map
2. At app init time, initialize the default delegate with the TMProvider map.

## Implementation
**Step #1:** At build time, generate a unique TMProvider map

**Insight:** Buck genrules can accept, as input, the output of a buck query.

So, here's how we get this done:
1. Buck query (i.e: input to Genrule): Given the app's deps, query all the schemas in the app.
2. Genrule: Read the schemas to generate the TMProvider map. The TMProvider map will also contain **all** the app's C++ module codegen.

Concretely:
1. This diff introduces a macro: rn_codegen_appmodules(deps).
2. rn_codegen_appmodules(deps) generates appmodules.so, which contains the TMProvider map.

**Step #2:** At app init time, initialize the default delegate with the TMProvider map.

This is how we'll initialize the DefaultTurboModuleManagerDelegate:
1. DefaultTurboModuleManagerDelegate will load appmodules.so during init.
2. When loaded, appmodules.so will assign the code-generated TMProvider map to DefaultTurboModuleManagerDelegate.

## Impact
This should allow us to:
1. Get one step closer to getting rid of the `js1 build turbomodule-manager-delegates --target <app>` script
3. Remove the TurboModuleManagerDelegate from React Native's public API. (Because we use one delegate for all React Native apps in Meta and OSS)

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D50988397

fbshipit-source-id: 0ca5dec14e2dae89ec97f5d39a182c7937c5c7bf
2023-11-22 13:52:51 -08:00
Dmitry Rykun 3ecf1bce1d Refactor generate-artifacts-executor.js: keep schema in memory instead of writing/reading from disk (#41554)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41554

This diff removes inefficiency where we first write schema to disk in `combine-js-to-schema.js`, and then read it from disk in `generate-specs-cli-executor.js`. With this change we can just pass it as an argument.
Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D51161162

fbshipit-source-id: 35d14ca3e53e4bf999520c635c66909c20081096
2023-11-22 06:57:03 -08:00
Dmitry Rykun 9071a3a0b0 Delete node calls from generate-artifacts-executor.js (#41534)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41534

This diff deletes calls to `node` from `generate-artifacts-executor.js`, and replaces them with normal `requires` of JS sources.
This is a squashed version of (D51116291 ... D51158799).
The following sequence of changes has been made:
1. Require and directly invoke `generate-specs-cli-executor` instead of using `node`.
2. Use `codegen-util` to get `RNCodegen` in `generate-provider-cli.js`.
3. Use `RNCodegen` directly instead of using `node`.
4. Move all implementation code from `combine-js-to-schema-cli.js` to `combine-js-to-schema.js`.
5. Decouple building the codegen from getting the codegen CLI.
6. Use `combine-js-to-schema` directly instead of using `node`.
7. Delete unit test that was testing node invocation.
8. Delete `nodeBinary` argument form `generate-codegen-artifacts.js` and its callsites.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D51158845

fbshipit-source-id: 5e039801c8045a42349f7cb6ca28e2df24634589
2023-11-22 05:18:15 -08:00
Christoph Purrer c2ac0cc72a react-native-codegen: Cxx TMs > Fixed Undefined Behavior exception when running ASAN builds (#41401)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41401

Changelog: [Internal]

When build Cxx Turbo Modules with Clang's ASAN build mode the apps are crashing at runtime due to, e.g.:
```
runtime error: downcast of address 0x00010dafd618 which does not point to an object of type 'facebook::react::NativePerformance'
0x00010dafd618: note: object is of type 'facebook::react::NativePerformanceCxxSpec<facebook::react::NativePerformance>'
 00 00 00 00  f0 08 49 06 01 00 00 00  4e 61 74 69 76 65 50 65  72 66 6f 72 6d 61 6e 63  65 43 78 78
              ^~~~~~~~~~~~~~~~~~~~~~~
              vptr for 'facebook::react::NativePerformanceCxxSpec<facebook::react::NativePerformance>'
UndefinedBehaviorSanitizer: undefined-behavior FBReactNativeSpecJSI.h:6122:17
```

Where the corresponding generated code looks like

```
NativePerformanceCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
    : TurboModule(std::string{NativePerformanceCxxSpec::kModuleName}, jsInvoker),
      delegate_(static_cast<T*>(this), jsInvoker) {}
```

This change fixes that problem

AddressSanitizer: stack-use-after-scope shared_ptr.h:634 in std::__1::shared_ptr<facebook::react::InstanceHandle const>::shared_ptr[abi:v160006](std::__1::shared_ptr<facebook::react::InstanceHandle const> const&)
Shadow bytes around the buggy address:
  0x00016cea4a80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00016cea4b00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00016cea4b80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x00016cea4c00: 00 00 00 00 00 00 00 00 f1 f1 f1 f1 f8 f8 f8 f8
  0x00016cea4c80: f8 f8 f2 f2 f2 f2 f8 f8 f2 f2 00 00 f2 f2 f8 f8
=>0x00016cea4d00: f2 f2 f8 f8 f2 f2 00 00 f2 f2[f8]f8 f2 f2 00 00
  0x00016cea4d80: f2 f2 f8 f8 f2 f2 f8 f8 f2 f2 f8 f8 f8 f2 f2 f2
  0x00016cea4e00: f2 f2 f8 f8 f2 f2 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
  0x00016cea4e80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f2 f2 f2 f2 f2 f2 f2
  0x00016cea4f00: f2 f2 f8 f8 f3 f3 f3 f3 00 00 00 00 00 00 00 00
  0x00016cea4f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==41992==ABORTING

```

Reviewed By: rshest

Differential Revision: D51183328

fbshipit-source-id: 5aff5b5eecb9d78f9b7438fbdda2c01625c9a4d9
2023-11-09 22:14:57 -08:00
Tommy Nguyen c58e19e89a Correctly declare runtime dependencies (#41398)
Summary:
In pnpm setups, codegen will fail during build because it cannot find its dependencies. Some of the dependencies it relies on at runtime are currently declared under `devDependencies`. This change moves them to `dependencies`.

## Changelog:

[GENERAL] [FIXED] - Fix `react-native/codegen` not being able to resolve dependencies in pnpm setups

Pull Request resolved: https://github.com/facebook/react-native/pull/41398

Test Plan: We are currently trying to [enable pnpm mode](https://github.com/microsoft/rnx-kit/pull/2811) in rnx-kit and hit this issue. We've patched this package locally and it works.

Reviewed By: christophpurrer

Differential Revision: D51169116

Pulled By: NickGerleman

fbshipit-source-id: 28906a0de412c660d2fc42f62deaf77240d27a58
2023-11-09 15:07:52 -08:00
Moti Zilberman 5abaf388cd Use hermes-parser for Flow codegen specs (#39036)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39036

Changelog: [General][Changed] Use `hermes-parser` instead of `flow-parser` to parse Flow Codegen specs.

`hermes-parser` is a WASM build of the Hermes parser (plus supporting code), maintained by the Flow and Hermes teams. It is the recommended way of parsing Flow code in Node and its benefits (compared to `flow-parser`) include better performance and improved type safety.

Here we update `react-native/codegen` to use `hermes-parser` instead of `flow-parser`. Both parsers produce ASTs that conform to the ESTree spec so this is mostly a drop-in replacement.

In future work we should be able to use the improved AST types available in `hermes-estree` to improve type safety within `react-native/codegen` itself.

Reviewed By: huntie

Differential Revision: D48384078

fbshipit-source-id: 310ad150ec62671ba395b0e2f6415ccae97ac04d
2023-11-08 01:33:42 -08:00
Moti Zilberman a74765eb0a Throw Flow syntax errors instead of continuing to process the AST (#39035)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39035

Changelog: [General][Fixed] Flow syntax errors in Codegen specs are no longer ignored.

Instead of throwing errors like most parsers, the `flow-parser` package returns errors as part of the AST (along with a best-effort parse). It turns out that `react-native/codegen` ignores such errors and only detects a subset of them after the fact. Here we change the behaviour to immediately throwing a descriptive error message (containing the file name and a code frame).

**This change is theoretically breaking** for any published packages that already contain broken Flow code (that somehow doesn't happen to affect the Codegen output today). Hopefully, anyone using Flow-flavoured RN Codegen is also typechecking with Flow and/or building with Metro (which would both flag the same errors), so the impact should be fairly contained.

Reviewed By: huntie

Differential Revision: D48385786

fbshipit-source-id: c7e1f5fb64a61fb0eb9e9f8f7501b43264c9626c
2023-11-08 01:33:42 -08:00
Moti Zilberman d6e0bc714a Enable lint/sort-imports everywhere (#41334)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41334

TSIA.

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D51025812

fbshipit-source-id: e10d437be775a6b80946483aa96460f34927f870
2023-11-06 12:59:38 -08:00
George Zahariev 9c135eb928 Update scripts to support AsExpressions
Summary:
Update various scripts to support AsExpressions, found by looking for scripts currently handling `TypeCastExpression`

Changelog: [Internal]

Reviewed By: SamChou19815

Differential Revision: D50822952

fbshipit-source-id: c88c04a507d94ddbc6458a68fd36509463e91953
2023-11-02 14:09:03 -07:00
Gijs Weterings d4ad19c969 Revert D49370200: Migrate codegen to shared build setup, remove package build pre-step from RNTester
Differential Revision:
D49370200

Original commit changeset: 992913155169

Original Phabricator Diff: D49370200

fbshipit-source-id: e8232c97c22065fb54ac940ee2351b2155eb51e0
2023-10-23 12:00:54 -07:00
Alex Hunt 4db31a3110 Migrate codegen to shared build setup, remove package build pre-step from RNTester (#39540)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39540

This simplifies the use of Codegen when creating dev builds of `rn-tester` in the monorepo. It now runs from source for this internal scenario, and this package is now built using the shared monorepo build setup.

Changes:
- Migrate `packages/react-native-codegen` to the shared `yarn build` setup.
    - Update package to use `"exports"` field and wrap entry point modules with `babel-register` (NOTE: This is only required for each entry point internally used in the monorepo).
- Fixup small Flow syntax quirks that fail under `hermes-parser`.
- Remove `BuildCodegenCLITask` task from Android build.
- Remove Codegen `build.sh` call from iOS build, use `require.resolve` for `combine-js-to-schema-cli.js` entry point.

Externally significant FYIs:
- `react-native/codegen` is converted to use the `"exports"` field — it should export all `.js` files, as before.
- `codegenPath` is now ignored and marked as deprecated on `ReactExtensions.kt`.

NOTE: TypeScript auto-generation is not yet enabled on this package, since it uses CommonJS `module.exports` syntax (unsupported by `flow-api-translator`).

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D49370200

fbshipit-source-id: 992913155169912ea1a3cb24cb26efbd3f783058
2023-10-23 08:32:33 -07:00
Alex Hunt f40bb9331c Bump package versions for next major (#39764)
Summary:
#publish-packages-to-npm

Bump all package versions to `0.74.0` (next major release) for `main`, following instructions at https://reactnative.dev/contributing/release-branch-cut-and-rc0#12-bump-minor-version-of-all-monorepo-packages-in-main.

```sh
yarn bump-all-updated-packages --release-branch-cutoff
```

Changelog: [Internal]

Pull Request resolved: https://github.com/facebook/react-native/pull/39764

Test Plan: —

Reviewed By: robhogan

Differential Revision: D49871039

Pulled By: huntie

fbshipit-source-id: f4df6efeae4d8a9209e7aae7b9e6fea3d15793b5
2023-10-11 08:36:23 -07:00
David Vacca b7191cde4e Move TurboModule from com.facebook.react.turbomodule -> com.facebook.react.internal.turbomodule (#39682)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39682

Move TurboModule from com.facebook.react.turbomodule -> com.facebook.react.internal.turbomodule

bypass-github-export-checks

changelog: [internal] internal

Reviewed By: RSNara

Differential Revision: D49523696

fbshipit-source-id: fee155f4fb7acf0f28f900c79f7aa38074bec0e6
2023-10-09 19:24:19 -07:00
Sunbreak af7bf9371c Fix typo of JSI module Cpp codegen (#39604)
Summary:
Fix code generatetion comment from `GenerateModuleH.js` to `GenerateModuleCpp.js`

## Changelog:

[GENERAL] [FIXED] - Fix typo of JSI module Cpp codegen

Pull Request resolved: https://github.com/facebook/react-native/pull/39604

Test Plan: None

Reviewed By: christophpurrer

Differential Revision: D49558245

Pulled By: cortinico

fbshipit-source-id: 28b6a6f4da0f5f973717f785fe21db86179f1996
2023-09-25 12:30:34 -07:00
Pieter Vanderwerff 29f62a41b4 Deploy 0.217.0 to fbsource (#39610)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39610

Reviewed By: SamChou19815

Differential Revision: D49522399

fbshipit-source-id: 98dc8ce53a4dea2b68909fda5f92251c6cc91717
2023-09-22 17:29:26 -07:00
Alex Hunt eaec4f7fda Fix Codegen build script on EdenFS (#39566)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39566

Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.

This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.

NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](https://github.com/facebook/react-native/pull/38718), and 2/ drop this step entirely from the Android Gradle build.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D49468891

fbshipit-source-id: 25d5db81798cf8ab150a135174a45f4d4c2cb5a2
2023-09-21 04:09:43 -07:00
Samuel Susla 7c928fffcc Remove use of folly::F14FastMap from React Native (#39496)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39496

changelog: [internal]

Remove use of folly::F14FastMap in favour of std::unordered_map.

Reviewed By: fkgozali

Differential Revision: D48968297

fbshipit-source-id: fa1e80534f817e1e37f932558c09e418a23383e8
2023-09-18 06:27:45 -07:00
Nick Gerleman 17154a661f C++ 20 all the things (#39454)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39454

1. Build with C++ 20 everywhere.
2. Update folly in OSS build to avoid a warning, and let us opt out of heavy bits required for supporting coroutines (we are still more than a year behind).
3. Update the folly podspec for the new version of folly
4. Update the many, many, copy/pasted header search paths for folly dependencies to be able to resolve fmt, now exposed to folly headers
4. Replaces a deprecated atomic usage with equivalent.
5. Fixes a deprecated implicit capturing `this` by value in lambda (same behavior, added a TODO because it seems sus)

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D49271685

fbshipit-source-id: 16610f7bcd1032d5796cc11f1cfa92a33d8c2593
2023-09-15 01:17:55 -07:00
Nicola Corti cf33e048dc Remove Codegen buck-oss scripts as they're unused (#39422)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39422

Those scripts were used when Buck OSS was invoking codegen. As we don't do Buck OSS anymore, we can remove them.

Changelog:
[Internal] [Changed] - Remove Codegen buck-oss scripts as they're unused

Reviewed By: huntie

Differential Revision: D49229846

fbshipit-source-id: fad0526e609bab159c56a62b85c91690e4cdbbce
2023-09-13 08:46:52 -07:00
Ruslan Shestopalyuk 0c292f3934 Fix bad formatting of generated C++ code (#39212)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39212

## Changelog:
[Internal] -

Some of the generated C++ code was badly formatted - even though it's normally not supposed to be read by humans, sometimes it's still useful/needed, so it helps when it's more readable.

Reviewed By: christophpurrer

Differential Revision: D48827010

fbshipit-source-id: 3481af68ee6158902007c431e72e631d852c8b3c
2023-08-30 10:40:47 -07:00
Ruslan Shestopalyuk 3c6bf7bf32 Suport type aliases for TM getConstants() return type (#39136)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39136

## Changelog:
[Internal] -

`getConstants()` method  for TM was enforced to only use object literals for the return type specs.

This limits flexibility, in particular those data structures can't be consequently exported and picked up by codegen (not even mentioning the potential need for copypasting those obejct literals around).

This relaxes this restriction.

Note that I've been digging into the development history in order to find out whether there was any particular historical reason for such a limitation, but couldn't find any, so I assume it was rather incidental.

Reviewed By: christophpurrer

Differential Revision: D48620652

fbshipit-source-id: 92d6ba531fc99fb9b25b4957ae123e7832f44ee4
2023-08-24 06:54:03 -07:00
Dr. Sergey Pogodin a323249e0a A fix in Codegen for Windows build host (#36542)
Summary:
Android builds with new arch fail on Windows build host (https://github.com/facebook/react-native/issues/36475). This tiny correction fixes generation of `schema.json` (without it codegen failed to find any files, and generated empty schema). Unfortunately, does not fixes the issue with Windows host entirely, as builds still fail later (on ninja build step).

## Changelog:
[Android] [Fixed] - A bug fix for Android builds with new arch on Windows host.

Pull Request resolved: https://github.com/facebook/react-native/pull/36542

Reviewed By: NickGerleman

Differential Revision: D48563587

Pulled By: cortinico

fbshipit-source-id: acd510308ce9768fb17d3a33c7927de3237748ac
2023-08-22 15:14:06 -07:00
Siddarth Kumar 1d8727966d add emitBuildEventSchema to parser commons (#38810)
Summary:
[Codegen 119] This PR introduces `emitBuildEventSchema` to parser commons and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872

## Changelog:

[Internal] [Changed] - Add `emitBuildEventSchema` to parser commons and update usages.

Pull Request resolved: https://github.com/facebook/react-native/pull/38810

Test Plan:
Run `yarn jest react-native-codegen` locally and ensure CI is green

## Screenshot of test passing locally:

<img width="1047" alt="Screenshot 2023-08-07 at 8 03 49 AM" src="https://github.com/facebook/react-native/assets/64726664/ab87f004-d9f8-4b5f-800b-0e724430301f">

Reviewed By: rshest

Differential Revision: D48155051

Pulled By: cipolleschi

fbshipit-source-id: a3db3f4783d60681b366a871b1d2ee32eb864bc0
2023-08-08 11:52:26 -07:00
Kyaw Thura ccd191d79a - Extract the content into handleEventHandler (#38805)
Summary:
Part of https://github.com/facebook/react-native/issues/34872
> Extract the content of the if branches that handle the EventHandlers ([Flow](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/flow/components/events.js#L131-L151), [TypeScript](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/typescript/components/events.js#L150-L171)) into a handleEventHandler function in parsers-commons.js. This will take a name, a typeAnnotation, a parser and a findEventArgumentsAndType function as parameters. Use the switch based approach from TypeScript.

## Changelog:

[Internal][Changed]: Extract the content into handleEventHandler

Pull Request resolved: https://github.com/facebook/react-native/pull/38805

Test Plan: `yarn test react-native-codegen`

Reviewed By: rshest

Differential Revision: D48100350

Pulled By: cipolleschi

fbshipit-source-id: 5de6deacd50e87ea0ec96147fff7c14ba55e5368
2023-08-07 03:41:39 -07:00
Facebook Community Bot 305dd4bfe5 Re-sync with internal repository (#38794)
Co-authored-by: Facebook Community Bot <6422482+facebook-github-bot@users.noreply.github.com>
2023-08-04 17:22:07 +01:00
Luiz Ozorio e22d1a10cb Parser create getTypeAnnotationName(typeAnnotation) (#37580)
Summary:
> [Codegen 134 - Assigned to cloudpresser] Create a function getTypeAnnotationName(typeAnnotation) in the Parser base class. Implement it using [this code for Flow](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/flow/components/events.js#L211) and [this code for Typescript](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/events.js#L223). Replace the callsites with the new function.

This is part of https://github.com/facebook/react-native/issues/34872

bypass-github-export-checks

## Changelog:

[INTERNAL] [ADDED] - getTypeAnnotationName(typeAnnotation) in parser

Pull Request resolved: https://github.com/facebook/react-native/pull/37580

Test Plan: `yarn jest packages/react-native-codegen` > new tests written, as well as coverage from existing tests

Reviewed By: rshest

Differential Revision: D46439051

Pulled By: cipolleschi

fbshipit-source-id: c0ccddc11b56d77788b4957381fbbaa82d992b01
2023-08-04 03:01:57 -07:00
Denis 5eaf28b247 add emitUnionProp in parser primitives (#38705)
Summary:
[Codegen 131] This PR add a function `emitUnionProp` to the parser-primitives, as requested on https://github.com/facebook/react-native/issues/34872

## Changelog:

[INTERNAL] [ADDED] - Add `emitUnionProp` function to parser-primitives

Pull Request resolved: https://github.com/facebook/react-native/pull/38705

Test Plan: `yarn test react-native-codegen`

Reviewed By: christophpurrer

Differential Revision: D47921708

Pulled By: rshest

fbshipit-source-id: c2c081c6317928e5eb8b0c1d0640c7b7f40a4b0b
2023-08-01 01:43:31 -07:00
Siddarth Kumar 8bcfc493ea add getPaperTopLevelNameDeprecated to parsers (#38683)
Summary:
[Codegen 135] This PR introduces `getPaperTopLevelNameDeprecated` to parser base class and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872

## Changelog:

[Internal] [Changed] - Add `getPaperTopLevelNameDeprecated` to parser base class and update usages.

Pull Request resolved: https://github.com/facebook/react-native/pull/38683

Test Plan:
Run `yarn jest react-native-codegen` locally and ensure CI is green

## Screenshot of test passing locally:
<img width="1060" alt="Screenshot 2023-07-30 at 10 04 24 AM" src="https://github.com/facebook/react-native/assets/64726664/3f61377b-9f44-45e8-bece-d4fd6bcc4567">

Reviewed By: cipolleschi

Differential Revision: D47902816

Pulled By: rshest

fbshipit-source-id: 6fab53e02cfc3f0aaa3ffd795c3fe1d2f723e060
2023-07-31 07:52:19 -07:00
Denis 6d5be2630c refactor(codegen): add getLiteralValue in parser (#38651)
Summary:
[Codegen 130] This PR add a `getLiteralValue` function to the Parser interface, which returns the literal value of an union represented, given an option. as requested on https://github.com/facebook/react-native/issues/34872

## Changelog:

[INTERNAL] [ADDED] - Add `getLiteralValue` function to codegen Parser

Pull Request resolved: https://github.com/facebook/react-native/pull/38651

Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green

Reviewed By: cipolleschi

Differential Revision: D47912960

Pulled By: rshest

fbshipit-source-id: d9426fef4c0f92c5244d5c4c72202ec29099b76e
2023-07-31 04:56:25 -07:00
Roy Berger f396067cca Add module name constant to class for downstream use (#38295)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38295

Move constant to class instance so customers can use strongly typed name, feedback from D46159001

Changelog:
[Internal] [Changed] - Add module name constant to codegen'd class for downstream use

Reviewed By: christophpurrer

Differential Revision: D47095993

fbshipit-source-id: 741d0d837bf912d6b32e5f12c5df871563d46686
2023-07-11 13:03:17 -07:00
Arushi Kesarwani 2eb25cbdbe Update Node.js to v18 in all RN packages (#37791)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37791

## Bump minimum Node JS version to 18 via `react-native/package.json#engines`

In https://github.com/facebook/react-native/pull/35443 we bumped up the node version from 16 to 18.

Node 16 [ends maintenance releases on 2023-09-11](https://nodejs.org/en/blog/announcements/nodejs16-eol/), and bumping this minimum will allow other associated Node JS tools (CLI, Metro, Jest) to reduce their support burden.

This follows up by formally making Node 18 the minimum supported version.

**Docs PR:**
https://github.com/facebook/react-native-website/pull/3748

**Changelog:**
[General][Breaking] Bump minimum Node JS version to 18

Reviewed By: cortinico, NickGerleman

Differential Revision: D46583997

fbshipit-source-id: 1f31e2f205ac8b09494c2a7d3b73b9f36eff221b
2023-06-22 09:53:21 -07:00