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.

is this just a compiler bug?

A build system hang is always the build system’s fault. It should either run to completion or tell you what’s gone wrong (for example, if you have a circular dependency).

My recommendation is that you file a bug against Xcode. If you can include a project that reproduces the problem, that’d be ideal. If not, please include a sysdiagnose log taken during the hang.

Please post your bug number, just for the record.

ps You can learn more about sysdiagnose logs on our Bug Reporting > Profiles and Logs page.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

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.

For what it's worth - my project has a similar hierarchy of frameworks being built.

Our project also has a similar structure. Did restructuring things happen to fix anything for you?


EDIT: I'm not sure if this is helpful, but sampling the "hung" (100% CPU in a loop?) compiler process looks something like this (multiple samples all look similar): https://pastebin.com/wSAN253n

I'm facing the same issue - however with only one framework involved. It consistently hangs with the step "Touch" when building the framework. The only ways to build an archive are:

- switching optimization for speed off (not really a solution)

- moving all files from the framework to the project before building the archive (inconvenient).

Yes, restructing my project to this resolved the issue for me.


/Main Project (has framework 2's files inside)

|-- framework 1

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.

Same issue? I can fix it with switching off optimization. Is this affecting my app in any way?

I'm having the same problem. 😠

Had to downgrade to Xcode 10.1

Not sure you can downgrade. But you may look for a 10.1 ß

XCode 10.2.1 resolved this issue for me. There is a note about Apple fixing swift building for large projects. I am able to build again with optimizations enabled.

Xcode 10.2.1 resolved this issue for me.

Yay! Thanks for letting us know.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Not here. We're trying to migrate and even after giving it a night (16hours) the swift process was still running and the build was still not completed...


Incremental and No Optimization seems to work for now, but that is far from ideal :/

Same here, even with xcode 10.2.1 this is still broken for me.

Swift Compilation Hangs on Release Builds
 
 
Q