From 9ab3e129bd3dd551562414a8261138779cb01c48 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Tue, 24 Jun 2025 14:37:37 -0700 Subject: [PATCH 01/12] Edit hermes-related cocoapods scripts so they work on RNTester Mac --- .../react-native/scripts/cocoapods/utils.rb | 2 +- .../sdks/hermes-engine/hermes-utils.rb | 68 ++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 63639792740eae..8f68cd14a1074c 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -196,7 +196,7 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild) def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration_type) installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| - if pod_name.to_s == target_pod_name + if pod_name.to_s == target_pod_name || %w[macOS iOS visionOS].any? { |platform| pod_name.to_s == "#{target_pod_name}-#{platform}" } # [macOS] target_installation_result.native_target.build_configurations.each do |config| if configuration_type == nil || (configuration_type != nil && config.type == configuration_type) config.build_settings[settings_name] ||= '$(inherited) ' diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index acf7a81edb7c5f..b9a04a1b5229e5 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -7,6 +7,7 @@ require 'rexml/document' require 'open3' # [macOS] require 'json' # [macOS] +require 'tmpdir' # [macOS] HERMES_GITHUB_URL = "https://github.com/facebook/hermes.git" ENV_BUILD_FROM_SOURCE = "RCT_BUILD_HERMES_FROM_SOURCE" @@ -19,13 +20,14 @@ module HermesEngineSourceType BUILD_FROM_GITHUB_TAG = :build_from_github_tag BUILD_FROM_GITHUB_MAIN = :build_from_github_main BUILD_FROM_LOCAL_SOURCE_DIR = :build_from_local_source_dir + BUILD_FROM_GITHUB_MERGE_BASE = :build_from_github_merge_base # [macOS] def HermesEngineSourceType.isPrebuilt(source_type) return source_type == LOCAL_PREBUILT_TARBALL || source_type == DOWNLOAD_PREBUILD_RELEASE_TARBALL || source_type == DOWNLOAD_PREBUILT_NIGHTLY_TARBALL end def HermesEngineSourceType.isFromSource(source_type) - return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN || source_type == BUILD_FROM_LOCAL_SOURCE_DIR + return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN || source_type == BUILD_FROM_LOCAL_SOURCE_DIR || source_type == BUILD_FROM_GITHUB_MERGE_BASE # [macOS] add BUILD_FROM_GITHUB_MERGE_BASE end end @@ -72,6 +74,12 @@ def hermes_source_type(version, react_native_path) return HermesEngineSourceType::DOWNLOAD_PREBUILT_NIGHTLY_TARBALL end + # [macOS - react-native-macos's main branch needs an extra bit of logic + if version == "1000.0.0" + return HermesEngineSourceType::BUILD_FROM_GITHUB_MERGE_BASE + end + # macOS] + return HermesEngineSourceType::BUILD_FROM_GITHUB_MAIN end @@ -119,6 +127,10 @@ def podspec_source(source_type, version, react_native_path) return podspec_source_download_prebuild_release_tarball(react_native_path, version) when HermesEngineSourceType::DOWNLOAD_PREBUILT_NIGHTLY_TARBALL return podspec_source_download_prebuilt_nightly_tarball(version) + # [macOS + when HermesEngineSourceType::BUILD_FROM_GITHUB_MERGE_BASE + return podspec_source_build_from_github_merge_base() + # macOS] else abort "[Hermes] Unsupported or invalid source type provided: #{source_type}" end @@ -195,6 +207,60 @@ def podspec_source_download_prebuilt_nightly_tarball(version) return {:http => url} end +# [macOS +# Hermes and JSI don't always guarantee backwards compatibility, so the safest option is to use +# the commit hash of Hermes at the time of the merge base between us and RNCore. +def podspec_source_build_from_github_merge_base() + rncore_main = `git ls-remote https://github.com/facebook/react-native.git main | cut -f 1`.strip + if rncore_main.empty? + abort <<-EOS + [Hermes] Unable to find the main branch commit hash of RNCore. + EOS + end + + fetch_result = `git fetch -q https://github.com/facebook/react-native.git #{rncore_main}` + if $?.exitstatus != 0 + abort <<-EOS + [Hermes] Failed to fetch RNCore main commit (#{rncore_main}) into the local repository. + EOS + end + + merge_base = `git merge-base #{rncore_main} HEAD`.strip + if merge_base.empty? + abort <<-EOS + [Hermes] Unable to find the merge base between RNCore main (#{rncore_main}) and the current branch. + EOS + end + + timestamp = `git show -s --format=%ci #{merge_base}`.strip + if timestamp.empty? + abort <<-EOS + [Hermes] Unable to extract the timestamp for the merge base (#{merge_base}). + EOS + end + + commit = nil + Dir.mktmpdir do |tmpdir| + hermes_git_dir = File.join(tmpdir, "hermes.git") + # Unfortunately we can't use git rev-list on HERMES_GITHUB_URL directly since we're not in that repo. + # Instead, we create a shallow clone to avoid downloading the entire history. + `git clone -q --bare --shallow-since="#{timestamp}" #{HERMES_GITHUB_URL} "#{hermes_git_dir}"` + `git --git-dir="#{hermes_git_dir}" fetch -q --deepen=1` + + # If all goes well, this will be the commit hash of hermes at the time of the merge base + commit = `git --git-dir="#{hermes_git_dir}" rev-list -1 --before="#{timestamp}" HEAD`.strip + if commit.empty? + abort <<-EOS + [Hermes] Unable to find the Hermes commit hash at time #{timestamp}. + EOS + end + end + + hermes_log("Using Hermes commit hash from the merge base with RNCore main: #{commit}") + return {:git => HERMES_GITHUB_URL, :commit => commit} +end +# macOS] + # HELPERS def artifacts_dir() From 2928a93a4796357c94dec094cea843fe0905719b Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Tue, 24 Jun 2025 14:41:19 -0700 Subject: [PATCH 02/12] Add hermes jobs to appleBuildMatrix --- .ado/jobs/build-test-rntester.yml | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.ado/jobs/build-test-rntester.yml b/.ado/jobs/build-test-rntester.yml index ed7eda63d74c64..f72e2869ae22cb 100644 --- a/.ado/jobs/build-test-rntester.yml +++ b/.ado/jobs/build-test-rntester.yml @@ -50,6 +50,54 @@ parameters: packager_platform: 'ios' new_arch_enabled: '1' use_hermes: '0' + - name: macos_debug_oldarch_hermes + friendly_name: 'macOS, Old Arch, Hermes' + sdk: macosx + configuration: Debug + scheme: RNTester-macOS + packager_platform: 'macos' + new_arch_enabled: '0' + use_hermes: '1' + - name: macos_debug_newarch_hermes + friendly_name: 'macOS, New Arch, Hermes' + sdk: macosx + configuration: Debug + scheme: RNTester-macOS + packager_platform: 'macos' + new_arch_enabled: '1' + use_hermes: '1' + - name: ios_debug_oldarch_hermes + friendly_name: 'iOS, Old Arch, Hermes' + sdk: iphonesimulator + configuration: Debug + scheme: RNTester + packager_platform: 'ios' + new_arch_enabled: '0' + use_hermes: '1' + - name: ios_debug_newarch_hermes + friendly_name: 'iOS, New Arch, Hermes' + sdk: iphonesimulator + configuration: Debug + scheme: RNTester + packager_platform: 'ios' + new_arch_enabled: '1' + use_hermes: '1' + - name: xros_debug_oldarch_hermes + friendly_name: 'xrOS, Old Arch, Hermes' + sdk: xrsimulator + configuration: Debug + scheme: RNTester-visionOS + packager_platform: 'ios' + new_arch_enabled: '0' + use_hermes: '1' + - name: xros_debug_newarch_hermes + friendly_name: 'xrOS, New Arch, Hermes' + sdk: xrsimulator + configuration: Debug + scheme: RNTester-visionOS + packager_platform: 'ios' + new_arch_enabled: '1' + use_hermes: '1' jobs: - ${{ each slice in parameters.appleBuildMatrix }}: From 0ee307d23b6c14bc67920f595b82e76856c2d386 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Tue, 24 Jun 2025 16:31:47 -0700 Subject: [PATCH 03/12] Skip artifact check on the main branch --- packages/react-native/sdks/hermes-engine/hermes-utils.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index b9a04a1b5229e5..7e568e6471d047 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -309,6 +309,11 @@ def resolve_url_redirects(url) # [macOS react-native-macos does not publish macos specific hermes artifacts # so we attempt to find the latest patch version of the iOS artifacts and use that def findLastestVersionWithArtifact(version) + if version == "1000.0.0" + # The main branch builds from source, so skip the artifact check + return nil + end + # See https://central.sonatype.org/search/rest-api-guide/ for details on query params versionWithoutPatch = "#{version.match(/^(\d+\.\d+)/)}" res, = Open3.capture3("curl -s https://search.maven.org/solrsearch/select?q=g:com.facebook.react+AND+a:react-native-artifacts+AND+v:#{versionWithoutPatch}.*&core=gav&rows=1&wt=json") From 85eb42b1f75dc865c842c5583532030d4a95af1f Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Tue, 24 Jun 2025 16:31:59 -0700 Subject: [PATCH 04/12] Fix typo --- packages/react-native/sdks/hermes-engine/hermes-engine.podspec | 2 +- packages/react-native/sdks/hermes-engine/hermes-utils.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec index b3b59893acb2b4..91ad1d191b6d6c 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec +++ b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec @@ -23,7 +23,7 @@ end package = JSON.parse(File.read(File.join(react_native_path, "package.json"))) # [macOS rn_version = package['version'] -version = findLastestVersionWithArtifact(rn_version) || rn_version +version = findLatestVersionWithArtifact(rn_version) || rn_version # macOS] source_type = hermes_source_type(version, react_native_path) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index 7e568e6471d047..96750b6f90161d 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -308,7 +308,7 @@ def resolve_url_redirects(url) # [macOS react-native-macos does not publish macos specific hermes artifacts # so we attempt to find the latest patch version of the iOS artifacts and use that -def findLastestVersionWithArtifact(version) +def findLatestVersionWithArtifact(version) if version == "1000.0.0" # The main branch builds from source, so skip the artifact check return nil From 866fcf7ed881171a35f33012438c831f5b126501 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Wed, 25 Jun 2025 12:11:32 -0700 Subject: [PATCH 05/12] Use $RN_PLATFORMS in add_build_settings_to_pod --- .../react-native/scripts/cocoapods/utils.rb | 17 ++++++++++++----- packages/rn-tester/Podfile | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 8f68cd14a1074c..522d32c600e48c 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -195,16 +195,23 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild) private def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration_type) + # [macOS + valid_suffixes = [""] + if $RN_PLATFORMS != nil && $RN_PLATFORMS.length() >= 2 + # Only apply suffixes if there are at least two platforms + valid_suffixes = $RN_PLATFORMS.map { |platform| "-#{platform}" } + end + # macOS] installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| - if pod_name.to_s == target_pod_name || %w[macOS iOS visionOS].any? { |platform| pod_name.to_s == "#{target_pod_name}-#{platform}" } # [macOS] + if valid_suffixes.any? { |suffix| pod_name.to_s == "#{target_pod_name}#{suffix}" } # [macOS] target_installation_result.native_target.build_configurations.each do |config| - if configuration_type == nil || (configuration_type != nil && config.type == configuration_type) - config.build_settings[settings_name] ||= '$(inherited) ' - config.build_settings[settings_name] << settings_value - end + if configuration_type == nil || (configuration_type != nil && config.type == configuration_type) + config.build_settings[settings_name] ||= '$(inherited) ' + config.build_settings[settings_name] << settings_value end end end + end end def self.fix_library_search_path(config) diff --git a/packages/rn-tester/Podfile b/packages/rn-tester/Podfile index 037ff88d2c5669..36de2659c76c89 100644 --- a/packages/rn-tester/Podfile +++ b/packages/rn-tester/Podfile @@ -107,5 +107,6 @@ end # visionOS] post_install do |installer| + $RN_PLATFORMS = %w[iOS macOS visionOS] # [macOS] react_native_post_install(installer, @prefix_path, :mac_catalyst_enabled => false) end From 11886ba404dd57e721c88b5f64507f391ac9acfb Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Wed, 25 Jun 2025 14:44:03 -0700 Subject: [PATCH 06/12] Move github_merge_base logic into github_main --- .../sdks/hermes-engine/hermes-utils.rb | 71 +++++++------------ 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index 96750b6f90161d..ff7dba13cecbbc 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -20,14 +20,13 @@ module HermesEngineSourceType BUILD_FROM_GITHUB_TAG = :build_from_github_tag BUILD_FROM_GITHUB_MAIN = :build_from_github_main BUILD_FROM_LOCAL_SOURCE_DIR = :build_from_local_source_dir - BUILD_FROM_GITHUB_MERGE_BASE = :build_from_github_merge_base # [macOS] def HermesEngineSourceType.isPrebuilt(source_type) return source_type == LOCAL_PREBUILT_TARBALL || source_type == DOWNLOAD_PREBUILD_RELEASE_TARBALL || source_type == DOWNLOAD_PREBUILT_NIGHTLY_TARBALL end def HermesEngineSourceType.isFromSource(source_type) - return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN || source_type == BUILD_FROM_LOCAL_SOURCE_DIR || source_type == BUILD_FROM_GITHUB_MERGE_BASE # [macOS] add BUILD_FROM_GITHUB_MERGE_BASE + return source_type == BUILD_FROM_GITHUB_COMMIT || source_type == BUILD_FROM_GITHUB_TAG || source_type == BUILD_FROM_GITHUB_MAIN || source_type == BUILD_FROM_LOCAL_SOURCE_DIR end end @@ -74,12 +73,6 @@ def hermes_source_type(version, react_native_path) return HermesEngineSourceType::DOWNLOAD_PREBUILT_NIGHTLY_TARBALL end - # [macOS - react-native-macos's main branch needs an extra bit of logic - if version == "1000.0.0" - return HermesEngineSourceType::BUILD_FROM_GITHUB_MERGE_BASE - end - # macOS] - return HermesEngineSourceType::BUILD_FROM_GITHUB_MAIN end @@ -127,10 +120,6 @@ def podspec_source(source_type, version, react_native_path) return podspec_source_download_prebuild_release_tarball(react_native_path, version) when HermesEngineSourceType::DOWNLOAD_PREBUILT_NIGHTLY_TARBALL return podspec_source_download_prebuilt_nightly_tarball(version) - # [macOS - when HermesEngineSourceType::BUILD_FROM_GITHUB_MERGE_BASE - return podspec_source_build_from_github_merge_base() - # macOS] else abort "[Hermes] Unsupported or invalid source type provided: #{source_type}" end @@ -189,46 +178,24 @@ def podspec_source_build_from_github_tag(react_native_path) end def podspec_source_build_from_github_main() - hermes_log("Using the latest commit from main.") - return {:git => HERMES_GITHUB_URL, :commit => `git ls-remote #{HERMES_GITHUB_URL} main | cut -f 1`.strip} -end - -def podspec_source_download_prebuild_release_tarball(react_native_path, version) - url = release_tarball_url(version, :debug) - hermes_log("Using release tarball from URL: #{url}") - download_stable_hermes(react_native_path, version, :debug) - download_stable_hermes(react_native_path, version, :release) - return {:http => url} -end - -def podspec_source_download_prebuilt_nightly_tarball(version) - url = nightly_tarball_url(version) - hermes_log("Using nightly tarball from URL: #{url}") - return {:http => url} -end - -# [macOS -# Hermes and JSI don't always guarantee backwards compatibility, so the safest option is to use -# the commit hash of Hermes at the time of the merge base between us and RNCore. -def podspec_source_build_from_github_merge_base() - rncore_main = `git ls-remote https://github.com/facebook/react-native.git main | cut -f 1`.strip - if rncore_main.empty? - abort <<-EOS - [Hermes] Unable to find the main branch commit hash of RNCore. - EOS - end + # [macOS + # The logic for this is a bit different on macOS. + # Since react-native-macos lags slightly behind react-native, we can't always use + # the latest Hermes commit because Hermes and JSI don't always guarantee backwards compatibility. + # Instead, we take the commit hash of Hermes at the time of the merge base between us and RNCore. - fetch_result = `git fetch -q https://github.com/facebook/react-native.git #{rncore_main}` + # We don't need ls-remote because react-native-macos is a fork of RNCore + fetch_result = `git fetch -q https://github.com/facebook/react-native.git` if $?.exitstatus != 0 abort <<-EOS - [Hermes] Failed to fetch RNCore main commit (#{rncore_main}) into the local repository. + [Hermes] Failed to fetch RNCore into the local repository. EOS end - merge_base = `git merge-base #{rncore_main} HEAD`.strip + merge_base = `git merge-base FETCH_HEAD HEAD`.strip if merge_base.empty? abort <<-EOS - [Hermes] Unable to find the merge base between RNCore main (#{rncore_main}) and the current branch. + [Hermes] Unable to find the merge base between RNCore main and the current branch. EOS end @@ -258,8 +225,22 @@ def podspec_source_build_from_github_merge_base() hermes_log("Using Hermes commit hash from the merge base with RNCore main: #{commit}") return {:git => HERMES_GITHUB_URL, :commit => commit} + # macOS] +end + +def podspec_source_download_prebuild_release_tarball(react_native_path, version) + url = release_tarball_url(version, :debug) + hermes_log("Using release tarball from URL: #{url}") + download_stable_hermes(react_native_path, version, :debug) + download_stable_hermes(react_native_path, version, :release) + return {:http => url} +end + +def podspec_source_download_prebuilt_nightly_tarball(version) + url = nightly_tarball_url(version) + hermes_log("Using nightly tarball from URL: #{url}") + return {:http => url} end -# macOS] # HELPERS From 8eb2af0f0c9b7d1c2ad20772dc8575881b89d69f Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 10:08:34 -0700 Subject: [PATCH 07/12] Add back the original implementation of podspec_source_build_from_github_main, but commented out --- packages/react-native/sdks/hermes-engine/hermes-utils.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index ff7dba13cecbbc..0322f05505876a 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -178,6 +178,9 @@ def podspec_source_build_from_github_tag(react_native_path) end def podspec_source_build_from_github_main() + # hermes_log("Using the latest commit from main.") + # return {:git => HERMES_GITHUB_URL, :commit => `git ls-remote #{HERMES_GITHUB_URL} main | cut -f 1`.strip} + # [macOS # The logic for this is a bit different on macOS. # Since react-native-macos lags slightly behind react-native, we can't always use From 4743dabedb79d567e59a85c2a552a4ca1081bd0a Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 10:15:17 -0700 Subject: [PATCH 08/12] Improve suffix logic --- packages/react-native/scripts/cocoapods/utils.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 522d32c600e48c..8d80535ffb0c19 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -196,11 +196,9 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild) def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration_type) # [macOS - valid_suffixes = [""] - if $RN_PLATFORMS != nil && $RN_PLATFORMS.length() >= 2 - # Only apply suffixes if there are at least two platforms - valid_suffixes = $RN_PLATFORMS.map { |platform| "-#{platform}" } - end + # Since some RN projects might combine multiple platforms into the same Xcode project, + # we'll be much more forgiving with the pod name matching in react-native-macos. + valid_suffixes = ["", "-iOS", "-macOS", "-visionOS"] # macOS] installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result| if valid_suffixes.any? { |suffix| pod_name.to_s == "#{target_pod_name}#{suffix}" } # [macOS] From fc94c637bdb3aa0bfe7f0cf8b16dd9bdaed9eee8 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 10:21:13 -0700 Subject: [PATCH 09/12] Rewording --- .../sdks/hermes-engine/hermes-utils.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index 0322f05505876a..91999b71c134a0 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -183,22 +183,22 @@ def podspec_source_build_from_github_main() # [macOS # The logic for this is a bit different on macOS. - # Since react-native-macos lags slightly behind react-native, we can't always use + # Since react-native-macos lags slightly behind facebook/react-native, we can't always use # the latest Hermes commit because Hermes and JSI don't always guarantee backwards compatibility. - # Instead, we take the commit hash of Hermes at the time of the merge base between us and RNCore. + # Instead, we take the commit hash of Hermes at the time of the merge base with facebook/react-native. - # We don't need ls-remote because react-native-macos is a fork of RNCore + # We don't need ls-remote because react-native-macos is a fork of facebook/react-native fetch_result = `git fetch -q https://github.com/facebook/react-native.git` if $?.exitstatus != 0 abort <<-EOS - [Hermes] Failed to fetch RNCore into the local repository. + [Hermes] Failed to fetch facebook/react-native into the local repository. EOS end merge_base = `git merge-base FETCH_HEAD HEAD`.strip if merge_base.empty? abort <<-EOS - [Hermes] Unable to find the merge base between RNCore main and the current branch. + [Hermes] Unable to find the merge base between our HEAD and upstream's HEAD. EOS end @@ -217,7 +217,7 @@ def podspec_source_build_from_github_main() `git clone -q --bare --shallow-since="#{timestamp}" #{HERMES_GITHUB_URL} "#{hermes_git_dir}"` `git --git-dir="#{hermes_git_dir}" fetch -q --deepen=1` - # If all goes well, this will be the commit hash of hermes at the time of the merge base + # If all goes well, this will be the commit hash of Hermes at the time of the merge base commit = `git --git-dir="#{hermes_git_dir}" rev-list -1 --before="#{timestamp}" HEAD`.strip if commit.empty? abort <<-EOS @@ -226,7 +226,7 @@ def podspec_source_build_from_github_main() end end - hermes_log("Using Hermes commit hash from the merge base with RNCore main: #{commit}") + hermes_log("Using Hermes commit hash from the merge base with facebook/react-native: #{commit}") return {:git => HERMES_GITHUB_URL, :commit => commit} # macOS] end From a6ec474586f46d195d26ab2822ad4cff30e74d49 Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 10:49:46 -0700 Subject: [PATCH 10/12] Move merge base logic to its own function --- .../sdks/hermes-engine/hermes-utils.rb | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index 91999b71c134a0..c578195acff900 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -186,7 +186,33 @@ def podspec_source_build_from_github_main() # Since react-native-macos lags slightly behind facebook/react-native, we can't always use # the latest Hermes commit because Hermes and JSI don't always guarantee backwards compatibility. # Instead, we take the commit hash of Hermes at the time of the merge base with facebook/react-native. + commit = hermes_commit_at_merge_base() + hermes_log("Using Hermes commit from the merge base with facebook/react-native: #{commit}") + return {:git => HERMES_GITHUB_URL, :commit => commit} + # macOS] +end + +def podspec_source_download_prebuild_release_tarball(react_native_path, version) + url = release_tarball_url(version, :debug) + hermes_log("Using release tarball from URL: #{url}") + download_stable_hermes(react_native_path, version, :debug) + download_stable_hermes(react_native_path, version, :release) + return {:http => url} +end + +def podspec_source_download_prebuilt_nightly_tarball(version) + url = nightly_tarball_url(version) + hermes_log("Using nightly tarball from URL: #{url}") + return {:http => url} +end + +# HELPERS + +def artifacts_dir() + return File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts") +end +def hermes_commit_at_merge_base() # We don't need ls-remote because react-native-macos is a fork of facebook/react-native fetch_result = `git fetch -q https://github.com/facebook/react-native.git` if $?.exitstatus != 0 @@ -226,29 +252,7 @@ def podspec_source_build_from_github_main() end end - hermes_log("Using Hermes commit hash from the merge base with facebook/react-native: #{commit}") - return {:git => HERMES_GITHUB_URL, :commit => commit} - # macOS] -end - -def podspec_source_download_prebuild_release_tarball(react_native_path, version) - url = release_tarball_url(version, :debug) - hermes_log("Using release tarball from URL: #{url}") - download_stable_hermes(react_native_path, version, :debug) - download_stable_hermes(react_native_path, version, :release) - return {:http => url} -end - -def podspec_source_download_prebuilt_nightly_tarball(version) - url = nightly_tarball_url(version) - hermes_log("Using nightly tarball from URL: #{url}") - return {:http => url} -end - -# HELPERS - -def artifacts_dir() - return File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts") + return commit end def hermestag_file(react_native_path) From 7c711f0d6e8f42bfc927c09520f0bcfdbc83e34e Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 14:07:29 -0700 Subject: [PATCH 11/12] Add macOS tags --- packages/react-native/sdks/hermes-engine/hermes-utils.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-native/sdks/hermes-engine/hermes-utils.rb b/packages/react-native/sdks/hermes-engine/hermes-utils.rb index c578195acff900..5c9a1810f62eca 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-utils.rb +++ b/packages/react-native/sdks/hermes-engine/hermes-utils.rb @@ -212,6 +212,7 @@ def artifacts_dir() return File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts") end +# [macOS def hermes_commit_at_merge_base() # We don't need ls-remote because react-native-macos is a fork of facebook/react-native fetch_result = `git fetch -q https://github.com/facebook/react-native.git` @@ -254,6 +255,7 @@ def hermes_commit_at_merge_base() return commit end +# macOS] def hermestag_file(react_native_path) return File.join(react_native_path, "sdks", ".hermesversion") From 9bd2abdb90128200fd32fc611a170eadb76826ea Mon Sep 17 00:00:00 2001 From: Adam Gleitman Date: Fri, 27 Jun 2025 14:07:37 -0700 Subject: [PATCH 12/12] Add reference to GH issue --- packages/react-native/scripts/cocoapods/utils.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/react-native/scripts/cocoapods/utils.rb b/packages/react-native/scripts/cocoapods/utils.rb index 8d80535ffb0c19..e10da4744deacc 100644 --- a/packages/react-native/scripts/cocoapods/utils.rb +++ b/packages/react-native/scripts/cocoapods/utils.rb @@ -198,6 +198,7 @@ def self.add_build_settings_to_pod(installer, settings_name, settings_value, tar # [macOS # Since some RN projects might combine multiple platforms into the same Xcode project, # we'll be much more forgiving with the pod name matching in react-native-macos. + # Could be upstreamed as part of https://github.com/microsoft/react-native-macos/issues/2526. valid_suffixes = ["", "-iOS", "-macOS", "-visionOS"] # macOS] installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|