Skip to content

Commit b037829

Browse files
j-piaseckimeta-codesync[bot]
authored andcommitted
Add Frameworks C++ API snapshots (#58836)
Summary: Pull Request resolved: #58836 Adds a `frameworks` variant to the `ReactCommon`, `ReactAndroid` and `ReactApple` C++ API views. API offered to frameworks gets its own snapshots: `ReactCommonFrameworksCxx.api`, `ReactAndroidFrameworksCxx.api` and `ReactAppleFrameworksCxx.api`. The variant uses each view's base definitions. To support this, a variant can now set `visibility`, overriding its view's. Changelog: [Internal] Reviewed By: coado Differential Revision: D123001823
1 parent 99d7141 commit b037829

7 files changed

Lines changed: 36278 additions & 3 deletions

File tree

‎scripts/cxx-api/README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ The pipeline produces one `.api` snapshot file per configured **API view × vari
1616
| `ReactAndroidReleaseCxx.api` | Android-specific C++ API (release) |
1717
| `ReactAppleDebugCxx.api` | Apple-specific C++/Obj-C API (debug) |
1818
| `ReactAppleReleaseCxx.api` | Apple-specific C++/Obj-C API (release) |
19+
| `ReactCommonFrameworksCxx.api` | Platform-independent C++ API, including for-frameworks symbols |
20+
| `ReactAndroidFrameworksCxx.api` | Android-specific C++ API, including for-frameworks symbols |
21+
| `ReactAppleFrameworksCxx.api` | Apple-specific C++/Obj-C API, including for-frameworks symbols |
1922

20-
For each view, debug and release variants are generated with different preprocessor definitions (e.g. `REACT_NATIVE_DEBUG` vs `NDEBUG`), since `#ifdef` guards in the source headers can produce a different public API surface per variant.
23+
For each view, debug and release variants are generated with different preprocessor definitions (e.g. `REACT_NATIVE_DEBUG` vs `NDEBUG`), since `#ifdef` guards in the source headers can produce a different public API surface per variant. The frameworks variant uses the view's base definitions and also includes symbols from "for frameworks" headers.
2124

2225
Snapshot files are committed to the repo under `scripts/cxx-api/api-snapshots/`.
2326

@@ -104,7 +107,7 @@ All API views and their variants are defined in `config.yml`. Each view specifie
104107
| `input_filter` | Whether to run Doxygen through the input filters in `parser/input_filters/` |
105108
| `visibility` | C++ stable API tiers to include (`public`, `frameworks`, `private`); defaults to `[public]`. See [Tier filtering](#tier-filtering) |
106109

107-
`exclude_patterns` and `exclude_symbols` can also be set at the top level, in which case they apply to every view. A top-level `visibility` applies to every view that does not set its own.
110+
`exclude_patterns` and `exclude_symbols` can also be set at the top level, in which case they apply to every view. A top-level `visibility` applies to every view that does not set its own, and a variant can set `visibility` to override its view's.
108111

109112
## Snapshot format
110113

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

Lines changed: 12317 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 14546 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 9371 additions & 0 deletions
Large diffs are not rendered by default.

‎scripts/cxx-api/config.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ platforms:
4545
newarch:
4646
definitions:
4747
RCT_REMOVE_LEGACY_ARCH: 1
48+
frameworks:
49+
visibility:
50+
- public
51+
- frameworks
4852
ReactAndroid:
4953
codegen:
5054
platform: android
@@ -78,6 +82,10 @@ platforms:
7882
newarch:
7983
definitions:
8084
RCT_REMOVE_LEGACY_ARCH: 1
85+
frameworks:
86+
visibility:
87+
- public
88+
- frameworks
8189
# ReactIOS?
8290
ReactApple:
8391
codegen:
@@ -118,3 +126,7 @@ platforms:
118126
newarch:
119127
definitions:
120128
RCT_REMOVE_LEGACY_ARCH: 1
129+
frameworks:
130+
visibility:
131+
- public
132+
- frameworks

‎scripts/cxx-api/parser/config.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ApiViewVariant:
2424

2525
name: str
2626
definitions: dict[str, str | int] = field(default_factory=dict)
27+
visibility: frozenset[Tier] = DEFAULT_TIERS
2728

2829

2930
@dataclass
@@ -116,6 +117,9 @@ def parse_config(
116117
ApiViewVariant(
117118
name=variant_name,
118119
definitions=variant_config.get("definitions") or {},
120+
visibility=_parse_visibility(
121+
variant_config.get("visibility"), visibility
122+
),
119123
)
120124
for variant_name, variant_config in raw_variants.items()
121125
]
@@ -146,7 +150,7 @@ def parse_config(
146150
codegen_platform=codegen_platform,
147151
input_filter=input_filter,
148152
exclude_symbols=exclude_symbols,
149-
visibility=visibility,
153+
visibility=variant.visibility,
150154
)
151155
)
152156

‎scripts/cxx-api/tests/test_config.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,28 @@ def test_visibility_propagated_to_variants(self):
668668
for r in result:
669669
self.assertEqual(r.visibility, frozenset({Tier.PUBLIC, Tier.PRIVATE}))
670670

671+
def test_variant_visibility_overrides_view(self):
672+
"""A variant's visibility replaces the view's for that variant only"""
673+
config = {
674+
"platforms": {
675+
"TestView": {
676+
"variants": {
677+
"debug": {},
678+
"frameworks": {"visibility": ["public", "frameworks"]},
679+
},
680+
}
681+
}
682+
}
683+
result = parse_config(config, "/base/dir")
684+
685+
debug = next(r for r in result if r.snapshot_name == "TestViewDebug")
686+
self.assertEqual(debug.visibility, frozenset({Tier.PUBLIC}))
687+
688+
frameworks = next(r for r in result if r.snapshot_name == "TestViewFrameworks")
689+
self.assertEqual(
690+
frameworks.visibility, frozenset({Tier.PUBLIC, Tier.FRAMEWORKS})
691+
)
692+
671693
def test_unknown_visibility_rejected(self):
672694
"""An unknown tier name in visibility raises"""
673695
config = {"platforms": {"TestView": {"visibility": ["internal"]}}}

0 commit comments

Comments
 (0)