From 69a4d32028e86769c23d2fa5c06270542e458c8d Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 14 Feb 2025 10:20:10 -0800 Subject: [PATCH] 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 --- .gitignore | 3 +- scripts/releases/prepare-ios-prebuilds.js | 36 ++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d2c702e78a1..f67615b93e6 100644 --- a/.gitignore +++ b/.gitignore @@ -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) diff --git a/scripts/releases/prepare-ios-prebuilds.js b/scripts/releases/prepare-ios-prebuilds.js index 054a1c4feb2..977c9eee934 100644 --- a/scripts/releases/prepare-ios-prebuilds.js +++ b/scripts/releases/prepare-ios-prebuilds.js @@ -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!'); }