Skip to content

Commit e2c1a6d

Browse files
sharifhhantonis
authored andcommitted
Support New Hermes Runtime Access Pattern (getsentry#5051)
* Update sentry_utils.rb * Update RNSentry.mm * Update RNSentry.podspec * lint clang and add changelog * PR review comments * Update CHANGELOG.md --------- Co-authored-by: Antonis Lilis <antonis.lilis@gmail.com>
1 parent a4dc853 commit e2c1a6d

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

packages/core/RNSentry.podspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rn_package = parse_rn_package_json()
66
rn_version = get_rn_version(rn_package)
77
is_hermes_default = is_hermes_default(rn_version)
88
is_profiling_supported = is_profiling_supported(rn_version)
9+
is_new_hermes_runtime = is_new_hermes_runtime(rn_version)
910

1011
folly_flags = ' -DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1'
1112
folly_compiler_flags = folly_flags + ' ' + '-Wno-comma -Wno-shorten-64-to-32'
@@ -14,7 +15,8 @@ is_new_arch_enabled = ENV["RCT_NEW_ARCH_ENABLED"] == "1"
1415
is_using_hermes = (ENV['USE_HERMES'] == nil && is_hermes_default) || ENV['USE_HERMES'] == '1'
1516
new_arch_enabled_flag = (is_new_arch_enabled ? folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED" : "")
1617
sentry_profiling_supported_flag = (is_profiling_supported ? " -DSENTRY_PROFILING_SUPPORTED=1" : "")
17-
other_cflags = "$(inherited)" + new_arch_enabled_flag + sentry_profiling_supported_flag
18+
new_hermes_runtime_flag = (is_new_hermes_runtime ? " -DNEW_HERMES_RUNTIME" : "")
19+
other_cflags = "$(inherited)" + new_arch_enabled_flag + sentry_profiling_supported_flag + new_hermes_runtime_flag
1820

1921
Pod::Spec.new do |s|
2022
s.name = 'RNSentry'

packages/core/ios/RNSentry.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,15 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
810810
{
811811
#if SENTRY_PROFILING_ENABLED
812812
try {
813+
# ifdef NEW_HERMES_RUNTIME
814+
auto *hermesAPI = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(
815+
facebook::hermes::makeHermesRootAPI());
816+
if (hermesAPI) {
817+
hermesAPI->enableSamplingProfiler();
818+
}
819+
# else
813820
facebook::hermes::HermesRuntime::enableSamplingProfiler();
821+
# endif
814822
if (nativeProfileTraceId == nil && nativeProfileStartTime == 0 && platformProfilers) {
815823
# if SENTRY_TARGET_PROFILING_SUPPORTED
816824
nativeProfileTraceId = [RNSentryId newId];
@@ -870,10 +878,19 @@ + (SentryUser *_Nullable)userFrom:(NSDictionary *)userKeys
870878
nativeProfileTraceId = nil;
871879
nativeProfileStartTime = 0;
872880

873-
facebook::hermes::HermesRuntime::disableSamplingProfiler();
874881
std::stringstream ss;
882+
# ifdef NEW_HERMES_RUNTIME
883+
auto *hermesAPI = facebook::jsi::castInterface<facebook::hermes::IHermesRootAPI>(
884+
facebook::hermes::makeHermesRootAPI());
885+
if (hermesAPI) {
886+
hermesAPI->disableSamplingProfiler();
887+
hermesAPI->dumpSampledTraceToStream(ss);
888+
}
889+
# else
890+
facebook::hermes::HermesRuntime::disableSamplingProfiler();
875891
// Before RN 0.69 Hermes used llvh::raw_ostream (profiling is supported for 0.69 and newer)
876892
facebook::hermes::HermesRuntime::dumpSampledTraceToStream(ss);
893+
# endif
877894

878895
std::string s = ss.str();
879896
NSString *data = [NSString stringWithCString:s.c_str()

packages/core/scripts/sentry_utils.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,12 @@ def is_hermes_default(rn_version)
3131
def is_profiling_supported(rn_version)
3232
return (rn_version[:major] >= 1 || (rn_version[:major] == 0 && rn_version[:minor] >= 69))
3333
end
34+
35+
# Check if we need the old Folly flags (for RN < 0.80.0)
36+
def should_use_folly_flags(rn_version)
37+
return (rn_version[:major] == 0 && rn_version[:minor] < 80)
38+
end
39+
40+
def is_new_hermes_runtime(rn_version)
41+
return (rn_version[:major] >= 1 || (rn_version[:major] == 0 && rn_version[:minor] >= 81))
42+
end
Binary file not shown.

0 commit comments

Comments
 (0)