CompileC fails when building Swift

I've been building Swift using the instructions from swift/GettingStarted.md at main · apple/swift · GitHub. When I tried to execute the following (from the actual build section):

utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping --test \
  --xcode

The build fails, when I tried to rebuild, I got

The following build commands failed:
	CompileC <path to swift-project>/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/unittests/Reflection/Swift.build/RelWithDebInfo/SwiftReflectionTests.build/Objects-normal/x86_64/TypeRef.o <path to swift-project>/swift/unittests/Reflection/TypeRef.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
ERROR: command terminated with a non-zero exit status 65, aborting
Full stderr
+ /usr/libexec/PlistBuddy -c 'Print :SupportedTargets:macosx:Archs' /Applications/Xcode12.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/SDKSettings.plist
+ mkdir -p <path to swift-project>/build/Xcode-RelWithDebInfoAssert
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/cmark-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/cmark-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo -- -parallelizeTargets -jobs 4 -target ALL_BUILD
+ ln -s -f /Applications/Xcode12.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../../usr/include/c++ <path to swift-project>/build/Xcode-RelWithDebInfoAssert/llvm-macosx-x86_64/include
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/llvm-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/llvm-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo -- -parallelizeTargets -jobs 4 -target ALL_BUILD
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo -- -parallelizeTargets -jobs 4 -target ALL_BUILD -target swift-test-stdlib-macosx-x86_64
+ /usr/local/bin/cmake --build <path to swift-project>/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64 --target ZERO_CHECK --config RelWithDebInfo -- -parallelizeTargets -jobs 4 -target SwiftUnitTests
** BUILD FAILED **


The following build commands failed:
	CompileC <path to swift-project>/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/unittests/Reflection/Swift.build/RelWithDebInfo/SwiftReflectionTests.build/Objects-normal/x86_64/TypeRef.o <path to swift-project>/swift/unittests/Reflection/TypeRef.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
ERROR: command terminated with a non-zero exit status 65, aborting

Does anyone have any idea how to troubleshoot this?

In case it helps, the env I've been using is

  • macOS 11.2 (Big Sur)
  • Xcode 12.3 (I also tried Xcode 12.4)
  • cmake 3.19.4
  • python3 3.9.1
  • ninja 1.10.2
  • sccache 0.2.15

PS

While I'm at it, has anyone been compiling with Xcode 12.4? Is there any issue?

We have seen this same/similar issue in other thread "gtest/gtest.h" not found in TypeRef.cpp while compiling the compiler

@typesanitizer, have you already seen something related?
As in the other thread I don't know the exact problem but I would suggest to build without --test flag to see if it may be a workaround...

Hi @Lantua,

I'm the creator of the thread

I came across the same error days ago, and if it's OK with you to do this, I would suggest you trying to do a clean build using ninja rather than using Xcode.

I didn't try removing the --test flag when building with Xcode (You can try this though) but I want to say that building with ninja really made everything work fine.

By the way, I'm using Xcode 12.4 as well

Hope this can help you.

Can confirmed that I can build w/o test successfully. Thanks!

Thanks for the idea. I think I'll also try to do the ninja+xcode setup since I really want Xcode env.

2 Likes

Awesome :)
This is just a work around, we still need to figure out what is the issue with --test failures. I think it should work out of the box, so we need to figure this out and or fix an issue or if there is an extra step/config required in order for this to work we need to document it...

Glad to hear you solved your problem~

I'm getting the exact same error trying to build Swift with Xcode 12.5, does someone know a fix for it?