From 08f16eef676999792dd695be5e15682f40a9fa46 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 6 Jun 2025 06:43:33 -0700 Subject: [PATCH] Integrate the cli script with the compose-xcframework task (#51850) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51850 This change refactors the last compose-xcframework step to intgrate with the cli.js script to coordinate the build process. ## Changelog: [Internal] - Reviewed By: cortinico Differential Revision: D76046443 fbshipit-source-id: 4740bb0869c688611a03d5085771aa6222132e7e --- packages/react-native/scripts/ios-prebuild.js | 8 ++-- .../scripts/ios-prebuild/xcframework.js | 39 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/react-native/scripts/ios-prebuild.js b/packages/react-native/scripts/ios-prebuild.js index 3160df83255..0e71fea00d8 100644 --- a/packages/react-native/scripts/ios-prebuild.js +++ b/packages/react-native/scripts/ios-prebuild.js @@ -68,9 +68,11 @@ async function main() { } // GENERATE XCFrameworks - const productsFolder = computeProductsFolder(outputFolder); - const frameworkPaths = computeFrameworkPaths(productsFolder); - buildXCFrameworks(root, buildFolder, frameworkPaths, buildType); + if (cli.tasks.compose) { + const productsFolder = computeProductsFolder(outputFolder); + const frameworkPaths = computeFrameworkPaths(productsFolder); + buildXCFrameworks(root, buildFolder, frameworkPaths, buildType); + } // Done! prebuildLog('🏁 Done!'); diff --git a/packages/react-native/scripts/ios-prebuild/xcframework.js b/packages/react-native/scripts/ios-prebuild/xcframework.js index 971d3ff250b..b86068e00f9 100644 --- a/packages/react-native/scripts/ios-prebuild/xcframework.js +++ b/packages/react-native/scripts/ios-prebuild/xcframework.js @@ -74,7 +74,7 @@ function buildXCFrameworks( buildFolder /*: string */, frameworkFolders /*: Array */, buildType /*: 'debug' | 'release' */, -) /*: Array */ { +) { const outputPath = path.join( buildFolder, 'output', @@ -86,25 +86,26 @@ function buildXCFrameworks( cleanPlatformFolders(outputPath); // Build the XCFrameworks by using each framework folder as input - const frameworks = frameworkFolders.map(frameworkFolder => { - const buildCommand = `xcodebuild -create-xcframework -framework "${frameworkFolder}" -output ${outputPath} -allow-internal-distribution`; - frameworkLog(`Building ${frameworkFolder}...`); + const frameworks = frameworkFolders + .map(frameworkFolder => { + return `-framework "${frameworkFolder}"`; + }) + .join(' '); - frameworkLog(buildCommand); - try { - execSync(buildCommand, { - cwd: rootFolder, - stdio: 'inherit', - }); - } catch (error) { - frameworkLog( - `Error building XCFramework: ${error.message}. Check if the build was successful.`, - 'warning', - ); - } + const buildCommand = `xcodebuild -create-xcframework ${frameworks} -output ${outputPath} -allow-internal-distribution`; - return outputPath; - }); + frameworkLog(buildCommand); + try { + execSync(buildCommand, { + cwd: rootFolder, + stdio: 'inherit', + }); + } catch (error) { + frameworkLog( + `Error building XCFramework: ${error.message}. Check if the build was successful.`, + 'warning', + ); + } // Copy header files from the headers folder that we used to build the swift package const outputHeaderFiles = copyHeaderFiles( @@ -121,8 +122,6 @@ function buildXCFrameworks( // Create the module map file createModuleMapFile(outputPath, umbrellaHeaderFile); - - return frameworks; } function copyHeaderFiles(