react-native: Build fails for Xcode 15 Beta 1 (and Beta 7)
Description
When building with Xcode 15 Beta 1, building fails with a C++ issue in boost:
› Compiling react-native Pods/RCT-Folly » json.cpp
❌ (ios/Pods/boost/boost/container_hash/hash.hpp:131:33)
129 | #else
130 | template <typename T>
> 131 | struct hash_base : std::unary_function<T, std::size_t> {};
| ^ no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
132 | #endif
133 |
134 | struct enable_hash_value { typedef std::size_t type; };
Apparently, boost 1.8x does not have this issue and builds correctly. However, react-jsi currently does not work with boost 1.8x due to breaking changes.
React Native Version
0.71.8
Output of npx react-native info
>> npx react-native info
info Fetching system and libraries information...
System:
OS: macOS 13.4
CPU: (10) arm64 Apple M1 Pro
Memory: 124.09 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.4.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 9.6.5 - /opt/homebrew/bin/npm
Watchman: Not Found
Managers:
CocoaPods: 1.12.1 - /opt/homebrew/lib/ruby/gems/3.1.0/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
Android SDK: Not Found
IDEs:
Android Studio: 2022.1 AI-221.6008.13.2211.9619390
Xcode: 15.0/15A5160n - /usr/bin/xcodebuild
Languages:
Java: javac 19 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.2.0 => 18.2.0
react-native: 0.71.8 => 0.71.8
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Steps to reproduce
- Prerequisite: On a machine running macOS, ensure that Xcode 15 is installed
- Download or clone this Sample
cd react-Xcode15Bug
npm install && (cd ios && pod install)
Then either:
yarn ios
Or
xed ios
and build with Xcode
Snack, code example, screenshot, or link to a repository
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 18
- Comments: 36 (10 by maintainers)
Commits related to this issue
- Add support for building with Xcode 15 (#37758) Summary: Fixes https://github.com/facebook/react-native/issues/37748 This PR adds a patch which fixes a build issue in Xcode 15. ## Changelog: [IOS]... — committed to facebook/react-native by AlexanderEggers a year ago
- Add support for building with Xcode 15 (#37758) Summary: Fixes https://github.com/facebook/react-native/issues/37748 This PR adds a patch which fixes a build issue in Xcode 15. ## Changelog: [IOS]... — committed to expo/react-native by AlexanderEggers a year ago
- fix(iOS): add workaround for building with Xcode 15. See: https://github.com/facebook/react-native/issues/37748. — committed to wix/Detox by asafkorem a year ago
- fix(iOS): ensure compatibility with Xcode 15. (#4152) * fix(iOS): bump `LNViewHierarchyDumper` to version 1.3. Current version is broken with Xcode 15.0/iOS 17. * fix(iOS): add workaround for b... — committed to wix/Detox by asafkorem a year ago
- fix(iOS): ensure compatibility with Xcode 15. (#4152) * fix(iOS): bump `LNViewHierarchyDumper` to version 1.3. Current version is broken with Xcode 15.0/iOS 17. * fix(iOS): add workaround for b... — committed to wix/Detox by asafkorem a year ago
- [iOS] Set `_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION` flag to unblock iOS build Summary: Linear: https://linear.app/comm/issue/ENG-4984/xcode-version-15-update GitHub: https://github.com/fac... — committed to CommE2E/comm by atulsmadhugiri 9 months ago
- add support for Xcode 15 After upgrading to Xcode 15 make run-ios would fail with ``` ❌ /Users/siddarthkumar/code/status-im/PR/status-mobile/ios/Pods/boost/boost/container_hash/hash.hpp:131:33: no t... — committed to status-im/status-mobile by siddarthkay 9 months ago
- add support for Xcode 15 (#17343) After upgrading to Xcode 15 make run-ios would fail with ``` ❌ /Users/siddarthkumar/code/status-im/PR/status-mobile/ios/Pods/boost/boost/container_hash/hash.hpp:... — committed to status-im/status-mobile by siddarthkay 9 months ago
you’re right @below to notice that Pods is re-generated. To complete answer this should be added in podfile
what happening
unary_function and binary_function are no longer provided in C++17 and newer Standard modes. They can be re-enabled with _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION.
release note xcode 15
What must be done
all library must update their code to use
std::function
&std::bind
instead ofunary_function
Workaround
_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
tested on Xcode 15 with react-native 0.71.7
btw folks, we are going to release new patches for all the versions in the support window with fixes for Xcode 15. @cipolleschi has already added comments in all the patches discussion with the links to the commits to pick.
Replacing
unary_function
with__unary_function
worked for meSame issue here. iOS 17 beta 7. xCode 15 beta 7.
@GraxMonzo: Yes, as soon as we release 0.71.11 (either this week or the next) the problem will be fixed there as well.
@marcshilling thanks for doing that. Keep us updated on how it goes. I plan to do the same today, hopefully, the more error they receive the more pressured they may feel
@sthales I’ll try again, but on my test it was working on iOS 17.0
Meanwhile, I made some investigation.
Combination Broken vs Working
What’s the issue
What got broken is in how C++ allocates memory.
In the latest versions, I can trigger the crash on iOS 14.5 with a simple:
The first stack trace reported the issue with Folly, specifically the AccessSpreaderStaticInit. Fun fact, we don’t need the
CacheLocality
in React Native.I made a test by removing that file from the Folly’s Podspec: React Native still builds, but it also still crash. In this situation, we don’t have any code coming from the framework.
I tried to reproduce the issue in a native iOS project without React Native: it does not crash.
There is something within React Native that tampers with how the memory is allocated in iOS 14.5, but I couldn’t pin what it is specifically.
Just to confirm that solution provided by Armanoide works smooth!
Can confirm this worked for me, thanks!
Had a quick look myself.
std::unary_function
was removed in 2019, but Boost didn’t bumpContainerHash
until last December 😢Do we have a separate task for upgrading Boost to a version that doesn’t use
std::unary_function
? I would imagine that we won’t be able to even turn this on in a future version.Thank you @Armanoide for pointing this out. In production, this will usually be have to be done via a post-install script in the
Podfile
, as the Pods are often re-generated.The other workaround is to patch
hash.hpp
locally@Shubham0850 hey, refer to this issue: https://github.com/mrousavy/react-native-vision-camera/issues/1802#issue-1896584069
this one is unrelated
Hi, I encountered the same problem today after updating my iPhone to iOS 17 and Xcode to 15.0. I managed to fix the iOS build failure by replacing ‘unary_function’ with ‘__unary_function’. However, when I tried running the app on my iOS 17 (iPhone 13), I got a ‘Paused app on iPhone’ message and the app didn’t start.
React native Version:
react-native@0.71.7
Here are the SS
@cipolleschi Thanks for the clarification! For future reference to anyone: If you have your own pods in the project, this workaround should be applied on the “projectname.xcodeproj” configurations. That way when adding the flag on preprocessors macros through the UI, the projectname.xcodeproj will be updated - you can commit the file to your git repository which is connected to Xcode cloud and it will fix the issue.
For third party Pods, This solution did the trick for me:
Thanks everyone
reopening for now since it seems that Beta 7 is having issues
@cipolleschi this is Xcode 15 Beta 6 which is the latest, trying to run on iOS 17 Beta 6!