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

https://github.com/below/react-Xcode15Bug

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 18
  • Comments: 36 (10 by maintainers)

Commits related to this issue

Most upvoted comments

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

you’re right @below to notice that Pods is re-generated. To complete answer this should be added in podfile

  post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
        end
      end
  end

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 of unary_function

Workaround

  • Select Pods > Build Settings > In section Apple Clang - Preprocessing > under Macro section
  • add in release & debug _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
Capture d’écran 2023-06-07 à 11 45 43

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 me

@cipolleschi I don’t know how to print a better crash log than this. Again it only happens when running/debugging through > Xcode. Execution just stops as soon as the app launches with this SIGABRT:

Same 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

Xcode \ iOS iOS 14.5 iOS 15.0 iOS 16.0 iOS 17.0
Xcode 15 beta 1
Xcode 15 beta 2
Xcode 15 beta 3* N/A N/A N/A N/A
Xcode 15 beta 4
Xcode 15 beta 5
Xcode 15 beta 6
Xcode 15 beta 7
  • Xcode 15 Beta 3 can’t be downloaded, the archive is corrupted somehow. So, it is broke either in beta 3 or beta 4.

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:

shared_ptr<string> strPtr = make_shared<string>("");

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!

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 of unary_function

Workaround

  • Select Pods > Build Settings > In section Apple Clang - Preprocessing > under Macro section
  • add in release & debug _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION
Capture d’écran 2023-06-07 à 11 45 43 tested on Xcode 15 with react-native 0.71.7

Can confirm this worked for me, thanks!

@tido64 As of my quick research, boost 1.8.x no longer uses std::unary_function. And yes, this would be the preferable solution to setting options in the Podfile

Had a quick look myself. std::unary_function was removed in 2019, but Boost didn’t bump ContainerHash 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

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. Screenshot 2023-09-20 at 7 51 40 PM

React native Version: react-native@0.71.7

Here are the SS

Screenshot 2023-09-20 at 7 50 00 PM Screenshot 2023-09-20 at 7 50 36 PM Screenshot 2023-09-20 at 7 50 59 PM

@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. image

For third party Pods, This solution did the trick for me:

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

you’re right @below to notice that Pods is re-generated. To complete answer this should be added in podfile

  post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', '_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION']
        end
      end
  end

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!