Skip to content
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

Build fails for Xcode 15 Beta 1 (and Beta 7) #37748

Closed
below opened this issue Jun 7, 2023 · 36 comments
Closed

Build fails for Xcode 15 Beta 1 (and Beta 7) #37748

below opened this issue Jun 7, 2023 · 36 comments
Labels
Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided. Tool: Xcode

Comments

@below
Copy link

below commented Jun 7, 2023

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

@Advait1306

This comment was marked as duplicate.

@below
Copy link
Author

below commented Jun 7, 2023

facing the same issue.

Thanks you for confirming reproducibility

@Armanoide
Copy link

Armanoide commented Jun 7, 2023

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

@below
Copy link
Author

below commented Jun 7, 2023

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

@Armanoide
Copy link

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

@cipolleschi
Copy link
Contributor

@Armanoide thanks so much for the work around. We will bake this into our Cocoapods scripts... or if you have time and you want to open a PR, that's very welcome! :D

@cortinico cortinico added the Resolution: PR Submitted A pull request with a fix has been provided. label Jun 7, 2023
@Armanoide
Copy link

@Armanoide thanks so much for the work around. We will bake this into our Cocoapods scripts... or if you have time and you want to open a PR, that's very welcome! :D

i didn't have time today unfortunately but some one did 37758.
It will be soon in the next version of RN 📦

@tido64
Copy link
Collaborator

tido64 commented Jun 8, 2023

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.

@below
Copy link
Author

below commented Jun 8, 2023

@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

@tido64
Copy link
Collaborator

tido64 commented Jun 8, 2023

@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 😢

@GraxMonzo
Copy link

Hi, this problem still exists in version 0.71.10, are there plans to add this in 0.71.x?

@cipolleschi
Copy link
Contributor

@GraxMonzo: Yes, as soon as we release 0.71.11 (either this week or the next) the problem will be fixed there as well.

kelset pushed a commit that referenced this issue Jun 13, 2023
Summary:
Fixes #37748

This PR adds a patch which fixes a build issue in Xcode 15.

## Changelog:

[IOS] [ADDED] - Add support for building with Xcode 15

Pull Request resolved: #37758

Reviewed By: cortinico

Differential Revision: D46524009

Pulled By: cipolleschi

fbshipit-source-id: 9f6c12e12a15c154467282a7b4a00e80e5cc0af2
Kudo pushed a commit to expo/react-native that referenced this issue Jun 15, 2023
Summary:
Fixes facebook#37748

This PR adds a patch which fixes a build issue in Xcode 15.

## Changelog:

[IOS] [ADDED] - Add support for building with Xcode 15

Pull Request resolved: facebook#37758

Reviewed By: cortinico

Differential Revision: D46524009

Pulled By: cipolleschi

fbshipit-source-id: 9f6c12e12a15c154467282a7b4a00e80e5cc0af2
(cherry picked from commit 8ed2cfd)
@ben-haim
Copy link

ben-haim commented Jul 6, 2023

You're correct that there is no template named unary_function in the std namespace. The error message suggests using __unary_function instead

asafkorem added a commit to wix/Detox that referenced this issue Aug 2, 2023
* fix(iOS): bump `LNViewHierarchyDumper` to version 1.3.

Current version is broken with Xcode 15.0/iOS 17.

* fix(iOS): add workaround for building with Xcode 15.

See: facebook/react-native#37748.

* fix(iOS): bump `LNViewHierarchyDumper` submodule.

Fixes unrecognized selector sent to errors.
@jitanshu
Copy link

jitanshu commented Aug 3, 2023

Replacing unary_function with __unary_function worked for me

@cipolleschi
Copy link
Contributor

@marcshilling can you share the crashlog?

@cipolleschi
Copy link
Contributor

We are aware of issues related to Xcode 15, beta, especially when it comes to older iOS.
Can you try if that happens with more recent betas?

@marcshilling
Copy link

@cipolleschi this is Xcode 15 Beta 6 which is the latest, trying to run on iOS 17 Beta 6!

@cipolleschi
Copy link
Contributor

uhm... the title of the issue says Beta 1, that's why I was asking.
Anyway, in our tests, iOS 17 and Xcode beta 6 are working properly. We are having issues with Xcode 15 beta 6 and older iOSes, though... but we haven't found a solution yet, unfortunately, as, even for us, the stack trace is pretty empty...

@sthales
Copy link

sthales commented Aug 25, 2023

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

@marcshilling
Copy link

marcshilling commented Aug 25, 2023

Yeah still happening for me in beta 7 as well (the startup SIGABRT). Here's crash report. I sent it to Apple as well in case this is some beta issue 🤷

Code Type:           X86-64 (Native)
Role:                Foreground
Parent Process:      launchd_sim [26423]
Coalition:           com.apple.CoreSimulator.SimDevice.249DDD8B-78A4-4847-98B3-29645FFF9567 [76346]
Responsible Process: SimulatorTrampoline [24850]

Date/Time:           2023-08-25 16:33:58.9305 -0400
Launch Time:         2023-08-25 16:33:57.5265 -0400
OS Version:          macOS 13.5.1 (22G90)
Release Type:        User
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: OBJC 1 

Triggered by Thread:  0

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	       0x114d49a52 __abort_with_payload + 10
1   libsystem_kernel.dylib        	       0x114d6784e abort_with_payload_wrapper_internal + 82
2   libsystem_kernel.dylib        	       0x114d677fc abort_with_reason + 19
3   libobjc.A.dylib               	    0x7ff800057593 _objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) + 121
4   libobjc.A.dylib               	    0x7ff80005751a _objc_fatal(char const*, ...) + 114
5   libobjc.A.dylib               	    0x7ff80004166d load_images + 1383
6   dyld_sim                      	       0x11389509b dyld4::RuntimeState::notifyObjCInit(dyld4::Loader const*) + 359
7   dyld_sim                      	       0x11389a73c dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const + 182
8   dyld_sim                      	       0x11389d49a dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const::$_1::operator()() const + 92
9   dyld_sim                      	       0x11389a7dd dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const + 93
10  dyld_sim                      	       0x1138b03df dyld4::APIs::runAllInitializersForMain() + 263
11  dyld_sim                      	       0x11388c10a dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 2535
12  dyld_sim                      	       0x11388b356 _dyld_sim_prepare + 854
13  dyld                          	       0x117f55424 dyld4::prepareSim(dyld4::RuntimeState&, char const*) + 1490
14  dyld                          	       0x117f53abc dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) + 249
15  dyld                          	       0x117f533bd start + 1805

Edit: Confirming issue is still present with Beta 8 :(

@kelset
Copy link
Contributor

kelset commented Aug 29, 2023

reopening for now since it seems that Beta 7 is having issues

@kelset kelset reopened this Aug 29, 2023
@kelset kelset changed the title Build fails for Xcode 15 Beta 1 Build fails for Xcode 15 Beta 1 (and Beta 7) Aug 29, 2023
@cipolleschi
Copy link
Contributor

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


@Daniel-Griffiths
Copy link

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!

@NikolaSimsic
Copy link

Just to confirm that solution provided by Armanoide works smooth!

@cipolleschi
Copy link
Contributor

Manually modifying your project works, but our infra is already doing it in the react_native_post_install hook.
It calls this function which is implemented here. Make sure that you are calling the hook in your Podfile.

@humanzai
Copy link

Xcode Cloud builds with Xcode 15 fails now with the same issue on react native < 5.4.2 which doesn't have this fix and no way to insert this workaround.

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

@cipolleschi
Copy link
Contributor

@humanzai you mean that Xcode cloud can't run cocoapods? If that the case, you'll have to check into your versioning system the pods and the xcworkspace for Xcode cloud to pick up the right file.
All these configurations are applied by our Cocoapod infra.

@humanzai
Copy link

@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

@MihaiEros
Copy link

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

Thank you very much! 🍻

@kelset
Copy link
Contributor

kelset commented Sep 19, 2023

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.

atulsmadhugiri added a commit to CommE2E/comm that referenced this issue Sep 19, 2023
…o unblock iOS build

Summary:
Linear: https://linear.app/comm/issue/ENG-4984/xcode-version-15-update
GitHub: facebook/react-native#37748

---

Depends on D9227

Test Plan: iOS builds succeeds after `yarn cleaninstall` without issue.

Reviewers: ashoat, ginsu, tomek, bartek

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D9228
siddarthkay added a commit to status-im/status-mobile that referenced this issue Sep 20, 2023
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 template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
```

This commit fixes the issue and makes existing codebase compatible with newer Xcode.

reference issue in react-native repo : facebook/react-native#37748
siddarthkay added a commit to status-im/status-mobile that referenced this issue Sep 20, 2023
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 template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
```

This commit fixes the issue and makes existing codebase compatible with newer Xcode.

reference issue in react-native repo : facebook/react-native#37748
@mrlexz
Copy link

mrlexz commented Sep 20, 2023

thanks Armanoide, this worked for me!!

@Shubham0850
Copy link

Shubham0850 commented Sep 20, 2023

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

@marcshilling
Copy link

marcshilling commented Sep 20, 2023

@Shubham0850 hey, refer to this issue: mrousavy/react-native-vision-camera#1802 (comment)

this one is unrelated

@cipolleschi
Copy link
Contributor

All the fixes for Xcode 15 has landed on main and they have been cherry picked in the right branch.
Brace with us for a few days, while the Release Crew prepares new Releases for each of the supported versions (0.70, 0.71 and 0.72).

Thank you all for your patience.

@facebook facebook locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Resolution: PR Submitted A pull request with a fix has been provided. Tool: Xcode
Projects
None yet
Development

Successfully merging a pull request may close this issue.