Repository navigation
fix(ios): patch nitro so Xcode 27 builds launch on iOS below 18 - #409
Conversation
iOS builds made with Xcode 27 crash at launch on iOS 15.1 to 17.x with a dyld error: Symbol not found std::exception_ptr::__from_native_exception_pointer. react-native-nitro-modules 0.37.1 calls std::make_exception_ptr in the inline makeException helper, which is emitted through Swift C++ interop. With Xcode 27 that path references libc++ symbols that only exist on iOS 18 and later. Patch the helper to throw and catch, returning std::current_exception(). This matches the upstream fix shipped in react-native-nitro-modules 0.37.2 (margelo/nitro#1652).
|
@catch-21, this is just a small patch to prevent the crash and get things running. We could upgrade react-native-nitro-modules entirely, but that may require more testing/troubleshooting. |
coreyphillips
left a comment
There was a problem hiding this comment.
Two independent reviews, nothing blocking a merge.
worth doing, does not block
- Patch omits upstream 0.37.2's matching fix in Promise::~Promise() (patches/react-native-nitro-modules+0.37.1.patch:1)
- Backport omits the Swift Promise part of the upstream fix (patches/react-native-nitro-modules+0.37.1.patch:14)
| @@ -0,0 +1,22 @@ | |||
| diff --git a/node_modules/react-native-nitro-modules/ios/utils/RuntimeError.hpp b/node_modules/react-native-nitro-modules/ios/utils/RuntimeError.hpp | |||
There was a problem hiding this comment.
worth doing, does not block: Patch omits upstream 0.37.2's matching fix in Promise::~Promise()
The PR describes this as the same change upstream shipped in 0.37.2, but upstream changed two places and this patch only covers makeException. 0.37.2 also rewrote the destructor in cpp/core/Promise.hpp, which in 0.37.1 still calls std::make_exception_ptr: diff ~Promise() { if (isPending()) [[unlikely]] { auto message = ...; - reject(std::make_exception_ptr(std::runtime_error(message))); + try { + throw std::runtime_error(message); + } catch (...) { + reject(std::current_exception()); + } } } Promise.hpp and PromiseHolder.hpp are public headers exposed to Swift. I built a repro with Xcode 27.2 (swiftc -target arm64-apple-ios15.1-simulator -cxx-interoperability-mode=default -explicit-module-build). A Swift caller that creates and drops a template with this destructor pattern references both __ZNSt13exception_ptr31__from_native_exception_pointerEPv and ___cxa_init_primary_exception. The patched makeException form references neither. It is latent today. No Swift code in nitro 0.37.1 or react-native-mmkv 4.3.2 uses PromiseHolder or the C++ Promise, which fits the author's finding that the patched binary is missing no symbols. But any nitro-based module with a Promise-returning Swift method, added before the upgrade to 0.37.2, would bring the iOS 15.1 to 17.x launch crash back. CI builds with Xcode 26, so it would not catch that. Adding the second hunk makes the patch match upstream and closes the gap.
There was a problem hiding this comment.
Addressed in 30f31f5. Added the upstream Promise<T> destructor change from margelo/nitro#1824, so the patch now matches 0.37.2. Rebuilt with Xcode 27.2: no libc++ imports missing against iOS 17.4, and the app launches on iOS 17.4 and 27.2 simulators.
| + // interop with Xcode 27, it references std::exception_ptr::__from_native_exception_pointer and | ||
| + // __cxa_init_primary_exception, which only exist in the iOS 18+ libc++. Apps that support older | ||
| + // iOS versions then fail to launch with a dyld "Symbol not found" error. | ||
| + // Upstream fix (react-native-nitro-modules 0.37.2): https://github.com/margelo/nitro/issues/1652 |
There was a problem hiding this comment.
worth doing, does not block: Backport omits the Swift Promise part of the upstream fix
The backport leaves both iOS 18-only imports in Nitro's Swift Promise bridge. I confirmed this by compiling a Swift caller of PromiseHolder<int>::create() against the patched package with Xcode 27.2 and an iOS 15.1 target. Ring's current MMKV bindings are synchronous, so this does not block the release. Describe the patch as the RuntimeError workaround or include the upstream Promise<T> destructor change. Upstream fix
There was a problem hiding this comment.
Addressed in 30f31f5. The patch now includes the upstream Promise<T> destructor change as well, and I updated the PR description to cover both parts of the upstream fix.
The upstream 0.37.2 fix (margelo/nitro#1824) changed two Swift-visible helpers: makeException in RuntimeError.hpp and the Promise<T> destructor in Promise.hpp. The previous commit only covered makeException. No Swift code in the app reaches the Promise destructor today, but any Nitro module with a Promise-returning Swift method would bring back the launch crash on iOS below 18. Apply the same throw and catch change there so the patch matches upstream.
|
This is the right fix and looks safe to merge. The crash is real. With Xcode 27, The patch matches the upstream 0.37.2 fix. Both
When |
Summary
react-native-nitro-modules0.37.1 so iOS builds made with Xcode 27 launch on iOS versions below 18.makeExceptioninios/utils/RuntimeError.hppand thePromise<T>destructor incpp/core/Promise.hpp. Patching instead of upgrading keeps the 2.1 release small, since 0.37.2 adds a newnitro-coredependency and restructures the package.Problem
The v2.1 RC (#408) built with Xcode 27 crashes immediately on launch on older iPhones. On an iOS 17.4 simulator, dyld kills the app before any app code runs:
The reference comes from
libNitroModules.a(RuntimeError.o). Nitro's SwiftError.toCpp()calls the inline C++ helpermargelo::nitro::makeException, which usesstd::make_exception_ptr. Emitted through Swift C++ interop with Xcode 27, that path referencesstd::exception_ptr::__from_native_exception_pointerand__cxa_init_primary_exception, which only exist in the iOS 18+ libc++.The
Promise<T>destructor inPromise.hppuses the same pattern and is also visible to Swift. Nothing in the app reaches it from Swift today, so it is not part of the current crash. But any Nitro module with a Promise-returning Swift method would bring the crash back, so it is patched too.Our deployment target is iOS 15.1, so every device on iOS 15.1 to 17.x is affected. CI still builds with Xcode 26, which is why it was not caught there.
Fix
In both places, replace
std::make_exception_ptrwith athrowpluscatch (...)that usesstd::current_exception(), which is available on every supported iOS version. This matches the upstream change.Testing
Release build for the iOS simulator with Xcode 27.2 (27B52), launched on fresh simulators:
Promise.hppchange, rebuilt and confirmed again: no missing symbols, and the app launches on iOS 17.4 and 27.2.patch-packageapplies cleanly on install.Follow ups
react-native-nitro-modules0.37.2 or later.