Skip to content

Refactor the prebuild script to use fetch instead of curl #51398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions packages/react-native/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class RNTarget: BaseTarget {
let dependencies: [String]
let sources: [String]?
let publicHeadersPath: String?
let defines: [CXXSetting]

init(name: String, path: String, searchPaths: [String] = [], linkedFrameworks: [String] = [], excludedPaths: [String] = [], dependencies: [String] = [], sources: [String]? = nil, publicHeadersPath: String? = ".") {
init(name: String, path: String, searchPaths: [String] = [], linkedFrameworks: [String] = [], excludedPaths: [String] = [], dependencies: [String] = [], sources: [String]? = nil, publicHeadersPath: String? = ".", defines: [CXXSetting] = []) {
self.linkedFrameworks = linkedFrameworks
self.excludedPaths = excludedPaths
self.dependencies = dependencies
self.sources = sources
self.publicHeadersPath = publicHeadersPath
self.defines = defines

super.init(name: name, path: path, searchPaths: searchPaths)
}
Expand All @@ -65,7 +67,8 @@ class RNTarget: BaseTarget {
dependencies: self.dependencies,
sources: self.sources,
publicHeadersPath: self.publicHeadersPath,
linkerSettings: linkerSettings
linkerSettings: linkerSettings,
defines: self.defines
)
}
}
Expand Down Expand Up @@ -165,15 +168,23 @@ let reactJsInspectorNetwork = RNTarget(
name: .reactJsInspectorNetwork,
path: "ReactCommon/jsinspector-modern/network",
searchPaths: ["ReactCommon", RuntimeExecutorPath],
dependencies: [.reactNativeDependencies]
dependencies: [.reactNativeDependencies],
defines: [
CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED", to: "1", .when(configuration: BuildConfiguration.debug)),
CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY", to: "1", .when(configuration: BuildConfiguration.debug)),
]
)

let reactJsInspector = RNTarget(
name: .reactJsInspector,
path: "ReactCommon/jsinspector-modern",
searchPaths: ["ReactCommon", RuntimeExecutorPath],
excludedPaths: ["tracing", "network", "tests"],
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .jsi, .reactJsInspectorTracing, .reactJsInspectorNetwork]
dependencies: [.reactNativeDependencies, .reactFeatureFlags, .jsi, .reactJsInspectorTracing, .reactJsInspectorNetwork],
defines: [
CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED", to: "1", .when(configuration: BuildConfiguration.debug)),
CXXSetting.define("REACT_NATIVE_DEBUGGER_ENABLED_DEVONLY", to: "1", .when(configuration: BuildConfiguration.debug)),
]
)

let reactCxxReact = RNTarget(
Expand Down Expand Up @@ -203,7 +214,10 @@ let reactHermes = RNTarget(
path: "ReactCommon/hermes",
searchPaths: ["ReactCommon", RuntimeExecutorPath],
excludedPaths: ["inspector-modern/chrome/tests"],
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactJsiExecutor, .reactJsInspector, .reactJsInspectorTracing, .reactPerfLogger, .hermesPrebuilt, .jsi]
dependencies: [.reactNativeDependencies, .reactCxxReact, .reactJsiExecutor, .reactJsInspector, .reactJsInspectorTracing, .reactPerfLogger, .hermesPrebuilt, .jsi],
defines: [
CXXSetting.define("HERMES_ENABLE_DEBUGGER", to: "1", .when(configuration: BuildConfiguration.debug))
]
)

let reactPerformanceTimeline = RNTarget(
Expand Down Expand Up @@ -331,7 +345,7 @@ let reactRuntimeApple = RNTarget(
path: "ReactCommon/react/runtime/platform/ios",
searchPaths: ["ReactCommon", RuntimeExecutorPath, CallInvokerPath, ReactFBReactNativeSpecPath, FBLazyVectorPath],
excludedPaths: ["ReactCommon/RCTJscInstance.mm"],
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .reactCxxReact, .rctDeprecation, .yoga, .reactRuntime, .reactRCTFabric, .reactCoreModules, .reactTurboModuleCore, .hermesPrebuilt]
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .reactCxxReact, .rctDeprecation, .yoga, .reactRuntime, .reactRCTFabric, .reactCoreModules, .reactTurboModuleCore, .hermesPrebuilt, .reactUtils]
)

let reactCore = RNTarget(
Expand Down Expand Up @@ -454,7 +468,7 @@ let reactRCTAnimation = RNTarget(
name: .reactRCTAnimation,
path: "Libraries/NativeAnimation",
searchPaths: ["ReactCommon", ReactFBReactNativeSpecPath, FBLazyVectorPath, CallInvokerPath],
dependencies: [.rctTypesafety, .jsi, .reactFeatureFlags, .yoga, .reactTurboModuleCore]
dependencies: [.reactNativeDependencies, .rctTypesafety, .jsi, .reactFeatureFlags, .yoga, .reactTurboModuleCore, .reactUtils]
)

let reactRCTImage = RNTarget(
Expand Down Expand Up @@ -648,7 +662,8 @@ extension Target {
dependencies: [String] = [],
sources: [String]? = nil,
publicHeadersPath: String? = ".",
linkerSettings: [LinkerSetting] = []
linkerSettings: [LinkerSetting] = [],
defines: [CXXSetting] = []
) -> Target {
let dependencies = dependencies.map { Dependency.byNameItem(name: $0, condition: nil) }
let excludes = excludedPaths
Expand All @@ -666,10 +681,9 @@ extension Target {
[
.unsafeFlags(["-std=c++20"]),
.define("DEBUG", .when(configuration: .debug)),
.define("NDEBUG", .when(configuration: .release)),
.define("USE_HERMES", to: "1"),
// TODO: T223727527 Why doesn't it pick up this when DEBUG is set??
.define("RCT_ENABLE_INSPECTOR", to: "1", .when(configuration: .debug)),
] + cxxCommonHeaderPaths
] + defines + cxxCommonHeaderPaths

return .target(
name: name,
Expand Down
36 changes: 23 additions & 13 deletions packages/react-native/scripts/ios-prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@
const {prepareHermesArtifactsAsync} = require('./ios-prebuild/hermes');
const {
createFolderIfNotExists,
prebuildLog,
throwIfOnEden,
} = require('./ios-prebuild/utils');
const {execSync} = require('child_process');
const fs = require('fs');
const path = require('path');

const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..');
const packageJsonPath = path.join(
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
'package.json',
);

// $FlowIgnore[unsupported-syntax]
const {version: currentVersion} = require(packageJsonPath);

async function main() {
console.log('Prebuilding React Native iOS...');
console.log('');
prebuildLog('Prebuilding React Native iOS...');

throwIfOnEden();

Expand Down Expand Up @@ -47,10 +56,11 @@ async function main() {
const link = (fromPath /*:string*/, includePath /*:string*/) => {
const source = path.resolve(root, fromPath);
const target = path.resolve(linksFolder, includePath);
console.log(`Linking ${source} to ${target}...`);

createFolderIfNotExists(target);

let linkedFiles = 0;

// get subfolders in source - make sure we only copy folders with header files
const entries = fs.readdirSync(source, {withFileTypes: true});
if (
Expand All @@ -73,6 +83,7 @@ async function main() {
}
try {
fs.linkSync(sourceFile, targetFile);
linkedFiles++;
} catch (e) {
console.error(
`Failed to create link for ${sourceFile} to ${targetFile}: ${e}`,
Expand All @@ -82,6 +93,10 @@ async function main() {
});
}

if (linkedFiles > 0) {
prebuildLog(`Linking ${source} to ${target}...`);
}

const subfolders = entries
.filter(dirent => dirent.isDirectory())
.filter(dirent => dirent.name !== '__tests__')
Expand All @@ -93,23 +108,18 @@ async function main() {
});
};

// HERMES ARTIFACTS
await prepareHermesArtifactsAsync(currentVersion, 'debug');

// CODEGEN
console.log('Running codegen...');
const codegenPath = path.join(root, '.build/codegen');
createFolderIfNotExists(codegenPath);

const command = `node scripts/generate-codegen-artifacts -p "${root}" -o "${codegenPath}" -t ios`;
console.log(command);
execSync(command, {stdio: 'inherit'});

// HERMES ARTIFACTS
console.log('Download hermes...');
// Temporary hardcoded hermes version to make the script work
// We will make it right in a future diff.
// TODO: T223708709
await prepareHermesArtifactsAsync('0.80.0-rc.0', 'debug');

// LINKING
prebuildLog('Linking header files...');
link('Libraries/WebSocket/', 'React');
link('React/Base', 'React');
link('React/Base/Surface', 'React');
Expand Down Expand Up @@ -151,7 +161,7 @@ async function main() {
);

// Done!
console.log('🏁 Done!');
prebuildLog('🏁 Done!');
} catch (err) {
console.error(err);
process.exitCode = 1;
Expand Down
Loading
Loading