From dd7dccd88b94fd7f128d9c80baf4e53c923fa27e Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 13 Mar 2025 08:40:14 -0700 Subject: [PATCH] Add Nightly support for prebuilds (#49991) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49991 This change adds nightly support for prebuilds. t works the same way hermes works: if the react native version contains nightly, we try to use that version to download the right tarball. To work, it needs to use the `RCT_USE_RN_DEP` env variable. ## Changelog [Internal] - Add Nightly support to consume ReactNativeDependencies Reviewed By: cortinico Differential Revision: D71050926 fbshipit-source-id: 9f461b5f17fde960d92b4082bc60f76959e82cdf --- .../scripts/cocoapods/rndependencies.rb | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/cocoapods/rndependencies.rb b/packages/react-native/scripts/cocoapods/rndependencies.rb index e020c15a7ed..357492aff0b 100644 --- a/packages/react-native/scripts/cocoapods/rndependencies.rb +++ b/packages/react-native/scripts/cocoapods/rndependencies.rb @@ -59,6 +59,7 @@ class ReactNativeDependenciesUtils @@build_from_source = true @@react_native_path = "" @@react_native_version = "" + @@use_nightly = false def self.build_react_native_deps_from_source() return @@build_from_source @@ -66,6 +67,11 @@ class ReactNativeDependenciesUtils def self.resolve_podspec_source() if ENV["RCT_USE_RN_DEP"] && ENV["RCT_USE_RN_DEP"] == "1" + if @@use_nightly + rndeps_log("Using nightly tarball") + return self.podspec_source_download_prebuilt_nightly_tarball(@@react_native_version) + end + rndeps_log("Using release tarball") return self.podspec_source_download_prebuild_release_tarball() end @@ -83,7 +89,12 @@ class ReactNativeDependenciesUtils @@react_native_path = react_native_path @@react_native_version = ENV["RCT_DEPS_VERSION"] == nil ? react_native_version : ENV["RCT_DEPS_VERSION"] - artifacts_exists = ENV["RCT_USE_RN_DEP"] == "1" && release_artifact_exists(@@react_native_version) + if @@react_native_version.include? 'nightly' + rndeps_log("Using nightly build") + @@use_nightly = true + end + + artifacts_exists = ENV["RCT_USE_RN_DEP"] == "1" && (@@use_nightly ? nightly_artifact_exists(@@react_native_version) : release_artifact_exists(@@react_native_version)) use_local_xcframework = ENV["RCT_USE_LOCAL_RN_DEP"] && File.exist?(ENV["RCT_USE_LOCAL_RN_DEP"]) if ENV["RCT_USE_LOCAL_RN_DEP"] @@ -129,11 +140,22 @@ class ReactNativeDependenciesUtils return "#{maven_repo_url}/#{group}/react-native-artifacts/#{version}/react-native-artifacts-#{version}-reactnative-dependencies-#{build_type.to_s}.tar.gz" end + def self.nightly_tarball_url(version) + params = "r=snapshots\&g=com.facebook.react\&a=react-native-artifacts\&c=reactnative-dependencies-debug\&e=tar.gz\&v=#{version}-SNAPSHOT" + return resolve_url_redirects("http://oss.sonatype.org/service/local/artifact/maven/redirect\?#{params}") + end + def self.download_stable_rndeps(react_native_path, version, configuration) tarball_url = release_tarball_url(version, configuration) download_rndeps_tarball(react_native_path, tarball_url, version, configuration) end + def self.podspec_source_download_prebuilt_nightly_tarball(version) + url = nightly_tarball_url(version) + rndeps_log("Using nightly tarball from URL: #{url}") + return {:http => url} + end + def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration) destination_path = configuration == nil ? "#{artifacts_dir()}/reactnative-dependencies-#{version}.tar.gz" : @@ -152,6 +174,10 @@ class ReactNativeDependenciesUtils return artifact_exists(release_tarball_url(version, :debug)) end + def self.nightly_artifact_exists(version) + return artifact_exists(nightly_tarball_url(version).gsub("\\", "")) + end + def self.artifacts_dir() return File.join(Pod::Config.instance.project_pods_root, "ReactNativeDependencies-artifacts") end @@ -177,4 +203,8 @@ class ReactNativeDependenciesUtils Pod::UI.puts log_message.yellow end end + + def self.resolve_url_redirects(url) + return (`curl -Ls -o /dev/null -w %{url_effective} \"#{url}\"`) + end end