Having an issue when building for release for Apple Watch any Apple platform with xcodebuild
from the command line with Xcode 10.2 and Swift 5.
$ xcodebuild -scheme MyApp-watchOS -configuration Release -destination 'OS=latest,name=Apple Watch Series 2 - 38mm' build analyze
[...]
error: Bus error: 10
<unknown>:0: error: unable to execute command: Bus error: 10
<unknown>:0: error: compile command failed due to signal 10 (use -v to see invocation)
[...]
The following build commands failed:
CompileSwift normal i386
CompileSwiftSources normal i386 com.apple.xcode.tools.swift.compiler
(2 failures)
I've tried with different simulators, but the error persist, both for build
and analyze
commands.
Building from Xcode works fine in Debug model, but fails in Release mode.
CompileSwiftSources normal i386 com.apple.xcode.tools.swift.compiler (in target: MyApp-watchOS)
[...]
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: compile command failed due to signal 4 (use -v to see invocation)
and
CompileSwift normal i386 (in target: MyApp-watchOS)
[...]
error: Illegal instruction: 4
Cleaning DerivedData didn't help in this case.
After much debugging, commenting out code and trying different project settings, I found the file causing the issue is this MD5 hash we use to compare files on disk: https://github.com/onmyway133/SwiftHash/blob/master/Sources/MD5.swift
Removing that file (and callers) from the target makes the compiler happy, but that is not an option.
Meanwhile, I also found the Swift 5 compiler does not crash when setting the "Optimization Level" to "Optimize for Size", so we will use that option for now.