|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +// ============================================================================= |
| 9 | +// Shared "public API" guard for React Native's C++ stable API. |
| 10 | +// |
| 11 | +// Include this header at the top of every *public* module header (right after |
| 12 | +// `#pragma once`): |
| 13 | +// |
| 14 | +// #include <react/cxxstableapi/UmbrellaGuard.h> |
| 15 | +// |
| 16 | +// The guard turns a *direct* include of a public module header into a hard |
| 17 | +// error, steering consumers to the module's umbrella header instead: |
| 18 | +// |
| 19 | +// #include <React/<Module>.h> // do this |
| 20 | +// |
| 21 | +// ----------------------------------------------------------------------------- |
| 22 | +// Macro contract (all `RN_*` macros are shared across modules) |
| 23 | +// |
| 24 | +// RN_STRICT_API Consumer opt-in master switch. Every guard in this |
| 25 | +// directory is INERT unless the consuming build defines |
| 26 | +// this macro. Shipping the guards therefore changes |
| 27 | +// nothing for existing consumers — they only activate |
| 28 | +// when a consumer opts into the strict public API by |
| 29 | +// defining RN_STRICT_API. |
| 30 | +// |
| 31 | +// RN_UMBRELLA_CONTEXT Internal marker (implementation detail; consumers never |
| 32 | +// set it). A module umbrella defines it around its own |
| 33 | +// `#include`s to signal the blessed inclusion path: |
| 34 | +// #define RN_UMBRELLA_CONTEXT |
| 35 | +// #include <react/.../PublicHeaderA.h> |
| 36 | +// #include <react/.../PublicHeaderB.h> |
| 37 | +// #undef RN_UMBRELLA_CONTEXT |
| 38 | +// The `#undef` matters: it keeps the marker scoped to the |
| 39 | +// umbrella's includes so later *direct* includes in the |
| 40 | +// same translation unit are still caught. |
| 41 | +// |
| 42 | +// RN_BUILDING Defined by React Native's own build targets so internal |
| 43 | +// sources may keep including the fine-grained headers |
| 44 | +// directly. |
| 45 | +// |
| 46 | +// This header is intentionally NOT `#pragma once`-guarded: it must be |
| 47 | +// re-evaluated on every inclusion so each direct include is checked. |
| 48 | +// ============================================================================= |
| 49 | + |
| 50 | +#if defined(RN_STRICT_API) && !defined(RN_UMBRELLA_CONTEXT) && !defined(RN_BUILDING) |
| 51 | +#error \ |
| 52 | + "Do not include this React Native header directly. Include the module's umbrella header <React/<Module>.h> instead." |
| 53 | +#endif |
0 commit comments