Skip to content

Commit 07f40ec

Browse files
chrfalchmeta-codesync[bot]
authored andcommitted
add support for symbolication of precompiled React.xcframework (#54033)
Summary: Pull Request resolved: #54033 This commit adds support for symbolication of the XCFrameworks on request. Symbol files are big and only needed if you need to debug React Native itself - f.ex. if you are a framework developer like Expo. Symbolication can be performed by setting the `RCT_SYMBOLICATE_PREBUILT_FRAMEWORKS=1` environment variable. This will cause the `ReactNativeCoreUtils` class to download symbol files and symbolicate the XFrameworks by doing the following: - After downloading the requested React.XCFramework the symbols will also be downloaded and places in the artifacts folder. - The XCFrameworks will be expanded and the folders in the symbol archive will be extracted into the XCFramework before it is zipped up again. <img width="400" alt="image" src="https://github.com/user-attachments/assets/ec8dd2e1-c7f8-4d5f-a3b6-b8ffbb678c95" /> ## Changelog: [IOS] [FIXED] - Added support for symbolication of precompiled React.xcframework Test Plan: ``` RCT_SYMBOLICATE_PREBUILT_FRAMEWORKS=1 RCT_USE_RN_DEP=1 RCT_USE_PREBUILT_RNCORE=1 bundle exec pod install ``` Remember to clean (remove the Pods directory) before turning on/off. Reviewed By: christophpurrer Differential Revision: D83753187 Pulled By: cipolleschi fbshipit-source-id: f1522e1befdea99fb8c65695322ea3ed68e6caed
1 parent 12850c2 commit 07f40ec

File tree

1 file changed

+78
-21
lines changed
  • packages/react-native/scripts/cocoapods

1 file changed

+78
-21
lines changed

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

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ def add_rncore_dependency(s)
2424
## - RCT_USE_PREBUILT_RNCORE: If set to 1, it will use the release tarball from Maven instead of building from source.
2525
## - RCT_TESTONLY_RNCORE_TARBALL_PATH: **TEST ONLY** If set, it will use a local tarball of RNCore if it exists.
2626
## - RCT_TESTONLY_RNCORE_VERSION: **TEST ONLY** If set, it will override the version of RNCore to be used.
27+
## - RCT_SYMBOLICATE_PREBUILT_FRAMEWORKS: If set to 1, it will download the dSYMs for the prebuilt RNCore frameworks and install these in the framework folders
2728

2829
class ReactNativeCoreUtils
2930
@@build_from_source = true
3031
@@react_native_path = ""
3132
@@react_native_version = ""
3233
@@use_nightly = false
34+
@@download_dsyms = false
3335

3436
## Sets up wether ReactNative Core should be built from source or not.
3537
## If RCT_USE_PREBUILT_RNCORE is set to 1 and the artifacts exists on Maven, it will
@@ -40,6 +42,7 @@ def self.setup_rncore(react_native_path, react_native_version)
4042
rncore_log("Setting up ReactNativeCore...")
4143
@@react_native_path = react_native_path
4244
@@react_native_version = ENV["RCT_TESTONLY_RNCORE_VERSION"] == nil ? react_native_version : ENV["RCT_TESTONLY_RNCORE_VERSION"]
45+
@@download_dsyms = ENV["RCT_SYMBOLICATE_PREBUILT_FRAMEWORKS"] == "1"
4346

4447
if @@react_native_version.include? "nightly"
4548
@@use_nightly = true
@@ -89,7 +92,7 @@ def self.resolve_podspec_source()
8992
if ENV["RCT_USE_PREBUILT_RNCORE"] == "1"
9093
if @@use_nightly
9194
begin
92-
return self.podspec_source_download_prebuilt_nightly_tarball(@@react_native_version)
95+
return self.podspec_source_download_prebuilt_nightly_tarball()
9396
rescue => e
9497
rncore_log("Failed to download nightly tarball: #{e.message}", :error)
9598
return
@@ -120,11 +123,63 @@ def self.podspec_source_download_prebuild_stable_tarball()
120123
if @@build_from_source
121124
return
122125
end
123-
url = stable_tarball_url(@@react_native_version, :debug)
124-
rncore_log("Using tarball from URL: #{url}")
125-
download_stable_rncore(@@react_native_path, @@react_native_version, :debug)
126-
download_stable_rncore(@@react_native_path, @@react_native_version, :release)
127-
return {:http => url}
126+
127+
destinationDebug = download_stable_rncore(@@react_native_path, @@react_native_version, :debug)
128+
destinationRelease = download_stable_rncore(@@react_native_path, @@react_native_version, :release)
129+
130+
if @@download_dsyms
131+
dSymsDebug = download_stable_rncore(@@react_native_path, @@react_native_version, :debug, true)
132+
dSymsRelease = download_stable_rncore(@@react_native_path, @@react_native_version, :release, true)
133+
rncore_log("Resolved stable dSYMs")
134+
rncore_log(" #{Pathname.new(dSymsDebug).relative_path_from(Pathname.pwd).to_s}")
135+
rncore_log(" #{Pathname.new(dSymsRelease).relative_path_from(Pathname.pwd).to_s}")
136+
137+
# Make sure that the dSYMs are processed
138+
process_dsyms(destinationDebug, dSymsDebug)
139+
process_dsyms(destinationRelease, dSymsRelease)
140+
end
141+
142+
rncore_log("Resolved stable ReactNativeCore-prebuilt version:")
143+
rncore_log(" #{Pathname.new(destinationDebug).relative_path_from(Pathname.pwd).to_s}")
144+
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")
145+
146+
return {:http => URI::File.build(path: destinationDebug).to_s }
147+
end
148+
149+
def self.podspec_source_download_prebuilt_nightly_tarball()
150+
if @@react_native_path == ""
151+
rncore_log("react_native_path is not set", :error)
152+
return
153+
end
154+
155+
if @@react_native_version == ""
156+
rncore_log("react_native_version is not set", :error)
157+
return
158+
end
159+
160+
if @@build_from_source
161+
return
162+
end
163+
164+
destinationDebug = download_nightly_rncore(@@react_native_path, @@react_native_version, :debug)
165+
destinationRelease = download_nightly_rncore(@@react_native_path, @@react_native_version, :release)
166+
167+
if @@download_dsyms
168+
dSymsDebug = download_nightly_rncore(@@react_native_path, @@react_native_version, :debug, true)
169+
dSymsRelease = download_nightly_rncore(@@react_native_path, @@react_native_version, :release, true)
170+
rncore_log("Resolved nightly dSYMs")
171+
rncore_log(" #{Pathname.new(dSymsDebug).relative_path_from(Pathname.pwd).to_s}")
172+
rncore_log(" #{Pathname.new(dSymsRelease).relative_path_from(Pathname.pwd).to_s}")
173+
174+
# Make sure that the dSYMs are processed
175+
process_dsyms(destinationDebug, dSymsDebug)
176+
process_dsyms(destinationRelease, dSymsRelease)
177+
end
178+
179+
rncore_log("Resolved nightly ReactNativeCore-prebuilt version:")
180+
rncore_log(" #{Pathname.new(destinationDebug).relative_path_from(Pathname.pwd).to_s}")
181+
rncore_log(" #{Pathname.new(destinationRelease).relative_path_from(Pathname.pwd).to_s}")
182+
return {:http => URI::File.build(path: destinationDebug).to_s }
128183
end
129184

130185
def self.process_dsyms(frameworkTarball, dSymsTarball)
@@ -275,7 +330,7 @@ def self.generate_plist_content(mappings)
275330
PLIST
276331
end
277332

278-
def self.stable_tarball_url(version, build_type)
333+
def self.stable_tarball_url(version, build_type, dsyms = false)
279334
## You can use the `ENTERPRISE_REPOSITORY` ariable to customise the base url from which artifacts will be downloaded.
280335
## The mirror's structure must be the same of the Maven repo the react-native core team publishes on Maven Central.
281336
maven_repo_url =
@@ -285,12 +340,12 @@ def self.stable_tarball_url(version, build_type)
285340
group = "com/facebook/react"
286341
# Sample url from Maven:
287342
# https://repo1.maven.org/maven2/com/facebook/react/react-native-artifacts/0.81.0/react-native-artifacts-0.81.0-reactnative-core-debug.tar.gz
288-
return "#{maven_repo_url}/#{group}/react-native-artifacts/#{version}/react-native-artifacts-#{version}-reactnative-core-#{build_type.to_s}.tar.gz"
343+
return "#{maven_repo_url}/#{group}/react-native-artifacts/#{version}/react-native-artifacts-#{version}-reactnative-core-#{dsyms ? "dSYM-" : ""}#{build_type.to_s}.tar.gz"
289344
end
290345

291-
def self.nightly_tarball_url(version)
346+
def self.nightly_tarball_url(version, configuration, dsyms = false)
292347
artefact_coordinate = "react-native-artifacts"
293-
artefact_name = "reactnative-core-debug.tar.gz"
348+
artefact_name = "reactnative-core-#{dsyms ? "dSYM-" : ""}#{configuration ? configuration : "debug"}.tar.gz"
294349
xml_url = "https://central.sonatype.com/repository/maven-snapshots/com/facebook/react/#{artefact_coordinate}/#{version}-SNAPSHOT/maven-metadata.xml"
295350

296351
response = Net::HTTP.get_response(URI(xml_url))
@@ -307,26 +362,28 @@ def self.nightly_tarball_url(version)
307362
end
308363
end
309364

310-
def self.download_stable_rncore(react_native_path, version, configuration)
311-
tarball_url = stable_tarball_url(version, configuration)
312-
download_rncore_tarball(react_native_path, tarball_url, version, configuration)
365+
def self.download_stable_rncore(react_native_path, version, configuration, dsyms = false)
366+
tarball_url = stable_tarball_url(version, configuration, dsyms)
367+
download_rncore_tarball(react_native_path, tarball_url, version, configuration, dsyms)
313368
end
314369

315-
def self.podspec_source_download_prebuilt_nightly_tarball(version)
316-
url = nightly_tarball_url(version)
317-
rncore_log("Using nightly tarball from URL: #{url}")
318-
return {:http => url}
370+
def self.download_nightly_rncore(react_native_path, version, configuration, dsyms = false)
371+
tarball_url = nightly_tarball_url(version, configuration, dsyms)
372+
download_rncore_tarball(react_native_path, tarball_url, version, configuration, dsyms)
319373
end
320374

321-
def self.download_rncore_tarball(react_native_path, tarball_url, version, configuration)
375+
def self.download_rncore_tarball(react_native_path, tarball_url, version, configuration, dsyms = false)
322376
destination_path = configuration == nil ?
323-
"#{artifacts_dir()}/reactnative-core-#{version}.tar.gz" :
324-
"#{artifacts_dir()}/reactnative-core-#{version}-#{configuration}.tar.gz"
377+
"#{artifacts_dir()}/reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}.tar.gz" :
378+
"#{artifacts_dir()}/reactnative-core-#{version}#{dsyms ? "-dSYM" : ""}-#{configuration}.tar.gz"
325379

326380
unless File.exist?(destination_path)
327381
# Download to a temporary file first so we don't cache incomplete downloads.
382+
rncore_log("Downloading ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball from #{tarball_url} to #{Pathname.new(destination_path).relative_path_from(Pathname.pwd).to_s}")
328383
tmp_file = "#{artifacts_dir()}/reactnative-core.download"
329384
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
385+
else
386+
rncore_log("Using downloaded ReactNativeCore-prebuilt #{dsyms ? "dSYMs " : ""}#{configuration ? configuration.to_s : ""} tarball at #{Pathname.new(destination_path).relative_path_from(Pathname.pwd).to_s}")
330387
end
331388

332389
return destination_path
@@ -337,7 +394,7 @@ def self.release_artifact_exists(version)
337394
end
338395

339396
def self.nightly_artifact_exists(version)
340-
return artifact_exists(nightly_tarball_url(version).gsub("\\", ""))
397+
return artifact_exists(nightly_tarball_url(version, :debug).gsub("\\", ""))
341398
end
342399

343400
def self.artifacts_dir()

0 commit comments

Comments
 (0)