Skip to content

Commit dee403e

Browse files
committed
fix swift compatibility and integrate with HelloWorld
1 parent 87a7cb3 commit dee403e

6 files changed

Lines changed: 481 additions & 153 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ vendor/
133133
# Swift Package build folder
134134
/packages/react-native/.build
135135
/packages/react-native/.swiftpm
136+
/packages/react-native/React/includes/
136137

137138
# @react-native/codegen
138139
/packages/react-native/React/FBReactNativeSpec/

packages/react-native/Package.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
*/
88

99
import PackageDescription
10+
import Foundation
11+
12+
let BUILD_FROM_SOURCE = false
1013

1114
/**
1215
This is the `Package.swift` file that allows to build React Native core using Swift PM.
@@ -352,6 +355,8 @@ let reactRuntimeApple = RNTarget(
352355
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .reactCxxReact, .rctDeprecation, .yoga, .reactRuntime, .reactRCTFabric, .reactCoreModules, .reactTurboModuleCore, .hermesPrebuilt, .reactUtils]
353356
)
354357

358+
let publicHeadersPathForReactCore: String = BUILD_FROM_SOURCE ? "includes" : "."
359+
355360
/// React-Core.podspec
356361
let reactCore = RNTarget(
357362
name: .reactCore,
@@ -364,7 +369,8 @@ let reactCore = RNTarget(
364369
linkedFrameworks: ["CoreServices"],
365370
excludedPaths: ["Fabric", "Tests", "Resources", "Runtime/RCTJscInstanceFactory.mm", "I18n/strings", "CxxBridge/JSCExecutorFactory.mm", "CoreModules"],
366371
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactPerfLogger, .jsi, .reactJsiExecutor, .reactUtils, .reactFeatureFlags, .reactRuntimeScheduler, .yoga, .reactJsInspector, .reactJsiTooling, .rctDeprecation, .reactCoreRCTWebsocket, .reactRCTImage, .reactTurboModuleCore, .reactRCTText, .reactRCTBlob, .reactRCTAnimation, .reactRCTNetwork, .reactFabric, .hermesPrebuilt],
367-
sources: [".", "Runtime/RCTHermesInstanceFactory.mm"]
372+
sources: [".", "Runtime/RCTHermesInstanceFactory.mm"],
373+
publicHeadersPath: publicHeadersPathForReactCore
368374
)
369375

370376
/// React-Fabric.podspec
@@ -758,8 +764,8 @@ extension String {
758764
static let reactJsInspector = "React-jsinspector"
759765
static let reactJsInspectorTracing = "React-jsinspectortracing"
760766
static let reactCxxReact = "React-cxxreact"
761-
static let reactCore = "React-Core"
762-
static let reactCoreRCTWebsocket = "React-Core/RCTWebSocket"
767+
static let reactCore = "React"
768+
static let reactCoreRCTWebsocket = "React/RCTWebSocket"
763769
static let reactFabric = "React-Fabric"
764770
static let reactRCTFabric = "React-RCTFabric"
765771

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
/**
12+
* Script to create symlinks for header files in React/includes/React
13+
*
14+
* This script:
15+
* 1. Scans the React and Libraries directories to build a map of header files
16+
* 2. Iterates over an array of headers
17+
* 3. Looks up each header in the map and creates a symlink in React/includes/React
18+
*/
19+
20+
// Import the headers array from headers.js
21+
const {HEADERS} = require('./headers');
22+
const fs = require('fs');
23+
const path = require('path');
24+
25+
// Define paths
26+
const ROOT_DIR = path.resolve(__dirname, '../../../..');
27+
const REACT_DIR = path.join(ROOT_DIR, 'packages/react-native/React');
28+
const LIBRARIES_DIR = path.join(ROOT_DIR, 'packages/react-native/Libraries');
29+
const DESTINATION_DIR = path.join(
30+
ROOT_DIR,
31+
'packages/react-native/React/includes/React',
32+
);
33+
34+
// Ensure destination directory exists
35+
if (!fs.existsSync(DESTINATION_DIR)) {
36+
console.log(`Creating directory: ${DESTINATION_DIR}`);
37+
fs.mkdirSync(DESTINATION_DIR, {recursive: true});
38+
}
39+
40+
console.log('Building header file map...');
41+
42+
// Function to recursively scan directories and build a map of header files
43+
function buildHeaderMap(directory) {
44+
const headerMap = new Map();
45+
46+
function scanDirectory(dir) {
47+
const entries = fs.readdirSync(dir, {withFileTypes: true});
48+
49+
for (const entry of entries) {
50+
const fullPath = path.join(dir, entry.name);
51+
52+
if (entry.isDirectory()) {
53+
scanDirectory(fullPath);
54+
} else if (entry.isFile() && entry.name.endsWith('.h')) {
55+
// Store by filename only, without any subpath
56+
headerMap.set(entry.name, fullPath);
57+
}
58+
}
59+
}
60+
61+
scanDirectory(directory);
62+
return headerMap;
63+
}
64+
65+
// Build a map of all header files in React and Libraries directories
66+
const reactHeaderMap = buildHeaderMap(REACT_DIR);
67+
const librariesHeaderMap = buildHeaderMap(LIBRARIES_DIR);
68+
69+
// Merge the two maps, with React headers taking precedence
70+
const headerMap = new Map([...librariesHeaderMap, ...reactHeaderMap]);
71+
72+
console.log(`Found ${headerMap.size} unique header files`);
73+
74+
// Counter for statistics
75+
let found = 0;
76+
let notFound = 0;
77+
let errors = 0;
78+
79+
// Arrays to collect headers that couldn't be found or had errors
80+
const notFoundHeaders = [];
81+
const errorHeaders = [];
82+
83+
// Process each header
84+
HEADERS.forEach(header => {
85+
try {
86+
// Extract just the filename for both search and target
87+
let targetFilename = header;
88+
89+
// Handle headers with path components
90+
if (header.includes('/')) {
91+
const parts = header.split('/');
92+
targetFilename = parts[parts.length - 1];
93+
}
94+
95+
// Look up the header in our map using just the filename
96+
const sourcePath = headerMap.get(targetFilename);
97+
98+
if (sourcePath) {
99+
const destPath = path.join(DESTINATION_DIR, targetFilename);
100+
101+
// Create symlink
102+
if (fs.existsSync(destPath)) {
103+
fs.unlinkSync(destPath);
104+
}
105+
106+
// Create relative symlink
107+
const relativeSourcePath = path.relative(DESTINATION_DIR, sourcePath);
108+
fs.symlinkSync(relativeSourcePath, destPath);
109+
110+
console.log(
111+
`Created symlink: ${targetFilename} -> ${relativeSourcePath}`,
112+
);
113+
found++;
114+
} else {
115+
console.warn(
116+
`Warning: Could not find header file: ${header} (filename: ${targetFilename})`,
117+
);
118+
notFoundHeaders.push({header, targetFilename});
119+
notFound++;
120+
}
121+
} catch (error) {
122+
console.error(`Error processing ${header}: ${error.message}`);
123+
errorHeaders.push({header, error: error.message});
124+
errors++;
125+
}
126+
});
127+
128+
console.log('\nSummary:');
129+
console.log(`- Found and linked: ${found} files`);
130+
console.log(`- Not found: ${notFound} files`);
131+
console.log(`- Errors: ${errors} files`);
132+
133+
if (notFound > 0) {
134+
console.log('\nHeaders that could not be found:');
135+
notFoundHeaders.forEach(({header, targetFilename}) => {
136+
console.log(` - ${header} (filename: ${targetFilename})`);
137+
});
138+
}
139+
140+
if (errors > 0) {
141+
console.log('\nHeaders that had errors:');
142+
errorHeaders.forEach(({header, error}) => {
143+
console.log(` - ${header}: ${error}`);
144+
});
145+
}
146+
147+
if (notFound > 0 || errors > 0) {
148+
console.log('\nSome headers could not be found or had errors.');
149+
process.exit(1);
150+
} else {
151+
console.log('\nAll headers were successfully linked.');
152+
}

0 commit comments

Comments
 (0)