Skip to content

Commit 394a2c0

Browse files
author
Adam Gleitman
committed
Cherry pick microsoft#2524 into 0.74-stable
1 parent 557d1cd commit 394a2c0

File tree

5 files changed

+119
-51
lines changed

5 files changed

+119
-51
lines changed

.ado/jobs/build-test-rntester.yml

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ parameters:
1616
packager_platform: 'macos'
1717
new_arch_enabled: '1'
1818
use_hermes: '0'
19-
# - name: macos_oldarch_hermes
20-
# friendly_name: 'macOS, Old Arch, Hermes'
21-
# sdk: macosx
22-
# scheme: RNTester-macOS
23-
# packager_platform: 'macos'
24-
# new_arch_enabled: '1'
25-
# use_hermes: '1'
26-
# - name: macos_newarch_hermes
27-
# friendly_name: 'macOS, New Arch, Hermes'
28-
# sdk: macosx
29-
# scheme: RNTester-macOS
30-
# packager_platform: 'macos'
31-
# new_arch_enabled: '1'
32-
# use_hermes: '1'
19+
- name: macos_oldarch_hermes
20+
friendly_name: 'macOS, Old Arch, Hermes'
21+
sdk: macosx
22+
scheme: RNTester-macOS
23+
packager_platform: 'macos'
24+
new_arch_enabled: '1'
25+
use_hermes: '1'
26+
- name: macos_newarch_hermes
27+
friendly_name: 'macOS, New Arch, Hermes'
28+
sdk: macosx
29+
scheme: RNTester-macOS
30+
packager_platform: 'macos'
31+
new_arch_enabled: '1'
32+
use_hermes: '1'
3333
- name: ios_oldarch_jsc
3434
friendly_name: 'iOS, Old Arch, JSC'
3535
sdk: iphonesimulator
@@ -44,20 +44,20 @@ parameters:
4444
packager_platform: 'ios'
4545
new_arch_enabled: '1'
4646
use_hermes: '0'
47-
# - name: ios_oldarch_hermes
48-
# friendly_name: 'iOS, Old Arch, Hermes'
49-
# sdk: iphonesimulator
50-
# scheme: RNTester
51-
# packager_platform: 'ios'
52-
# new_arch_enabled: '1'
53-
# use_hermes: '1'
54-
# - name: ios_newarch_hermes
55-
# friendly_name: 'iOS, New Arch, Hermes'
56-
# sdk: iphonesimulator
57-
# scheme: RNTester
58-
# packager_platform: 'ios'
59-
# new_arch_enabled: '1'
60-
# use_hermes: '1'
47+
- name: ios_oldarch_hermes
48+
friendly_name: 'iOS, Old Arch, Hermes'
49+
sdk: iphonesimulator
50+
scheme: RNTester
51+
packager_platform: 'ios'
52+
new_arch_enabled: '1'
53+
use_hermes: '1'
54+
- name: ios_newarch_hermes
55+
friendly_name: 'iOS, New Arch, Hermes'
56+
sdk: iphonesimulator
57+
scheme: RNTester
58+
packager_platform: 'ios'
59+
new_arch_enabled: '1'
60+
use_hermes: '1'
6161
- name: xros_oldarch_jsc
6262
friendly_name: 'xrOS, Old Arch, JSC'
6363
sdk: xrsimulator
@@ -72,20 +72,20 @@ parameters:
7272
packager_platform: 'ios'
7373
new_arch_enabled: '1'
7474
use_hermes: '0'
75-
# - name: xros_oldarch_hermes
76-
# friendly_name: 'xrOS, Old Arch, Hermes'
77-
# sdk: xrsimulator
78-
# scheme: RNTester-visionOS
79-
# packager_platform: 'ios'
80-
# new_arch_enabled: '1'
81-
# use_hermes: '1'
82-
# - name: xros_newarch_hermes
83-
# friendly_name: 'xrOS, New Arch, Hermes'
84-
# sdk: xrsimulator
85-
# scheme: RNTester-visionOS
86-
# packager_platform: 'ios'
87-
# new_arch_enabled: '1'
88-
# use_hermes: '1'
75+
- name: xros_oldarch_hermes
76+
friendly_name: 'xrOS, Old Arch, Hermes'
77+
sdk: xrsimulator
78+
scheme: RNTester-visionOS
79+
packager_platform: 'ios'
80+
new_arch_enabled: '1'
81+
use_hermes: '1'
82+
- name: xros_newarch_hermes
83+
friendly_name: 'xrOS, New Arch, Hermes'
84+
sdk: xrsimulator
85+
scheme: RNTester-visionOS
86+
packager_platform: 'ios'
87+
new_arch_enabled: '1'
88+
use_hermes: '1'
8989

9090
jobs:
9191
- ${{ each slice in parameters.appleBuildMatrix }}:

packages/react-native/scripts/cocoapods/utils.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,22 @@ def self.apply_xcode_15_patch(installer, xcodebuild_manager: Xcodebuild)
202202
private
203203

204204
def self.add_build_settings_to_pod(installer, settings_name, settings_value, target_pod_name, configuration)
205+
# [macOS
206+
# Since some RN projects might combine multiple platforms into the same Xcode project,
207+
# we'll be much more forgiving with the pod name matching in react-native-macos.
208+
# Could be upstreamed as part of https://github.com/microsoft/react-native-macos/issues/2526.
209+
valid_suffixes = ["", "-iOS", "-macOS", "-visionOS"]
210+
# macOS]
205211
installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
206-
if pod_name.to_s == target_pod_name
212+
if valid_suffixes.any? { |suffix| pod_name.to_s == "#{target_pod_name}#{suffix}" } # [macOS]
207213
target_installation_result.native_target.build_configurations.each do |config|
208-
if configuration == nil || (configuration != nil && config.name.include?(configuration))
209-
config.build_settings[settings_name] ||= '$(inherited) '
210-
config.build_settings[settings_name] << settings_value
211-
end
214+
if configuration == nil || (configuration != nil && config.type == configuration)
215+
config.build_settings[settings_name] ||= '$(inherited) '
216+
config.build_settings[settings_name] << settings_value
212217
end
213218
end
214219
end
220+
end
215221
end
216222

217223
def self.fix_library_search_path(config)

packages/react-native/sdks/hermes-engine/hermes-engine.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ react_native_path = File.join(__dir__, "..", "..")
1212
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
1313
# [macOS
1414
rn_version = package['version']
15-
version = findLastestVersionWithArtifact(rn_version) || rn_version
15+
version = findLatestVersionWithArtifact(rn_version) || rn_version
1616
# macOS]
1717

1818
source_type = hermes_source_type(version, react_native_path)

packages/react-native/sdks/hermes-engine/hermes-utils.rb

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
require 'rexml/document'
88
require 'open3' # [macOS]
99
require 'json' # [macOS]
10+
require 'tmpdir' # [macOS]
1011

1112
HERMES_GITHUB_URL = "https://github.com/facebook/hermes.git"
1213
ENV_BUILD_FROM_SOURCE = "RCT_BUILD_HERMES_FROM_SOURCE"
@@ -175,8 +176,18 @@ def podspec_source_build_from_github_tag(react_native_path)
175176
end
176177

177178
def podspec_source_build_from_github_main()
178-
hermes_log("Using the latest commit from main.")
179-
return {:git => HERMES_GITHUB_URL, :commit => `git ls-remote #{HERMES_GITHUB_URL} main | cut -f 1`.strip}
179+
# hermes_log("Using the latest commit from main.")
180+
# return {:git => HERMES_GITHUB_URL, :commit => `git ls-remote #{HERMES_GITHUB_URL} main | cut -f 1`.strip}
181+
182+
# [macOS
183+
# The logic for this is a bit different on macOS.
184+
# Since react-native-macos lags slightly behind facebook/react-native, we can't always use
185+
# the latest Hermes commit because Hermes and JSI don't always guarantee backwards compatibility.
186+
# Instead, we take the commit hash of Hermes at the time of the merge base with facebook/react-native.
187+
commit = hermes_commit_at_merge_base()
188+
hermes_log("Using Hermes commit from the merge base with facebook/react-native: #{commit}")
189+
return {:git => HERMES_GITHUB_URL, :commit => commit}
190+
# macOS]
180191
end
181192

182193
def podspec_source_download_prebuild_release_tarball(react_native_path, version)
@@ -199,6 +210,51 @@ def artifacts_dir()
199210
return File.join(Pod::Config.instance.project_pods_root, "hermes-engine-artifacts")
200211
end
201212

213+
# [macOS
214+
def hermes_commit_at_merge_base()
215+
# We don't need ls-remote because react-native-macos is a fork of facebook/react-native
216+
fetch_result = `git fetch -q https://github.com/facebook/react-native.git`
217+
if $?.exitstatus != 0
218+
abort <<-EOS
219+
[Hermes] Failed to fetch facebook/react-native into the local repository.
220+
EOS
221+
end
222+
223+
merge_base = `git merge-base FETCH_HEAD HEAD`.strip
224+
if merge_base.empty?
225+
abort <<-EOS
226+
[Hermes] Unable to find the merge base between our HEAD and upstream's HEAD.
227+
EOS
228+
end
229+
230+
timestamp = `git show -s --format=%ci #{merge_base}`.strip
231+
if timestamp.empty?
232+
abort <<-EOS
233+
[Hermes] Unable to extract the timestamp for the merge base (#{merge_base}).
234+
EOS
235+
end
236+
237+
commit = nil
238+
Dir.mktmpdir do |tmpdir|
239+
hermes_git_dir = File.join(tmpdir, "hermes.git")
240+
# Unfortunately we can't use git rev-list on HERMES_GITHUB_URL directly since we're not in that repo.
241+
# Instead, we create a shallow clone to avoid downloading the entire history.
242+
`git clone -q --bare --shallow-since="#{timestamp}" #{HERMES_GITHUB_URL} "#{hermes_git_dir}"`
243+
`git --git-dir="#{hermes_git_dir}" fetch -q --deepen=1`
244+
245+
# If all goes well, this will be the commit hash of Hermes at the time of the merge base
246+
commit = `git --git-dir="#{hermes_git_dir}" rev-list -1 --before="#{timestamp}" HEAD`.strip
247+
if commit.empty?
248+
abort <<-EOS
249+
[Hermes] Unable to find the Hermes commit hash at time #{timestamp}.
250+
EOS
251+
end
252+
end
253+
254+
return commit
255+
end
256+
# macOS]
257+
202258
def hermestag_file(react_native_path)
203259
return File.join(react_native_path, "sdks", ".hermesversion")
204260
end
@@ -238,7 +294,12 @@ def resolve_url_redirects(url)
238294

239295
# [macOS react-native-macos does not publish macos specific hermes artifacts
240296
# so we attempt to find the latest patch version of the iOS artifacts and use that
241-
def findLastestVersionWithArtifact(version)
297+
def findLatestVersionWithArtifact(version)
298+
if version == "1000.0.0"
299+
# The main branch builds from source, so skip the artifact check
300+
return nil
301+
end
302+
242303
# See https://central.sonatype.org/search/rest-api-guide/ for details on query params
243304
versionWithoutPatch = "#{version.match(/^(\d+\.\d+)/)}"
244305
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")

packages/rn-tester/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ end
106106
# visionOS]
107107

108108
post_install do |installer|
109+
$RN_PLATFORMS = %w[iOS macOS visionOS] # [macOS]
109110
react_native_post_install(installer, @prefix_path, :mac_catalyst_enabled => false)
110111
end

0 commit comments

Comments
 (0)