-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Direct Debugging with JSC #39549
Conversation
Base commit: eb1b42f |
@ryancat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Any update for this one? |
Ping on this PR again, any chance someone can take a look? This should be non, risky, and inline with the previous ifdef structure that fb30fca had removed |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
@cipolleschi any chance this could be looked at again? |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400 | ||
#define _JSC_HAS_INSPECTABLE | ||
#endif | ||
#endif | ||
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) | ||
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130300 | |
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 13300 |
If MacOS follows the same semantics of iOS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In AvailabilityVersions.h
:
#define __IPHONE_16_4 160400
#define __IPHONE_16_5 160500
#define __IPHONE_16_6 160600
#define __IPHONE_16_7 160700
#define __IPHONE_17_0 170000
#define __IPHONE_17_1 170100
#define __IPHONE_17_2 170200
#define __IPHONE_17_3 170300
#define __IPHONE_17_4 170400
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm... so, why the check #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160400
failed on devices < 16.4? 😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do some testing with an iOS 15 simulator and try to update. Luckily Xcode has a way to see post macro processed files (though I forget the command at this time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing, and as far as I can tell. the existing code is right.
With local testing, I added two printf statements to the offending block and tested on an iOS 15.5 and iOS 17.2 Simulator + RNTester with USE_HERMES=0 pod install
:
//#if (__OSX_AVAILABLE_STARTING(MAC_13_3, IPHONE_16_4))
printf("Inside JSC_HAS_INSPECTABLE hit");
if (__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)) {
printf("Inside __builtin_available hit");
JSGlobalContextSetInspectable(ctx_, true);
}
//#endif
#endif
With the outer __OSX_AVAILABLE_STARTING
macro commented out, iOS 17.2 will hit both printf statements, while iOS 15.5 will only hit the outer statement (expected). However, with the extra __OSX_AVAILABLE_STARTING
commented in, we hit neither printf statement on both iOS 15.5 and iOS 17.2! I can confirm this breaks JSC direct debugging on iOS 16.4+ as well 😨 .
Looking even deeper at Availability.h
, I suspect the original crash repoprted the apple forum had their app build setting misconfigured. I see this in comments around the __OSX_AVAILABLE_STARTING
macro:
For these macros to function properly, a program must specify the OS version range
it is targeting. The min OS version is specified as an option to the compiler:
-mmacosx-version-min=10.x when building for Mac OS X, and -miphoneos-version-min=y.z
when building for the iPhone. The upper bound for the OS version is rarely needed,
but it can be set on the command line via: -D__MAC_OS_X_VERSION_MAX_ALLOWED=10x0 for
Mac OS X and __IPHONE_OS_VERSION_MAX_ALLOWED = y0z00 for iOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? There was an internal app using JSC? I guess you could maybe compile and link this file without using JSC.. Now I don't know 😵💫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, unfortunately some teams are still on JSC... 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that just leaves the current state being that Direct Debugging is broken on JSC for iOS 16.4+, and fix crashes iOS 16.4-...
I will need to investigate more it seems, but short term priority for be right now is React Native macOS 0.74 sooo no timeline guarantees :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Unless of course my testing was wrong and the patch for the new macro is actually fine.. maybe I'll try outside of RNTester
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update:
- The crash only happens on device, hence we didn't catch it in simulator (Thankfully I kept my old iPad)
- System frameworks are dynamically linked, so the symbol lookup happens at runtime. That makes sense why it's a crash and not a failure to compile.
- It can be fixed by linking
JavascriptCore
as a weak_framework instead of a framework. Doing so means it will explicitly link all the sumbols in the framework weakly, and seems to be the intended way to deal with new APIs. We don't use weak frameworks internally much, so it's a bit of a blind spot to me. https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
I updated this PR so that we weakly link JavascriptCore. I also totally changed the title and description because the scope is now very different :D
## Summary: Merge up to RN Core's `0.73.8` release, with one notable change: - Instead of picking up facebook#44185 , let's instead port facebook#39549 to React Native macOS, so that we have direct debugging with JSC working. ## Test Plan: CI should pass.
Is it a problem if we keep this PR hovering for a bit? We are in the middle of some migrations of internal apps and it will be easier to land this after the migration is done. |
No problem for me. Internally, we're all clear because we use React Native macOS (and have higher minimum Xcode support, etc). For the community, I guess if nobody else has complained, 🤷🏽♂️. I'm also focused more on internal stuff atm. |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Hi @cipolleschi, are the team in a position where this could be landed now? (Asking because the stale bot just kicked in 😄) |
@liamjones is there a reason why you are still using JSC instead of Hermes? With Hermes, you can use the React Native DevTools that are much more powerful than the JSC direct debugging. |
@cipolleschi It's down to dependency/upgrade complexity + resource constraint issues here. I'd love to get to Hermes (and the new architecture) but, alongside feature development & bug fixing of our own code, we struggle to even keep up to date with RN upgrades currently due to their frequency (I'm trying to upgrade from 0.73 to 0.74+ atm). I have tried to look at the Hermes switchover in the past but;
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi merged this pull request in b04d17a. |
This pull request was successfully merged by @Saadnajmi in b04d17a When will my fix make it into a release? | How to file a pick request? |
Heh. Didn't think this would land. Thanks! |
Summary:
Originally with 5cf8f43 , we added a call to a new Apple API
JSGlobalContextSetInspectable
to ensure that our Javascript running with JSC is debuggable. That change was guarded with a__builtin_available(macOS 13.3, iOS 16.4, tvOS 16.4, *)
check to make sure it only ran on OS'es where to function existed. Later, in 3eeee11 we did an extra guard in the way of a macro to check we were compiling against a new enough version of Xcode (so that Xcode knows about the symbol).Between the runtime check and the compile time check, we should be good right? Wrong! As it turns out, this bit of code still caused crashes on iOS 15 devices (See this Apple Forum Thread). To address this, #44185 was added which added a new compiler guard (
__OSX_AVAILABLE_STARTING(MAC_NA, IPHONE_16_4)
was added. Unfortunately, this guard is incorrect: It is basically checking if our minimum iOS deployment target is 16.4 (It's not, as of writing it is iOS 13.4), which effectively means this code is never compiled and one can never direct debug with JSC on iOS 16.4+ 😨!So what went wrong, and why were the first two guards not good enough? Three main reasons..
Firstly, this is a device only crash, and not reproducible on simulator. This is probably why the crash was not caught earlier. Secondly, It's because system frameworks (like JavascriptCore) are dynamically linked: the linker doesn't look for the symbol till runtime (and crashes when doing so). Thirdly, It's because we are strongly linking the framework, so every symbol must be present and the macros / guard Apple provides with
AvailabilityMacros.h
don't work.What we want to do is link JavascriptCore as a
weak_framework
, more info here: https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.htmlFrom that link:
This seems to be exactly what we want, and the Apple provided method for using new APIs in system frameworks!
Let's update our podspecs so we link JavascriptCore weakly. As a bonus (and admittedly, the original purpose of this PR) let's add macOS support to the
JSC_HAS_INSPECTABLE
macro (This fileJSCRuntime.cpp
used to have more explicit macOS support in it's macros, but I had removed it with fb30fca).Changelog:
[IOS] [FIXED] - Fix Direct Debugging with JSC
Test Plan:
Tested that RNTester doesn't crash on boot running on an iPad Air 2 running iOS 15.8., and that an iOS 17.2 simulator is debuggable.
Built RN-Tester and RN-Tester-macOS and verified both show up in Safari Web Inspectors' debug menu:
macOS screenshot small bc I got some internal stuff I gotta crop 😅