The one year game develpoment duel
Dec

21

2014

Joy of Debugging: Command swiftc failed with exit code 1

I’ve been working through a particularly nasty issue, so it feels right to document it for anyone else who encounters it. Also, just to serve as a note and reminder that game development is full of unexpected, time consuming tasks on a near weekly basis. This most recent problem — releasing a build to an iOS device fails to compile, but it works on the simulator. Specifically, this occurs when I try to change the Swift compiler optimization level.

Command /Applications/...../XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

Unfortunately, no line number accompanies this issue. Stack Overflow is full of potential causes like missing resource, deleting derived data, or codesign issues. Unfortunately, none of those worked for me. (Side note: two of those links are not swiftc errors. They are clang, and swift-stdlib-tool commands. In my frustration I overlooked that.) However, I did stumble across this wonderful post explaining how to get more information from the build. Going forward with the command line approach, a helpful error message is visible at the bottom of the output:

** BUILD FAILED **

The following build commands failed:

    CompileSwift normal arm64 /Users/veeneck/Documents/Games/Xcode/Fort/Fort/PinchGesture.swift

    CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler

That shows me that PinchGesture.swift is the culprit. You can get similar help from Xcode, but it is not as clear. You have to scan each individual file in the output for errors instead of just jumping to the bottom. In any case, if you’re interested in that approach, show all messages in the output like so. Notice the error in the same file, but this time it may read:

LLVM ERROR: Broken function found, compilation aborted!

Now that the error has been isolated, let’s fix the code. I was able to fix this by trial and error, and I still don’t fully understand the differences, but here goes. My original function:

And now the new function. Notice that I changed the variable to not be editable, and to return within the if statements.

Definitely an interesting bug, and anything you encounter will most likely be a different sort of issue. But, now we know how to track something like this down.

5 of you did not hold your tongue!
  1. Thanks to the pointer to that command line build Stack Overflow question. It appears that using min() or max() with values that were nil coalesced broke the compiler when the optimisation level was fastest. Hey ho!

  2. […] the answer to that determines a lot about how my game will flow. After a week of focusing on this, optimizing the compiler, testing different approaches, and going through the code piece by piece, I can support ~90 units […]

  3. Ah, good to know. Thanks for the tip.

  4. […] just wanted to make a quick note here that there has been a lot of progress on that front. Between Swift compiler optimizations and caching enumerateChildNodesWithName, I’ve seen significant […]


Speak Freely


Thank you

Your comment will be published once it has been approved.

Click here to see the pull request you generated.