Re: 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?

I have the same issue. Things worked fine in XCode 10.1. Tried using old build system and same result, seems to get stuck in the same place each time in terms of task number, but unclear what files are apart of that task.

Changing Compilation Mode from Whole Module to Incremental does NOT solve it for me, the build gets a lot further, but still ends up hanging. Changing Optimization Level from Optimize for Speed to either No Optimization does resolve it, but this isn't really a solution in my opinion.

I made an interesting discovery last night. My project has two frameworks and framework 2 uses framework 1 as does the project. Hierarchy looks like this:

/Main Project

|-- framework 2

| `-- framework 1

|-- framework 1

If instead of having the code in those frameworks I put all the code directly into Main Project I can build just fine so there is some issue with using frameworks. I am able to archive framework 2 without issue, the part where it hangs is somewhere when the build system goes to compile the Main Project after compiling both frameworks. If I look in the biuld output the part it hangs on is Compile Swift Source Files of Main Project.

Is there a way we can get XCode to spit out more debug information or any other advice for trying to figure out what is choking the build system? My project gets stuck in the same spot each time task 192 of 229.

It would be terribly inconvenient for us to do this unfortunately. We have a large number of common obj-c and swift files that actually need to be referenced by multiple frameworks + targets, so frameworks are a pretty nice solution to the problem. Hopefully Apple is able to get a patch out soon.

I have downgraded from 10.2.1 to 10.1 and from 10.3 to 10.1. Just download the 10.1 version, unpack it, and replace the existing xcode app with the one you downloaded.

I have the same problem. I can't troubleshoot the issue after trying many things in this thread and others. I found that the build doesn't hang in Xcode 11 beta 4. So I will continue to submit apps to the App Store with Xcode 10.1 until Xcode 11 is officially released, hoping that the released version doesn't bring the issue back.

Reading through the analysis so far, there’s a possibility that this is being trigger by the Exclusive Access to Memory (SWIFT_ENFORCE_EXCLUSIVE_ACCESS) build setting. The default value for this is Full Enforcement (Runtime Checks in All Builds). If you flip that to Full Enforcement (Runtime Checks in Debug Builds Only), do you still see the hang?

Still seeing a hang by setting Exclusive Access to Memory to Full Enforcement (Runtime Checks in Debug Builds Only). Also have tried adjusting Optimization Level and Compilation Mode as suggested to no avail...

Hi! I'm facing the same issue with release builds, and enabling runtime checks in debug builds only makes the build complete as usual. As far as I understand this is a workaround, but is there something I can do/investigate in my project/sources to fix it? Or is it something related to the build system I cannot do anything about?

We found that to be the case – changing the exclusive access to memory setting from Runtime Checks in All Builds to Runtime Checks in Debug Builds Only made our compiles finish again. We didn't see this issue in Xcode 10.1, but it might be because the setting wasn't enabled by default back then (see this nice table someone made).

Just figured I'd share – we tried a bunch of different combinations of optimization settings, and the exclusive access to memory definitely seemed to be the culprit (are stalling builds, are passing)

i just tried to run our release process with Xcode 10.3 in the hopes of getting this resolved but the release build still gets stuck at the same position. We are still building our tvOS releases on Xcode 10.1. Looking forward to a fix for this hopefully soon.

My understanding is that Xcode 10.3 is a minor update whose primary focus is on shipping new SDKs. I had a look at a few of the bugs mentioned on this thread and it seems that any fixes are targeting Xcode 11. Are you see this problem on the Xcode 11.0 beta release?

IMPORTANT One thing that I didn’t make clear in that post is that you should file a bug about this even if there are other existing bugs on file. There’s two reasons for this:

There have been multiple causes of these hangs, and it’s important to make sure that yours is covered.

The person filing the other bug may not have been able to include a project that reproduces the problem, which makes it much harder to investigate. The project you attach could make all the difference.

Filed a bug report with a sample project. Basically it is a new project with few dependencies installed using CocoaPods. Able to build for debug but not able to archive (Stuck on "Touch" for a long time).

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.

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.

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

More Like This

Retrieving data ...

This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Developer Forums Participation Agreement.