Skip to content

Commit 43bfb5d

Browse files
chrfalchfacebook-github-bot
authored andcommitted
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: #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
1 parent a21a4b8 commit 43bfb5d

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

  • packages/react-native/scripts/ios-prebuild
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
const {execSync} = require('child_process');
13+
const fs = require('fs');
14+
const path = require('path');
15+
16+
async function prepareHermesArtifactsAsync(
17+
version /*:string*/,
18+
buildType /*:string*/,
19+
) /*: Promise<string> */ {
20+
// Check if the Hermes artifacts are already downloaded
21+
const artifactsPath /*: string*/ = path.resolve(
22+
process.cwd(),
23+
'.build',
24+
'artifacts',
25+
'hermes',
26+
);
27+
if (fs.existsSync(artifactsPath)) {
28+
return artifactsPath;
29+
}
30+
31+
// Download the Hermes artifacts
32+
const url = getHermesArtifactsUrl(version, buildType);
33+
console.log(`Downloading Hermes artifacts from ${url}...`);
34+
35+
// download the file pointed to by the URL and store it in the ./.build/artifacts folder on disk
36+
await downloadAndExtract(url, artifactsPath);
37+
return artifactsPath;
38+
}
39+
40+
async function downloadAndExtract(url /*:string*/, targetFolder /*:string*/) {
41+
const buildDir = path.resolve('.build', 'artifacts');
42+
const tarballPath = path.join(buildDir, 'artifact.tar.gz');
43+
44+
// Ensure build directory exists
45+
fs.mkdirSync(targetFolder, {recursive: true});
46+
47+
console.log(`Downloading file from ${url} to ${tarballPath}...`);
48+
49+
try {
50+
// Download the file using curl via execSync
51+
execSync(`curl -L "${url}" -o "${tarballPath}"`, {stdio: 'inherit'});
52+
53+
console.log('Download complete. Extracting...');
54+
55+
// Extract the tar.gz using execSync
56+
execSync(`tar -xzf "${tarballPath}" -C "${targetFolder}"`, {
57+
stdio: 'inherit',
58+
});
59+
60+
// Delete the tarball after extraction
61+
fs.unlinkSync(tarballPath);
62+
63+
console.log('Download and extraction complete.');
64+
} catch (error) {
65+
if (fs.existsSync(tarballPath)) {
66+
fs.unlinkSync(tarballPath);
67+
}
68+
throw new Error(`Failed to download or extract: ${error.message}`);
69+
}
70+
}
71+
72+
function getHermesArtifactsUrl(
73+
version /*:string*/,
74+
buildType /*:string*/,
75+
) /*:string*/ {
76+
// Define the URL for the Hermes artifacts
77+
// The URL format is:
78+
// https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/<version>/react-native-artifacts-<version>-hermes-ios-<buildType>.tar.gz
79+
// where <version> is the version of React Native and <buildType> is the build type (e.g., "debug" or "release")
80+
// The Maven repository URL and namespace
81+
// are hardcoded for simplicity, but they could be parameterized if needed
82+
const maven_repo_url = 'https://repo1.maven.org/maven2';
83+
const namespace = 'com/facebook/react';
84+
return `${maven_repo_url}/${namespace}/react-native-artifacts/${version}/react-native-artifacts-${version}-hermes-ios-${buildType}.tar.gz`;
85+
}
86+
87+
module.exports = {
88+
prepareHermesArtifactsAsync,
89+
};

0 commit comments

Comments
 (0)