From 43bfb5da1110c95dcc5d893c02bdf919b4fb936f Mon Sep 17 00:00:00 2001 From: Christian Falch Date: Thu, 8 May 2025 12:59:49 -0700 Subject: [PATCH] building up to React Core (#50766) Summary: - Added multiple targets to Package.swift - WIP: Builds up untill we need to touch files in React/Base ## Changelog: [INTERNAL] - WIP: prebuilding using Swift packages Pull Request resolved: https://github.com/facebook/react-native/pull/50766 Test Plan: This will be tested in a diff in the stack. Reviewed By: cortinico Differential Revision: D74386522 Pulled By: cipolleschi fbshipit-source-id: 7bac3c21a362c4ef79d0104727cdd3494419012f --- .../scripts/ios-prebuild/hermes.js | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 packages/react-native/scripts/ios-prebuild/hermes.js diff --git a/packages/react-native/scripts/ios-prebuild/hermes.js b/packages/react-native/scripts/ios-prebuild/hermes.js new file mode 100644 index 00000000000..b5aa9671c76 --- /dev/null +++ b/packages/react-native/scripts/ios-prebuild/hermes.js @@ -0,0 +1,89 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + * @oncall react_native + */ + +const {execSync} = require('child_process'); +const fs = require('fs'); +const path = require('path'); + +async function prepareHermesArtifactsAsync( + version /*:string*/, + buildType /*:string*/, +) /*: Promise */ { + // Check if the Hermes artifacts are already downloaded + const artifactsPath /*: string*/ = path.resolve( + process.cwd(), + '.build', + 'artifacts', + 'hermes', + ); + if (fs.existsSync(artifactsPath)) { + return artifactsPath; + } + + // Download the Hermes artifacts + const url = getHermesArtifactsUrl(version, buildType); + console.log(`Downloading Hermes artifacts from ${url}...`); + + // download the file pointed to by the URL and store it in the ./.build/artifacts folder on disk + await downloadAndExtract(url, artifactsPath); + return artifactsPath; +} + +async function downloadAndExtract(url /*:string*/, targetFolder /*:string*/) { + const buildDir = path.resolve('.build', 'artifacts'); + const tarballPath = path.join(buildDir, 'artifact.tar.gz'); + + // Ensure build directory exists + fs.mkdirSync(targetFolder, {recursive: true}); + + console.log(`Downloading file from ${url} to ${tarballPath}...`); + + try { + // Download the file using curl via execSync + execSync(`curl -L "${url}" -o "${tarballPath}"`, {stdio: 'inherit'}); + + console.log('Download complete. Extracting...'); + + // Extract the tar.gz using execSync + execSync(`tar -xzf "${tarballPath}" -C "${targetFolder}"`, { + stdio: 'inherit', + }); + + // Delete the tarball after extraction + fs.unlinkSync(tarballPath); + + console.log('Download and extraction complete.'); + } catch (error) { + if (fs.existsSync(tarballPath)) { + fs.unlinkSync(tarballPath); + } + throw new Error(`Failed to download or extract: ${error.message}`); + } +} + +function getHermesArtifactsUrl( + version /*:string*/, + buildType /*:string*/, +) /*:string*/ { + // Define the URL for the Hermes artifacts + // The URL format is: + // https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts//react-native-artifacts--hermes-ios-.tar.gz + // where is the version of React Native and is the build type (e.g., "debug" or "release") + // The Maven repository URL and namespace + // are hardcoded for simplicity, but they could be parameterized if needed + const maven_repo_url = 'https://repo1.maven.org/maven2'; + const namespace = 'com/facebook/react'; + return `${maven_repo_url}/${namespace}/react-native-artifacts/${version}/react-native-artifacts-${version}-hermes-ios-${buildType}.tar.gz`; +} + +module.exports = { + prepareHermesArtifactsAsync, +};