|
| 1 | +# iOS Prebuild Scripts |
| 2 | + |
| 3 | +This directory contains scripts for prebuilding React Native itself into |
| 4 | +XCFrameworks for iOS and related platforms. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +These scripts automate the process of building React Native as a Swift Package |
| 9 | +and packaging it into XCFrameworks that can be distributed and consumed by iOS |
| 10 | +applications. The build process creates optimized frameworks for multiple |
| 11 | +architectures and platforms. |
| 12 | + |
| 13 | +## Purpose |
| 14 | + |
| 15 | +The prebuild scripts are used to: |
| 16 | + |
| 17 | +- Build React Native itself (not its dependencies) as XCFrameworks |
| 18 | +- Create distributable binaries for iOS, iOS Simulator, Catalyst. |
| 19 | +- Support both Debug and Release build configurations |
| 20 | +- Generate Debug Symbol (dSYM) files for debugging |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +Run the prebuild script from the command line: |
| 25 | + |
| 26 | +```bash |
| 27 | +cd packages/react-native |
| 28 | +node scripts/ios-prebuild |
| 29 | +``` |
| 30 | + |
| 31 | +If no options are passed, the script executes all the steps in this order: |
| 32 | + |
| 33 | +- setup the codebase for all platforms and flavors |
| 34 | +- build for all platforms and flavors |
| 35 | +- compose xcframeworks |
| 36 | +- sign (if an identity is passed) |
| 37 | + |
| 38 | +### Options |
| 39 | + |
| 40 | +| Option | Alias | Type | Default | Description | |
| 41 | +| ------------- | ----- | ------- | ------------------------------------------ | ------------------------------------------------------------------- | |
| 42 | +| `--setup` | `-s` | boolean | - | Download and setup dependencies | |
| 43 | +| `--build` | `-b` | boolean | - | Build dependencies/platforms | |
| 44 | +| `--compose` | `-c` | boolean | - | Compose XCFramework from built dependencies | |
| 45 | +| `--platforms` | `-p` | array | `['ios', 'ios-simulator', 'mac-catalyst']` | Specify one or more platforms to build for | |
| 46 | +| `--flavor` | `-f` | string | `Debug` | Specify the flavor to build: `Debug` or `Release` | |
| 47 | +| `--identity` | `-i` | string | - | Specify the code signing identity to use for signing the frameworks | |
| 48 | +| `--help` | - | boolean | - | Show help information | |
| 49 | + |
| 50 | +### Output Structure |
| 51 | + |
| 52 | +The build produces: |
| 53 | + |
| 54 | +- XCFrameworks in the specified output directory |
| 55 | +- Debug symbols (dSYM files) for debugging |
| 56 | +- Build products organized by platform and configuration |
| 57 | + |
| 58 | +## Architecture |
| 59 | + |
| 60 | +The build system consists of several components: |
| 61 | + |
| 62 | +### `cli.js` |
| 63 | + |
| 64 | +The main entry point that orchestrates the build process. It: |
| 65 | + |
| 66 | +- Parses command-line arguments |
| 67 | +- Validates build parameters |
| 68 | +- Coordinates the build, archiving, and XCFramework creation steps |
| 69 | + |
| 70 | +### `build.js` |
| 71 | + |
| 72 | +Handles the Swift Package build process. It: |
| 73 | + |
| 74 | +- Executes `xcodebuild` commands with appropriate flags |
| 75 | +- Builds for specific platforms and build types (Debug/Release) |
| 76 | +- Locates and validates the generated framework artifacts |
| 77 | +- Uses build settings like `BUILD_LIBRARY_FOR_DISTRIBUTION=YES` for binary |
| 78 | + compatibility |
| 79 | + |
| 80 | +### `types.js` |
| 81 | + |
| 82 | +Defines TypeScript/Flow type definitions for: |
| 83 | + |
| 84 | +- `BuildFlavor`: Debug or Release configurations |
| 85 | +- `Destination`: Target platforms (iOS, iOS Simulator, Catalyst, Vision, |
| 86 | + visionOS) |
| 87 | +- `ArchiveOptions`: Configuration options for the build process |
| 88 | + |
| 89 | +### `utils.js` |
| 90 | + |
| 91 | +Provides utility functions including: |
| 92 | + |
| 93 | +- Logging functionality with prefixed output |
| 94 | +- Common helper functions used across scripts |
| 95 | + |
| 96 | +## Build Flags |
| 97 | + |
| 98 | +The build process uses specific `xcodebuild` flags: |
| 99 | + |
| 100 | +- `BUILD_LIBRARY_FOR_DISTRIBUTION=YES`: Enables module stability |
| 101 | +- `SKIP_INSTALL=NO`: Ensures frameworks are properly installed |
| 102 | +- `DEBUG_INFORMATION_FORMAT="dwarf-with-dsym"`: Generates debug symbols |
| 103 | +- `OTHER_SWIFT_FLAGS="-no-verify-emitted-module-interface"`: Skips interface |
| 104 | + verification (useful for React Native modules due to the header structure not |
| 105 | + beeing modular) |
| 106 | + |
| 107 | +## Notes |
| 108 | + |
| 109 | +- These scripts build React Native itself, not third-party dependencies |
| 110 | +- The build process requires significant disk space for derived data |
| 111 | +- Build times vary depending on the target platform and configuration |
| 112 | +- XCFrameworks support multiple architectures in a single bundle |
| 113 | + |
| 114 | +## Known Issues |
| 115 | + |
| 116 | +The generated XCFrameworks currently use CocoaPods-style header structures |
| 117 | +rather than standard framework header conventions. This may cause modularity |
| 118 | +issues when: |
| 119 | + |
| 120 | +- Consuming the XCFrameworks in projects that expect standard framework headers |
| 121 | +- Building dependent frameworks that rely on proper module boundaries |
| 122 | +- Integrating with Swift Package Manager projects expecting modular headers |
| 123 | + |
| 124 | +## Integrating in your project with Cocoapods |
| 125 | + |
| 126 | +For consuming, debugging or troubleshooting when using Cocoapods scripts, you |
| 127 | +can use the following environment variables: |
| 128 | + |
| 129 | +- `RCT_USE_PREBUILT_RNCORE`: If set to 1, it will use the release tarball from |
| 130 | + Maven instead of building from source. |
| 131 | +- `RCT_TESTONLY_RNCORE_TARBALL_PATH`: **TEST ONLY** If set, it will use a local |
| 132 | + tarball of RNCore if it exists. |
| 133 | +- `RCT_TESTONLY_RNCORE_VERSION`: **TEST ONLY** If set, it will override the |
| 134 | + version of RNCore to be used. |
| 135 | +- `RCT_SYMBOLICATE_PREBUILT_FRAMEWORKS`: If set to 1, it will download the dSYMs |
| 136 | + for the prebuilt RNCore frameworks and install these in the framework folders |
0 commit comments