Swift Compilation Hangs on Release Builds

I'm getting an issue where compiling both my macOS and iOS frameworks in Release modes (i.e., Archive) in Xcode 10.2. This happens with both Swift 4.2 and with Swift 5. I can get it to stop hanging by either:

  • Changing Compilation Mode from Whole Module to Incremental
  • Changing Optimization Level from Optimize for Speed to either Optimize for Size or No Optimization


Does anyone know what may be going on here? Is there a likely culprit in my codebase or is this just a compiler bug?

Replies

Just tried on Xcode GM Seed 2...STILL doesn't work

To be honest I think this is being caused by Firebase. In my case it hangs on a Firebase compiling step, and I've seen other people with similar issues. Builds well for debug, not for release.

In my case it gets stuck archiving either Realm or Charts

This is clearly an XCode bug.

Regardless of the pods or module, Archive should either fail with a clear message or complete.

This is still hapenning to me with XCode 11 release build.


This is a pain in the neck because it means I cannot publish my app with support for iOS13 features such as dark mode.


Has anyone found a workarround ?

Not really adding anything other than to register that we are also suffering this issue. Debug build works fine, Release hangs with no obvious workable solution. I have tried pod deintegrate and pod install but no change, still fails to build and hangs at the same point. I have raised and issue, FB7315222.

So actually this seems to be fixed on apple side

https://github.com/apple/swift/commit/378c6adbd625f1c1f568fa28116be3335506082f#diff-8b0154fba360507e6f59f3a0c8e98d1a


However who knows when this will be part of Xcode. Most probably only when Swift 5.1 is released. Unlike my previous comment this actually seems a problem with the SwiftSoup library. Mayhap you people are also using it?


Anyway if you are using SwiftSoup and CocoaPods like I was, make sure you disable Optimization Level by changing it from Optimize for Speed to No Optimization ON THE AFFECTED LIBRARY, in this case SwiftSoup.


This solved my issue, and the builds no longer freeze. I'll have to live with this for now until the Swift fix gets it's way into Xcode or i have time to migrate to another library.


NOTE: Mayhap your culprit library is another one. Please identify it by carefully examining the build log. Then follow this instructions by replacing SwiftSoup with the library which is actually causing the issue.



I did this by adding the following to my Podfile:


post_install do |installer|

installer.pods_project.targets.each do |target|

if ['SwiftSoup'].include? target.name

target.build_configurations.each do |config|

config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'

end

end

end

end

Same thing is happening to me with xcode 11. Hangs forever at the end of archiving and never gets past it. In my case, its hanging on Alamofire.

j.santos.f's reply pointed me to the right direction. Thanks for that.


In my case, the build hangs on my own project, not on a Carthage/Cocoapods dependency. While it is a compiler bug for the compiler to hang, it might still be a bug in your code that causes this (like in mine).


The compiler bug that was fixed is this one: https://bugs.swift.org/browse/SR-11010

Going from the example in the bug report, I checked the places where I was using a while loop. Turns out I have a similar while loop that was looking up super views.


var cell = self.superview
while !(cell is UITableViewCell) {
     cell = cell?.superview
}
return cell as? UITableViewCell


Thewhile loop will go forever if `cell` is nil. So the fix is:


var cell = self.superview
while cell != nil && !(cell is UITableViewCell) {
     cell = cell?.superview
}
return cell as? UITableViewCell


With this code change, archiving works with the Optimized for Speed (-O) option.


Hopefully this could help you if you have something similar, or at least point you to the right direction.

Hi guys, does anyone have an update for this?


I also posted on stackoverflow: https://stackoverflow.com/questions/58286522/xcode-11-product-archive-stuck-on-notification-extension

You saved my day! Thanks!

I still have this bug, but after removing optimisation for SwiftSoup pod (https://stackoverflow.com/a/58355036/3283808), I manager to Archive

The issue I had was with a piece of my own (shoddy) code. Apple support provided the following which allowed me to locate the failing class and, following a rewrite, I can now release.


1. Open Activity Monitor.

2. Start your project building.

3. Wait for the the build’s progress to completely stop for several minutes.

4. Locate the Swift processes in Activity Monitor (they should be using nearly 100% CPU) and select one of them.

5. In the menu bar, select “View”, then “Send Signal To Process…”

6. Select “Abort (SIGABRT)” from the drop-down list.

7. Click the “Send” button. This will simulate an assertion failing, so the compiler will print information about what it’s doing and then exit.

8. In Xcode, switch to the Report Navigator (the “speech bubble” button over the left-side pane) and select the build.

9. Scroll down to the now-failed compilation step and click the transcript button (button with five lines, to the right of the “Compile [Filename]” line).

10. Scroll down to see the diagnostic information. It will probably include a list of command-line flags, a few lines saying things like “In pass SimplifyCFG”, and a stack trace.

This works for me too 👍