Skip to content

Commit 593ec79

Browse files
j-piaseckigabrieldonadel
authored andcommitted
Fix case-colliding React/ and react/ folders in the prebuilt iOS headers
The C++ module umbrellas (React/Debug.h, React/View.h and 15 others) shipped in ReactNativeHeaders next to the react/ folder. On a case-insensitive filesystem the two folders merge, so every #include <react/...> warns with -Wnonportable-include-path. On a case-sensitive filesystem these includes do not resolve. Ship the umbrellas in React.framework again and list them as `exclude header` in its module map. Including them from a react/ header then stays textual and does not close the React -> ReactNativeHeaders_react -> React module cycle. The Swift C++ interop gate in headers-verify now also searches React.framework, as every real consumer does. (cherry picked from commit ccde58c)
1 parent 4f7a94d commit 593ec79

6 files changed

Lines changed: 61 additions & 65 deletions

File tree

‎packages/react-native/scripts/ios-prebuild/__docs__/headers-rules.md‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,27 +234,28 @@ emitted as a one-line redirect shim (`#import <owner>`). Shims that are
234234
namespace-module members are fine: they import the owning module, so
235235
declarations stay single-owned.
236236

237-
**R12 — a namespace module's own umbrella stays in ReactNativeHeaders.** The C++
238-
stable API ships one umbrella per module, physically nested inside it
239-
(`ReactCommon/react/debug/React/Debug.h`), so its natural path is
240-
`React/Debug.h` and R1 would hoist it into the framework. It must not be:
241-
**ReactNativeHeaders is the lower layer** — `React.framework` imports it
242-
(`RCTCallInvoker.h` → `<ReactCommon/CallInvoker.h>`). A framework-owned umbrella
243-
makes every `#include <React/X.h>` inside a lowercase-namespace header an import
244-
of module `React`, closing a cycle:
237+
**R12 — a namespace module's own umbrella is an `exclude header` of module
238+
`React`.** The C++ stable API ships one umbrella per module, physically nested
239+
inside it (`ReactCommon/react/debug/React/Debug.h`), so its natural path is
240+
`React/Debug.h` and R1 hoists it into the framework. **ReactNativeHeaders is the
241+
lower layer** — `React.framework` imports it (`RCTCallInvoker.h` →
242+
`<ReactCommon/CallInvoker.h>`). A framework header that belongs to module
243+
`React` makes every `#include <React/X.h>` inside a lowercase-namespace header
244+
an import of module `React`, closing a cycle:
245245

246246
```text
247247
React -> ReactNativeHeaders_react -> React
248248
```
249249

250-
Found empirically: `react/timing/primitives.h` -> `<React/Debug.h>`. This is the
251-
same two-module-ownership failure as `UMBRELLA_CXX_GUARDED_EXCLUSIONS`
252-
(`RCTFrameTimingsObserver.h`, which reaches the same `primitives.h`), in the
253-
opposite direction. They are `objc-blocked` by construction (they re-export
254-
their module's C++ surface), so they were never R4 umbrella or R5 module
255-
members; `planFromInventory` fails closed if one ever becomes a modular
256-
candidate, since its R5 module would be named `React` and alias the framework
257-
module.
250+
Found empirically: `react/timing/primitives.h` -> `<React/Debug.h>`. The React
251+
module map therefore lists each of these umbrellas as `exclude header`, so it is
252+
included textually and creates no module edge. They cannot ship in
253+
ReactNativeHeaders instead: a `React/` dir next to `react/` in one `Headers/`
254+
root merges with it on a case-insensitive filesystem, and every `<react/...>`
255+
include then warns with `-Wnonportable-include-path` (or does not resolve on a
256+
case-sensitive one). `planFromInventory` fails closed if one ever becomes a
257+
modular candidate, since it would then join the umbrella and bring the cycle
258+
back.
258259

259260
## Stage 3 — Emission (headers-compose.js)
260261

‎packages/react-native/scripts/ios-prebuild/__tests__/framework-resources-test.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ describe('emitReactFrameworkHeaders resource landing (integration)', () => {
352352
react: [],
353353
umbrella: [],
354354
privateReactHeaders: {modular: [], textual: []},
355+
excludedReactHeaders: [],
355356
},
356357
rnRoot,
357358
);

‎packages/react-native/scripts/ios-prebuild/__tests__/headers-spec-test.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ describe('R11 redirect shims for dual-identity headers', () => {
370370
});
371371
});
372372

373-
describe('R12 namespace module umbrellas stay in ReactNativeHeaders', () => {
374-
test('a module-nested React/ umbrella is not hoisted into the framework', () => {
373+
describe('R12 namespace module umbrellas are excluded from the React module', () => {
374+
test('a module-nested React/ umbrella ships in the framework as `exclude header`', () => {
375375
const m = validManifest();
376376
m.headers.push(
377377
entry(
@@ -381,17 +381,17 @@ describe('R12 namespace module umbrellas stay in ReactNativeHeaders', () => {
381381
),
382382
);
383383
const plan = planFromInventoryForTest(m);
384-
// Lower layer: including it from a react/-namespace header cannot create a
385-
// React module edge (React -> ReactNativeHeaders_react -> React).
386384
expect(
387-
plan.reactNativeHeaders.find(e => e.naturalPath === 'React/Debug.h')
388-
?.relPath,
389-
).toBe('React/Debug.h');
385+
plan.react.find(e => e.naturalPath === 'React/Debug.h')?.relPath,
386+
).toBe('Debug.h');
390387
expect(
391-
plan.react.find(e => e.naturalPath === 'React/Debug.h'),
392-
).toBeUndefined();
388+
plan.reactNativeHeaders.some(e => e.relPath.startsWith('React/')),
389+
).toBe(false);
393390
expect(plan.umbrella).not.toContain('React/Debug.h');
394-
expect(Object.keys(plan.namespaceModules)).not.toContain('React');
391+
expect(plan.excludedReactHeaders).toEqual(['Debug.h']);
392+
expect(
393+
renderReactModuleMap(plan.privateReactHeaders, plan.excludedReactHeaders),
394+
).toContain(' exclude header "Debug.h"');
395395
});
396396

397397
test('genuine React.framework headers are still hoisted (R1)', () => {

‎packages/react-native/scripts/ios-prebuild/headers-compose.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function emitReactFrameworkHeaders(
211211
fs.mkdirSync(path.join(fwk, 'Modules'), {recursive: true});
212212
fs.writeFileSync(
213213
path.join(fwk, 'Modules', 'module.modulemap'),
214-
renderReactModuleMap(plan.privateReactHeaders),
214+
renderReactModuleMap(plan.privateReactHeaders, plan.excludedReactHeaders),
215215
);
216216
if (privacyManifest != null) {
217217
fs.writeFileSync(

‎packages/react-native/scripts/ios-prebuild/headers-spec.js‎

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,17 @@
7979
* module members are fine: they import the owning module, so declarations
8080
* stay single-owned.
8181
* R12. A namespace module's OWN umbrella (ReactCommon/<ns...>/React/<Name>.h,
82-
* natural path React/<Name>.h) ships in ReactNativeHeaders — it is NOT
83-
* hoisted into React.framework by R1. ReactNativeHeaders is the LOWER
84-
* layer (React.framework imports it: RCTCallInvoker.h pulls
82+
* natural path React/<Name>.h) is hoisted into React.framework by R1, but
83+
* declared `exclude header` in the React module map. ReactNativeHeaders
84+
* is the LOWER layer (React.framework imports it: RCTCallInvoker.h pulls
8585
* <ReactCommon/CallInvoker.h>), so a framework-owned umbrella turns every
8686
* `#include <React/X.h>` inside a lowercase-namespace header into an import
8787
* of module React and closes a cycle:
8888
* React -> ReactNativeHeaders_react -> React
89-
* Found empirically: react/timing/primitives.h -> <React/Debug.h>. Kept in
90-
* ReactNativeHeaders the same spelling still resolves — framework lookup
91-
* misses and clang falls back to the header search path — textually and
92-
* within one artifact, so no module edge is created. These umbrellas are
93-
* objc-blocked by construction (they re-export their module's C++
94-
* surface), so they were never R4 umbrella or R5 module members anyway.
89+
* Found empirically: react/timing/primitives.h -> <React/Debug.h>. An
90+
* excluded header is included textually, so no module edge is created.
91+
* It cannot ship in ReactNativeHeaders instead: a `React/` dir next to
92+
* `react/` merges with it on a case-insensitive filesystem.
9593
* R13. The C++ stable API guards (react/cxxstableapi/*Guard.h) are
9694
* `textual header` members of their R5 module, as is every R5 member that
9795
* reaches one through unguarded includes. A guard decides at each
@@ -139,6 +137,8 @@ export type HeadersSpecPlan = {
139137
namespaceUmbrellas: Array<{relPath: string, content: string}>,
140138
// R9: private headers added to the React module map (allowlist).
141139
privateReactHeaders: {modular: Array<string>, textual: Array<string>},
140+
// R12: React.framework headers declared `exclude header`.
141+
excludedReactHeaders: Array<string>,
142142
collisions: Array<string>,
143143
};
144144
*/
@@ -362,6 +362,7 @@ function planFromInventory(
362362
const react /*: Array<SpecEntry> */ = [];
363363
const reactNativeHeaders /*: Array<SpecEntry> */ = [];
364364
const umbrella /*: Array<string> */ = [];
365+
const excludedReactHeaders /*: Array<string> */ = [];
365366
const namespaceModules /*: {[string]: Array<string>} */ = {};
366367
const textualNamespaceHeaders /*: Array<string> */ = [];
367368
const guardedHeaders = stableApiGuardedHeaders(manifest);
@@ -374,13 +375,7 @@ function planFromInventory(
374375
let bucketKey;
375376
let entryList;
376377
let relPath;
377-
if (np.startsWith('React/') && NS_MODULE_UMBRELLA_RE.test(source)) {
378-
// R12: a namespace module's own umbrella stays in the LOWER layer, so
379-
// including it from that namespace cannot create a React module edge.
380-
relPath = np;
381-
bucketKey = `ReactNativeHeaders/${relPath}`;
382-
entryList = reactNativeHeaders;
383-
} else if (np.startsWith('React/')) {
378+
if (np.startsWith('React/')) {
384379
relPath = np.slice(6); // R1: hoist React/ to the framework Headers root
385380
bucketKey = `React.framework/${relPath}`;
386381
entryList = react;
@@ -405,13 +400,18 @@ function planFromInventory(
405400
seen.set(bucketKey, source);
406401
entryList.push({relPath, source, naturalPath: np});
407402

408-
// R4: React umbrella membership. Only headers the framework actually ships
409-
// (R12 umbrellas carry a React/ natural path but live in ReactNativeHeaders).
410-
if (
411-
entryList === react &&
412-
np.startsWith('React/') &&
413-
isUmbrellaSafe(h, root)
414-
) {
403+
if (np.startsWith('React/') && NS_MODULE_UMBRELLA_RE.test(source)) {
404+
// R12: fail closed, an umbrella member would bring the cycle back.
405+
if (isUmbrellaSafe(h, root)) {
406+
throw new Error(
407+
`R12: '${np}' is a modular candidate. As a React module member it ` +
408+
`would close the React -> ReactNativeHeaders_react -> React ` +
409+
`cycle. Keep it out of the modular surface.`,
410+
);
411+
}
412+
excludedReactHeaders.push(relPath);
413+
} else if (np.startsWith('React/') && isUmbrellaSafe(h, root)) {
414+
// R4: React umbrella membership.
415415
umbrella.push(np);
416416
}
417417
// R5: namespace modules (only for ReactNativeHeaders namespaces). Every
@@ -424,19 +424,6 @@ function planFromInventory(
424424
if (entryList === reactNativeHeaders) {
425425
const ns = np.split('/')[0];
426426
if (isUmbrellaSafe(h, root)) {
427-
// R12 assert: an R12-routed umbrella lands under the `React` namespace
428-
// here, and renderNamespaceModuleMap only renames the lowercase `react`
429-
// one — so its module would be named `React` and alias the framework
430-
// module, reintroducing the cycle R12 exists to break. These umbrellas
431-
// are objc-blocked today so they never reach this branch; fail closed
432-
// if that ever changes.
433-
if (ns === 'React') {
434-
throw new Error(
435-
`R12: '${np}' is a modular candidate in ReactNativeHeaders. Its ` +
436-
`namespace module would be named 'React' and alias the React ` +
437-
`framework module. Keep it out of the modular surface.`,
438-
);
439-
}
440427
// R5 exemption assert: a namespace whose name is not a valid module
441428
// identifier cannot get a module, so a modular-candidate header in it
442429
// would be silently non-modular — consumers importing it from a
@@ -463,6 +450,7 @@ function planFromInventory(
463450
}
464451

465452
umbrella.sort();
453+
excludedReactHeaders.sort();
466454
for (const ns of Object.keys(namespaceModules)) {
467455
namespaceModules[ns].sort();
468456
}
@@ -539,23 +527,27 @@ function planFromInventory(
539527
textualNamespaceHeaders,
540528
namespaceUmbrellas,
541529
privateReactHeaders: PRIVATE_REACT_HEADERS,
530+
excludedReactHeaders,
542531
collisions,
543532
};
544533
}
545534

546535
/**
547-
* Renders React.framework's module map (R4 + R9). The umbrella covers the
536+
* Renders React.framework's module map (R4 + R9 + R12). The umbrella covers the
548537
* public modular surface; the allowlisted private headers (R9) are appended as
549538
* explicit `header` (modular) / `textual header` (objc-blocked) entries so
550539
* `#import <React/...>` of them stays modular without polluting the umbrella.
540+
* The R12 umbrellas are appended as `exclude header` entries.
551541
*/
552542
function renderReactModuleMap(
553543
privateReactHeaders /*:: ?: {modular: Array<string>, textual: Array<string>} */,
544+
excludedReactHeaders /*: ReadonlyArray<string> */ = [],
554545
) /*: string */ {
555546
const pv = privateReactHeaders ?? {modular: [], textual: []};
556547
const extra = [
557548
...pv.modular.map(h => ` header "${h}"`),
558549
...pv.textual.map(h => ` textual header "${h}"`),
550+
...excludedReactHeaders.map(h => ` exclude header "${h}"`),
559551
];
560552
const extraBlock = extra.length > 0 ? '\n' + extra.join('\n') : '';
561553
return `framework module React {

‎packages/react-native/scripts/ios-prebuild/headers-verify.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function verifyStructural(
211211
const fwk = path.join(reactSlice, 'React.framework');
212212
assertFileEquals(
213213
path.join(fwk, 'Modules', 'module.modulemap'),
214-
renderReactModuleMap(plan.privateReactHeaders),
214+
renderReactModuleMap(plan.privateReactHeaders, plan.excludedReactHeaders),
215215
'React module map',
216216
);
217217
assertFileEquals(
@@ -593,6 +593,8 @@ function runCompileGates(
593593
SIM_TARGET,
594594
'-module-cache-path',
595595
path.join(tmp, 'mc-swift-cxx-interop-probe'),
596+
'-F',
597+
reactSlice,
596598
'-I',
597599
cxxInteropProbeHeaders,
598600
'-I',

0 commit comments

Comments
 (0)