Add function to package the xcframework (#49434)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49434

This change adds a function to create the xcframework sarting from the various .framework's slice built before.

## Changelog:
[Internal] - Add function to create the xcframework

Reviewed By: cortinico

Differential Revision: D69660662

fbshipit-source-id: f58034c75cce3d242910d0ec1512be28059771ca
This commit is contained in:
Riccardo Cipolleschi
2025-02-14 10:20:10 -08:00
committed by Facebook GitHub Bot
parent f05ebd5d9d
commit 69a4d32028
2 changed files with 34 additions and 5 deletions
+2 -1
View File
@@ -145,7 +145,8 @@ vendor/
/packages/react-native/third-party/glog
/packages/react-native/third-party/.swiftpm
/packages/react-native/third-party/.build
.patch
fix_*.patch
*.xcframework
# Visual Studio Code (config dir - if present, this merges user defined
# workspace settings on top of react-native.code-workspace)
+32 -4
View File
@@ -226,21 +226,49 @@ async function copyHeadersToFrameworks(
});
}
function composeXCFrameworks(
thirdPartyFolder /*: string */,
buildDestinationPath /*: string */,
) {
console.log('Composing XCFrameworks...');
const frameworksFolder = path.join(buildDestinationPath, 'Build', 'Products');
const frameworks = fs.readdirSync(frameworksFolder);
const frameworkPaths = frameworks.map(framework =>
path.join(
frameworksFolder,
framework,
'PackageFrameworks',
'ReactNativeDependencies.framework',
),
);
const frameworksArgs = frameworkPaths
.map(framework => `-framework ${framework}`)
.join(' ');
const command = `xcodebuild -create-xcframework ${frameworksArgs} -output ${path.join(thirdPartyFolder, 'ReactNativeDependencies.xcframework')}`;
execSync(command, {stdio: 'inherit'});
}
async function main() {
console.log('Starting iOS prebuilds preparation...');
const swiftPMFolder = path.join(process.cwd(), THIRD_PARTY_PATH);
const buildDestinationPath = path.join(swiftPMFolder, BUILD_DESTINATION);
const thirdPartyFolder = path.join(process.cwd(), THIRD_PARTY_PATH);
const buildDestinationPath = path.join(thirdPartyFolder, BUILD_DESTINATION);
await Promise.all(dependencies.map(setupDependency));
await build(swiftPMFolder, buildDestinationPath);
await build(thirdPartyFolder, buildDestinationPath);
await Promise.all(
dependencies.map(dependency =>
copyHeadersToFrameworks(dependency, swiftPMFolder, buildDestinationPath),
copyHeadersToFrameworks(
dependency,
thirdPartyFolder,
buildDestinationPath,
),
),
);
composeXCFrameworks(thirdPartyFolder, buildDestinationPath);
console.log('Done!');
}