Commit Graph

935 Commits

Author SHA1 Message Date
Gijs Weterings 237ddb4dbf Fix Circle CI builds due to incorrect UnsupportedEnumDeclarationParserError import
Summary:
Changelog: [Internal]

The import style used
```
npm ERR! /home/circleci/react-native/packages/react-native-codegen/lib/parsers/typescript/modules/index.js:13
npm ERR! import {UnsupportedEnumDeclarationParserError} from '../../errors';
npm ERR! ^^^^^^
npm ERR!
npm ERR! SyntaxError: Cannot use import statement outside a module
npm ERR!     at internalCompileFunction (node:internal/vm:73:18)
npm ERR!     at wrapSafe (node:internal/modules/cjs/loader:1175:20)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1219:27)
npm ERR!     at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:1113:32)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:960:12)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1137:19)
npm ERR!     at require (node:internal/modules/helpers:121:18)
npm ERR!     at Object.<anonymous> (/home/circleci/react-native/packages/react-native-codegen/lib/parsers/typescript/parser.js:60:19)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1255:14)
```
is not supported.

Reviewed By: philIip

Differential Revision: D56809538

fbshipit-source-id: 4b42f9e964d49c4fe3c3a4020eb2b3860fdd810c
2024-05-01 03:16:15 -07:00
Christoph Purrer 536edf3726 Don't support float enums
Summary:
Changelog: [General][BREAKING] Don't support 'float' enums in Turbo Modules

- The current implementation of 'float enums' in C++ does not work as invalid results are returned.
- At potential fix could still cause rounding errors when crossing language bounaries, e.g. `4.6` can become `4.5599999942..`
- C++ enum classes don't support float: https://eel.is/c++draft/dcl.enum#2.sentence-4

> The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored.

Hence removing the feature of `float enums` for now

Reviewed By: NickGerleman

Differential Revision: D52120405

fbshipit-source-id: 3685ad0629e16ff9db424ba67e07d09df6027553
2024-04-30 21:52:09 -07:00
Alan Lee 639d890dff add missing struct member initialization in Props.h (#44294)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44294

**Problem:**

It was discovered while testing 3 party library, generated member variables in a C++ `struct` in `Props.h` is not initialized.
Also `WithDefault` would not work as well.
(For the problematic case it was a `boolean` but would also apply to other primitive types.)

If there is no default initialization and the component prop is optional and the user of the native component does not set the prop then the variable is never initialized and this is problematic for primitive types in C++ where no initialization results in an undefined behavior.

**Proposed solution:**

(Following C++Core Guideline of [always initialize](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-always).)
Reusing `generatePropsString()` used by `ClassTemplate` to generate props for `StructTemplate` as well.
updated relevant test snapshots.
This change is only concerning the `Props.h` file.

**Changelog:**
[General][Fixed] - fixed `Props.h` created from codegen missing default initializers in C++ `struct`

Reviewed By: cipolleschi

Differential Revision: D56659457

fbshipit-source-id: 0d21ad20c0491a7e8bb718cd3156da65def72f23
2024-04-30 18:29:31 -07:00
Christoph Purrer c96c893374 Support emitting typed RCTDeviceEmitter events
Summary:
This enables to code-gen base C++ types for custom exported JS types from a RN TM spec - which have been previously excluded from code-gen as these aren't used in any function.

The only work around so far was to ‘register’ a random function using the custom type which should be used for RCTDeviceEventEmitter events

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D56685903

fbshipit-source-id: add9ca40018b91c9fca98609ba3d1f85d3affec1
2024-04-30 11:16:57 -07:00
Sam Zhou 41f525ccae Pre-suppress unsafe string key access errors in xplat/js (#44221)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44221

This diff pre-suppresses errors of the following pattern, to prepare for the next Flow release.

```
declare const obj: {foo: string};
declare const key: string;
obj[key]; // error: invalid-computed-prop
```

Changelog: [Internal]

Reviewed By: alexmckenley

Differential Revision: D56477899

fbshipit-source-id: 5676b8685bd3157a519fe433cfce0fa28e003502
2024-04-23 11:36:14 -07:00
Nizam 99f3c241ad fix array enum prop parsing for array enum types (#44123)
Summary:
codegen generates type alias for  array enum props with uint32_t which cause wrong overloaded fromRawValue to call at runtime eventually app to terminate
more detailed info at issue https://github.com/facebook/react-native/issues/43821

## Changelog:

[Internal] [Fixed] - Codegen for array enum props

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

Test Plan: TODO

Reviewed By: cipolleschi

Differential Revision: D56414554

Pulled By: dmytrorykun

fbshipit-source-id: 0ec1b65951bc16ff58dd2b119c97a4e3fac2b161
2024-04-22 10:55:36 -07:00
Blake Friedman e0799536ef Fix: OSS builds can accidentally using coreutils cp (#44097)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44097

There are two places where we use a feature specific to the system version of 'cp', the:

  -X    Do not copy Extended Attributes (EAs) or resource forks.

This feature isn't available in GNU's cp, which is commonly installed on macOS using:

  brew install coreutils && brew link coreutils

We can avoid the problem alltogether by being specific about the path of the system cp.

Changelog: [General][Fixed] don't break script phase and codegen when coreutils installed on macOS

Reviewed By: cipolleschi

Differential Revision: D56143216

fbshipit-source-id: f1c1ef9ea2f01614d6d89c4e9eedf43113deb80c
2024-04-17 08:08:50 -07:00
Riccardo Cipolleschi 46b6453eb6 Fix the Redefinition of 'NativeXXXSpecJSI' error with Frameworks (#44005)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44005

When using frameworks on iOS, there is a possibility that modules import the Spec.h file twice and this might end up in a Redefinition of some symbols and duplication of symbols which ends up in build errors, as reported here: https://github.com/facebook/react-native/issues/42670.

This change adds some [`#include guards`](https://en.wikipedia.org/wiki/Include_guard) in codegen to avoid the redefinition of those symbols if the header is imported/included multiple times.

Note: I also experimented with `#pragma once`, but it looks like Apple is not happy with that directive. [It seems](https://forums.developer.apple.com/forums/thread/739964) that it started working flakely from Xcode 15.

## Changelog:
[General][Fixed] - Make sure that we can't include Codegen symbols multiple times

Reviewed By: cortinico

Differential Revision: D55925605

fbshipit-source-id: 15ca076aace2ffbd03ab8fa8a68a3d8ce0d1ea65
2024-04-11 11:39:43 -07:00
Christoph Purrer 04bf8cfb23 Clean up old Cxx TM member generation (#43710)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43710

As we had already cut a branch for RN 0.74
https://github.com/facebook/react-native/releases/tag/v0.74.0-rc.1

We can delete this code already

Changelog: [Internal]

Reviewed By: shwanton

Differential Revision: D55511382

fbshipit-source-id: 3ef15af338b5ad31b02e0a1eed7ac873566d9562
2024-03-29 14:39:24 -07:00
Pieter De Baets 6014dce04c Revert D54630694: Fix duplication across and rncore and FBReactNativeComponentSpec
Differential Revision:
D54630694

Original commit changeset: 75cb961ded9f

Original Phabricator Diff: D54630694

fbshipit-source-id: 50832c934e5bcc1a92456d949995c05a33767a92
2024-03-18 10:38:35 -07:00
Blake Friedman a380ea55fb Summary: minor fix found in nightly logs from Publish NPM job (#43519)
Summary:
Minor fix to package.json which newer version of npm warn about when publishing, after running `npm pkg fix -ws` on the workspace.

{F1470070110}

## Changelog: [Internal] npm pkg fix -ws

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

Test Plan: eyescloseddog

Reviewed By: cortinico

Differential Revision: D55012872

Pulled By: blakef

fbshipit-source-id: ff3c63a3eefaf56d369219a3d4b32d44d6d842c9
2024-03-18 08:29:10 -07:00
Pieter De Baets ef77087293 Fix duplication across and rncore and FBReactNativeComponentSpec (#43385)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43385

`rncore` and `FBReactNativeComponentSpec` contain the same symbols, which leads to conflicts when we try to merge them into a single shared library. Cleanup the duplication and standardize on `FBReactNativeComponentSpec` everywhere. I've left the Android OSS targets as is, to avoid breaking deps.

Changelog: [Internal]

Reviewed By: cortinico, dmytrorykun

Differential Revision: D54630694

fbshipit-source-id: 75cb961ded9fd75508755c0530e29409fef801cf
2024-03-18 07:30:33 -07:00
Sam Zhou 923d4abd7b Update hermes-parser and related packages in fbsource to 0.20.1 (#43317)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43317

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

Changelog: [internal]

Reviewed By: pieterv

Differential Revision: D54510131

fbshipit-source-id: 064d2078e85e465552dccf5c1368e49707c3aeef
2024-03-04 17:10:51 -08:00
Alex Hunt f57be12977 Bump packages for next major release (#43132)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43132

Command run:

```
node scripts/releases/set-version 0.75.0-main --skip-react-native-version
```

Changelog: [Internal]

Reviewed By: lunaleaps, cipolleschi

Differential Revision: D54006327

fbshipit-source-id: 7afe9e7ca3020faf399fdba2221fab8a102c56c7
2024-03-04 07:54:37 -08:00
Sam Zhou 2053364e5a Update hermes-parser and related packages in fbsource to 0.20.0
Summary:
Bump hermes-parser and related packages to [0.20.0](https://github.com/facebook/hermes/blob/main/tools/hermes-parser/js/CHANGELOG.md).

Changelog: [internal]

Reviewed By: alexmckenley

Differential Revision: D54368487

fbshipit-source-id: a5a05f1e499ff5d8bda4649433bd285f7215d3da
2024-02-29 14:19:29 -08:00
Rubén Norte 67b9628af5 Modify native module codegen to throw JS errors when passing null values for non-nullable arguments
Summary:
Changelog: [General][Breaking] Native modules using the codegen now throw an error when called with `null` for optional but not nullable arguments.

## Context

Right now, if you have a native module using the codegen with a method like this:

```
someMethod(value?: number): void;
```

And you call it like this:

```
NativeModule.someMethod(null);
```

The app doesn't throw an error, but it should because this method shouldn't accept `null` according to its type definition.

## Changes

This modifies the codegen to only check for `undefined` in those cases, otherwise trying to cast the value to the expected type and failing if it's `null`.

NOTE: this is technically a breaking change, but if people are using Flow or TypeScript in their projects they're very unlikely to hit this case, because they would've complained if you tried to pass `null` in these cases.

Reviewed By: cipolleschi

Differential Revision: D54206289

fbshipit-source-id: 58f2f2f3009d203b96189d3c66d1ae98a9e4fb36
2024-02-29 13:12:49 -08:00
Nicola Corti 4d982dcdae Undo moving of TurboModule to internal and expose utility function for TurboModule.class.isAssignableFrom (#43219)
Summary:
After discussing with mdvacca, we prefer to undo the change of `TurboModule` package to `.internal` as this is a quite aggressive breaking change for the ecosystem.

Moreover: users should not invoke `TurboModule.class.isAssignableFrom` because `TurboModule` is `.internal`. Therefore I'm exposing another API to check if a class is a TurboModule as a static field of `ReactModuleInfo`.

## Changelog:

[INTERNAL] - Do not use TurboModule.class.isAssignableFrom

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

Test Plan: Tests are attached

Reviewed By: mdvacca, cipolleschi

Differential Revision: D54280882

Pulled By: cortinico

fbshipit-source-id: 9443c8aa23cf70dd5cfe574fe573d83313134358
2024-02-29 10:23:09 -08:00
Rubén Norte 179b684e76 Modify native module codegen to throw JS errors instead of crashing when not passing required parameters
Summary:
Changelog: [General][Fixed] Fixed crash when passing fewer arguments than expected in native modules using codegen

## Context

Right now, if you have a native module using the codegen with a method like this:

```
someMethod(value: number): void;
```

And you call it like this:

```
NativeModule.someMethod();
```

The app crashes.

This happens because the codegen tries to cast the value to the expected type without checking if the argument is within the bounds of the arguments array.

## Changes

This fixes that issue with a change in the codegen to guard against this in the generated code (see changes in the snapshot tests).

Reviewed By: RSNara

Differential Revision: D54206287

fbshipit-source-id: 575af462725515928f8634fccc7a9cb51ca0ce4f
2024-02-27 09:29:53 -08:00
Rubén Norte abbc6eb022 Modify codegen to throw JS errors instead of crashing when passing non-number arguments where RootTags are expected
Summary:
Changelog: [General][Fixed] Fixed crash when passing non-numeric values where RootTag is expected to methods in native modules using codegen

## Context

Right now, if you have a native module using the codegen with a method like this:

```
someMethod(value: RootTag): void;
```

And you call it like this:

```
NativeModule.someMethod('');
```

The app crashes.

This happens because we cast the JS value to a C++ value using the method that asserts (`toNumber`) instead of the one that throws a JS error (`asNumber`).

## Changes

This fixes the crash by using `asNumber` instead of `toNumber`.

Reviewed By: RSNara

Differential Revision: D54206288

fbshipit-source-id: 9398112667e0f26edaf4f8f3b32e79fa8aafde62
2024-02-27 09:29:53 -08:00
Alex Taylor (alta) b857a6eb54 Update hermes-parser and related packages in fbsource to 0.19.2 (#43140)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43140

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

Changelog: [internal]

Reviewed By: pieterv

Differential Revision: D54044847

fbshipit-source-id: ce6830c6cdae8f9cb7225a86c0a1ff23a6929796
2024-02-22 08:56:32 -08:00
Nicola Corti 1e49f93b19 Fix autolinking for local app Fabric components
Summary:
Autolinking local app fabric component requires user to manipulate the C++ code.
This removes this requirement by generating the code necessary to register all the discovered Fabric Components.

I've updated the RN-Tester Android setup to use this mechanism also.

Changelog:
[Android] [Fixed] - Fix autolinking for local app Fabric components

Reviewed By: cipolleschi

Differential Revision: D53710676

fbshipit-source-id: 667af4bcf7fa99563081330aa64d072faf50863b
2024-02-13 11:29:13 -08:00
Nicola Corti b366b4b42e Back out "Fix autolinking for local app Fabric components"
Summary:
Original commit changeset: 28c376fbd08c

Original Phabricator Diff: D53661231

Reviewed By: cipolleschi

Differential Revision: D53709386

fbshipit-source-id: aab2d99327460cc82591f7de5e6e0296f7695cd6
2024-02-13 07:27:54 -08:00
Nicola Corti f9a5b30e5a Fix autolinking for local app Fabric components (#42962)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42962

Autolinking local app fabric component requires user to manipulate the C++ code.
This removes this requirement by generating the code necessary to register all the discovered Fabric Components.

I've updated the RN-Tester Android setup to use this mechanism also.

Changelog:
[Android] [Fixed] - Fix autolinking for local app Fabric components

Reviewed By: RSNara

Differential Revision: D53661231

fbshipit-source-id: 28c376fbd08c326f117f8d420485d63e2b4b1241
2024-02-13 05:29:24 -08:00
Dmitry Rykun 6974697b04 Use paperTopLevelNameDeprecated in generated EventEmitters if defined (#42812)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42812

There is a way of defining events where you specify additional string type parameter in the EventHandler in the spec. This additional type parameter is an overridden top level event name, that can be completely unrelated to the event handler name.
More context here D16042065.

Let's say we have
```
onLegacyStyleEvent?: ?BubblingEventHandler<LegacyStyleEvent, 'alternativeLegacyName'>
```
This will produce the following entry in the view config:
```
topAlternativeLegacyName: {
  phasedRegistrationNames: {
    captured: 'onLegacyStyleEventCapture',
    bubbled: 'onLegacyStyleEvent'
  }
}
```
This means that React expects `topAlternativeLegacyName`.
But the generated EventEmitter looks like this:
```
void RNTMyNativeViewEventEmitter::onLegacyStyleEvent(OnLegacyStyleEvent $event) const {
  dispatchEvent("legacyStyleEvent", [$event=std::move($event)](jsi::Runtime &runtime) {
    auto $payload = jsi::Object(runtime);
    $payload.setProperty(runtime, "string", $event.string);
    return $payload;
  });
}
```
The native component will emit `legacyStyleEvent` (`topLegacyStyleEvent` after normalization) that React will not be able to handle.

This issue only happens on iOS because Android doesn't use EventEmitter currently.

To address this issue we'll use `paperTopLevelNameDeprecated` for the generated EventEmitters if it is defined.

Changelog: [iOS][Fixed] - Fixed support for event name override in component specs.

Reviewed By: cortinico, mdvacca, cipolleschi

Differential Revision: D53310654

fbshipit-source-id: 018d5b11d8d36e2ecf900b9d8d6fe3e2ed71f80b
2024-02-13 04:31:25 -08:00
Ramanpreet Nara 3582f43440 Fix relative includes in component codegen (#42956)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42956

In the component codegen system, when the header prefix is an empty string, we generate includes using angle brackets, like this:

```
#include <EventEmitter.h>
```

This fails to compile in buck.

If we instead generate includes using quotations, buck compiles again.
```
#include "EventEmitter.h"
```

So, changes: if the headerPrefix is an empty string, generate includes using quotes.

This is a followup to D51811596.

Changelog: [Internal]

Reviewed By: fkgozali, dmytrorykun

Differential Revision: D53487111

fbshipit-source-id: e90a8b9fd4f8a2a93a0f4ad0ed989af26ad122c5
2024-02-10 14:32:13 -08:00
Alex Taylor (alta) e37da1e71a Update hermes-parser and related packages in fbsource to 0.19.1 (#42901)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42901

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

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D53485553

fbshipit-source-id: 9ecc0cd30606462bcbd29a7a75daccda8d442dd6
2024-02-07 12:47:15 -08:00
Oskar Kwaśniewski 1ce7bfd8c9 fix(Codegen): case where no platform or deployment_target is specified (#42867)
Summary:
This PR fixes a specific case pointed out by dmytrorykun, where there might be no platform or `deployment_target` specified at all and in that case we assume that this library supports every platform (same as Cocoapods).

## Changelog:

[IOS] [FIXED] - Don't add compiler conditionals when no platforms are specified

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

Test Plan:
Test running codegen when library doesn't specify a `platform`:

```
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name            = 'OSSLibraryExample'
  s.version         = package['version']
  s.summary         = package['description']
  s.description     = package['description']
  s.homepage        = package['homepage']
  s.license         = package['license']
  s.author          = 'Meta Platforms, Inc. and its affiliates'
  s.source          = { :git => package['repository'], :tag => '#{s.version}' }

  s.source_files = 'ios/**/*.{h,m,mm,cpp}'

  install_modules_dependencies(s)
end
```

Check generated `RCTThirdPartyFabricComponentsProvider`

Reviewed By: cortinico

Differential Revision: D53405625

Pulled By: dmytrorykun

fbshipit-source-id: 0f6917c56b84f0fa29807f516acdbd8d15aa5b46
2024-02-05 05:30:38 -08:00
Alex Taylor (alta) 64debd9a96 Update hermes-parser and related packages in xplat to 0.19.0 (#42824)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42824

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

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D53359412

fbshipit-source-id: e77c798232006eecb13611fbf01a4cb6d56cc310
2024-02-02 15:02:46 -08:00
Pieter De Baets 069c244d48 Revert D53330004: Update hermes-parser and related packages in fbsource to 0.19.0
Differential Revision:
D53330004

Original commit changeset: c20ef324ac2a

Original Phabricator Diff: D53330004

fbshipit-source-id: 4953b2ff66fd3d8ad31dae7fa4c72e92ebef6a8c
2024-02-02 05:53:06 -08:00
Alex Taylor (alta) 12155c464c Update hermes-parser and related packages in fbsource to 0.19.0 (#42798)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42798

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

Changelog: [internal]

Reviewed By: mvitousek, SamChou19815

Differential Revision: D53330004

fbshipit-source-id: c20ef324ac2a295c3f42fa6bbe1dbbf816146ccb
2024-02-01 19:11:47 -08:00
Dmitry Rykun b32c6c2cc1 Event name normalization (#42586)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42586

Every event name must be normalized.

The normalization strategy is:
1. If it starts with `top` -> do nothing.
2. If it starts with `on` -> replace `on` with `top`.
3. Else -> capitalize the first character and prepend `top`.

We have it for the old renderer on iOS [here](https://github.com/facebook/react-native/blob/a7586947d719a9cd2344ad346d271e7ca900de87/packages/react-native/React/Base/RCTEventDispatcher.m#L12-L21). This one is also used by the interop layer.
Static ViewConfigs being a part of the new renderer [replicate](https://github.com/facebook/react-native/blob/a7586947d719a9cd2344ad346d271e7ca900de87/packages/react-native-codegen/src/generators/components/GenerateViewConfigJs.js#L164-L172) this behavior to match the old rendered.

The Android that we have is incomplete, it is missing the [*2. If it starts with `on` -> replace `on` with `top`*]. This means that some events names that worked with the old renderer would not be compatible with the new renderer + Static ViewConfigs. Specifically every event names that start with `on`.

This diff implements event name normalization on Android.

Changelog: [Internal] - Update event normalization algorithm to match SVCs.

Reviewed By: cortinico

Differential Revision: D50604571

fbshipit-source-id: cef34d8baa2cf31f641be423a16bca7ea9fa20c4
2024-01-29 07:01:26 -08:00
Oskar Kwaśniewski ebb2b9c3fc feat: make codegen take OOT Apple platforms into account (#42047)
Summary:
### The problem

1. We have a library that's supported on iOS but doesn't have support for visionOS.
2. We run pod install
3. Codegen runs and generates Code for this library and tries to reference library class in `RCTThirdPartyFabricComponentsProvider`
4. Example:

```objc
Class<RCTComponentViewProtocol> RNCSafeAreaProviderCls(void) __attribute__((used)); // 0
```

This is an issue because the library files are not linked for visionOS platform (because code is linked only for iOS due to pod supporting only iOS).

### Solution

Make codegen take Apple OOT platforms into account by adding compiler macros if the given platform doesn't explicitly support this platform in the native package's podspec file.

Example generated output for library supporting only `ios` and `visionos` in podspec:

![CleanShot 2023-12-22 at 15 48 22@2x](https://github.com/facebook/react-native/assets/52801365/0cdfe7f5-441d-4466-8713-5f65feef26e7)

I used compiler conditionals because not every platform works the same, and if in the future let's say react-native-visionos were merged upstream compiler conditionals would still work.

Also tvOS uses Xcode targets to differentiate which platform it builds so conditionally adding things to the generated file wouldn't work.

## Changelog:

[IOS] [ADDED] - make codegen take OOT Apple platforms into account

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

Test Plan:
1. Generate a sample app with a template
5. Add third-party library (In my case it was https://github.com/callstack/react-native-slider)
6. Check if generated codegen code includes compiler macros

Reviewed By: cipolleschi

Differential Revision: D52656076

Pulled By: dmytrorykun

fbshipit-source-id: c827f358997c70a3c49f80c55915c28bdab9b97f
2024-01-23 06:53:57 -08:00
Eric Rozell 1d89fad824 Ignore TM specs with out-of-tree platform suffix (#42360)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42360

In cases where you merge out-of-tree platforms like react-native-windows with react-native mobile JS files, codegen awareness of the Windows suffix is useful. This helps prevent the creation of generated code for iOS and Android in mixed out-of-tree platform folders.

## Changelog

[Internal]

Reviewed By: mdvacca

Differential Revision: D52873212

fbshipit-source-id: ad6b1471e63d68057f54c79141123fb15f8aab5e
2024-01-18 22:52:24 -08:00
Riccardo Cipolleschi 3690e4413b Restore RCT_NEW_ARCH_ENABLED semantics for backward compatibility (#42259)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42259

At the end of last year, we reduce build fragmentation in iOS making sure that we were always building both architecture.
In the process, we break the semantic od RCt_NEW_ARCH_ENABLED flag, making several libs stop working in one of the two archs.

This change should restore the semantic, so libraries that were using RCT_NEW_ARCH_ENABLED to run conditional code will still work in the same way. While doing so, I also removed the new USE_NEW_ARCH as we don't want unnecessary flags

## CHANGELOG:
[iOS][Fixed] - Bring the old RCT_NEW_ARCH_ENABLED semantic back for compatibility

Reviewed By: cortinico

Differential Revision: D52727792

fbshipit-source-id: e211b10e7885eada83dd2886375575133ca76c8c
2024-01-12 08:10:35 -08:00
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