Skip to content

Commit 31844eb

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Leave private and frameworks headers out of the C++ API snapshots (#58837)
Summary: Pull Request resolved: #58837 The C++ API snapshots now cover only the public tier of the C++ stable API. Symbols declared in headers that include `PrivateGuard.h` or `FrameworksGuard.h` are left out, unless a public header reaches them directly or transitively, in which case they are public in practice. Unclassified headers are kept. In verbose mode the generator reports how many private or frameworks headers are kept that way. The snapshots are regenerated, and the README and snapshot docs describe the filtering. Changelog: [Internal] Reviewed By: coado Differential Revision: D123001770
1 parent bfd0b70 commit 31844eb

15 files changed

Lines changed: 1877 additions & 58708 deletions

‎scripts/cxx-api/README.md‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Python build pipeline for React Native's C++ (and Objective-C) API snapshots.
44

55
## Overview
66

7-
`scripts/cxx-api` generates human-readable snapshots of React Native's public C++ API surface. It uses [Doxygen](https://www.doxygen.nl/) to parse C/C++/Objective-C headers and a custom Python parser to produce a simplified, sorted representation of every public symbol.
7+
`scripts/cxx-api` generates human-readable snapshots of React Native's public C++ API surface. It uses [Doxygen](https://www.doxygen.nl/) to parse C/C++/Objective-C headers and a custom Python parser to produce a simplified, sorted representation of every public symbol. Symbols declared in headers that the C++ stable API classifies as private or "for frameworks" are left out (see [Tier filtering](#tier-filtering)).
88

99
The pipeline produces one `.api` snapshot file per configured **API view × variant** combination:
1010

@@ -41,17 +41,44 @@ python -m scripts.cxx-api.parser --validate
4141

4242
If any snapshot differs, a unified diff is printed and the process exits with a non-zero status. To fix a failing validation, regenerate the snapshots with `python -m scripts.cxx-api.parser` and commit the updated `.api` files.
4343

44+
#### Log tier boundary breaks
45+
46+
Pass `--log-boundary-breaks` (in either mode) to print every header whose includes cross a tier boundary, with the include chain that causes it:
47+
48+
```sh
49+
python -m scripts.cxx-api.parser --validate --log-boundary-breaks
50+
```
51+
4452
## How it works
4553

46-
The pipeline has two main stages:
54+
The pipeline has three main stages:
55+
56+
### 1. Tier classification
57+
58+
Every header in a view's inputs is classified by the C++ stable API guard it includes:
4759

48-
### 1. Doxygen XML generation
60+
| Guard | Tier |
61+
|---|---|
62+
| `react/cxxstableapi/UmbrellaGuard.h` | public |
63+
| `react/cxxstableapi/FrameworksGuard.h` | for frameworks |
64+
| `react/cxxstableapi/PrivateGuard.h` | private |
65+
| none | unclassified |
66+
67+
The headers' `#include`/`#import` directives are resolved into an include graph of the view.
68+
69+
### 2. Doxygen XML generation
4970

5071
Doxygen is configured via a generated config file (built from `.doxygen.config.template`) with the input directories, exclude patterns, and preprocessor definitions specified in `config.yml`. It outputs XML describing every symbol found in the headers.
5172

52-
### 2. Snapshot parsing
73+
### 3. Snapshot parsing
74+
75+
The Python parser (`parser/`) reads the Doxygen XML output and builds a scope tree of the public API surface, leaving out symbols declared in skipped headers. The tree is then serialized to a deterministically sorted, human-readable `.api` text format.
5376

54-
The Python parser (`parser/`) reads the Doxygen XML output and builds a scope tree of the public API surface. The tree is then serialized to a deterministically sorted, human-readable `.api` text format.
77+
## Tier filtering
78+
79+
A private or for-frameworks header is skipped unless a public header reaches it, directly or through other includes: anything a public header includes is public in practice, whatever its own guard says. Unclassified headers are never skipped.
80+
81+
A boundary break is a public header that reaches a for-frameworks or private header, or a for-frameworks header that reaches a private one. `--log-boundary-breaks` reports them at the edge where visibility drops.
5582

5683
## When to use it
5784

@@ -73,7 +100,10 @@ All API views and their variants are defined in `config.yml`. Each view specifie
73100
| `definitions` | Preprocessor macros to define |
74101
| `variants` | Named build variants (e.g. debug/release) with extra definitions |
75102
| `codegen` | Optional codegen platform (`android`, `ios`) to generate TurboModule/Component headers before scanning |
76-
| `private_directories` | Directories whose headers are scanned (they may be transitively included) but should not contribute public symbols. If any public API entity is defined in a private directory, a warning is printed to help catch accidental API exposure. |
103+
| `exclude_symbols` | Regex patterns for symbols to skip |
104+
| `input_filter` | Whether to run Doxygen through the input filters in `parser/input_filters/` |
105+
106+
`exclude_patterns` and `exclude_symbols` can also be set at the top level, in which case they apply to every view.
77107

78108
## Snapshot format
79109

‎scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api‎

Lines changed: 114 additions & 6655 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api‎

Lines changed: 132 additions & 6440 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api‎

Lines changed: 114 additions & 6653 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api‎

Lines changed: 195 additions & 6646 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api‎

Lines changed: 183 additions & 6465 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api‎

Lines changed: 192 additions & 6641 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactCommonDebugCxx.api‎

Lines changed: 205 additions & 6449 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactCommonNewarchCxx.api‎

Lines changed: 205 additions & 6280 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/api-snapshots/ReactCommonReleaseCxx.api‎

Lines changed: 205 additions & 6447 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)