Error compiling swift with ninja

Hi, I'm having problems when compiling swift, it fails when start compiling swift, the previous steps compile without a problem.

I execute the following:

./utils/build-script --release-debuginfo --debug-swift -c

Compiles llvm & cmake without a problem. But when start to compile swift it fails with this error:

[46/734] Generating LLVMRevision.inc
-- Found Git: /usr/bin/git (found version "2.24.1 (Apple Git-126)")
[48/734] Generating SwiftRevision.inc
-- Found Git: /usr/bin/git (found version "2.24.1 (Apple Git-126)")
[49/734] Building CXX object lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMSwiftAA.cpp.o
FAILED: lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMSwiftAA.cpp.o
/Applications/Xcode_11_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/LLVMPasses -I/Volumes/Compiler/swift/swift/lib/LLVMPasses -Iinclude -I/Volumes/Compiler/swift/swift/include -I/Volumes/Compiler/swift/llvm-project/llvm/include -I/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/llvm-macosx-x86_64/include -I/Volumes/Compiler/swift/llvm-project/clang/include -I/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/llvm-macosx-x86_64/tools/clang/include -I/Volumes/Compiler/swift/cmark/src -I/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/cmark-macosx-x86_64/src -Wno-unknown-warning-option -Werror=unguarded-availability-new -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -index-store-path "/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/IndexStore" -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -g -isysroot /Applications/Xcode_11_4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fno-exceptions -fno-rtti -Werror=gnu -target x86_64-apple-macosx10.9 -isysroot /Applications/Xcode_11_4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -arch x86_64 -F/../../../Developer/Library/Frameworks -mmacosx-version-min=10.9 -O0 -g -UNDEBUG -std=c++14 -MD -MT lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMSwiftAA.cpp.o -MF lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMSwiftAA.cpp.o.d -o lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMSwiftAA.cpp.o -c /Volumes/Compiler/swift/swift/lib/LLVMPasses/LLVMSwiftAA.cpp
error: failed writing record 'LLVMSwift.def-2FS6CZNHKB9I7': failed to rename '/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/IndexStore/v5/records/I7/LLVMSwift.def-2FS6CZNHKB9I7-temp-7aee5ccc' to '/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/IndexStore/v5/records/I7/LLVMSwift.def-2FS6CZNHKB9I7': File exists
1 error generated.
[62/734] Building CXX object lib/Syntax/CMakeFiles/swiftSyntax.dir/SyntaxNodes.cpp.o
ninja: build stopped: subcommand failed.

I don't know if is useful, but the CMakeError.log in the swift-macosx-x86_6 is the following:

Checking whether the ASM compiler is GNU using "--version" did not match "(GNU assembler)|(GCC)|(Free Software Foundation)":
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode_11_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Performing C++ SOURCE FILE Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS failed with the following output:
Change Dir: /Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_c2928 && [1/2][ 50%][0.026s] Building CXX object CMakeFiles/cmTC_c2928.dir/src.cxx.o
[2/2][100%][0.042s] Linking CXX executable cmTC_c2928
FAILED: cmTC_c2928
: && /Applications/Xcode_11_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Wno-unknown-warning-option -Werror=unguarded-availability-new -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -index-store-path "/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/IndexStore" -fdiagnostics-color -DLINKER_SUPPORTS_COLOR_DIAGNOSTICS -arch x86_64 -isysroot /Applications/Xcode_11_4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,--color-diagnostics CMakeFiles/cmTC_c2928.dir/src.cxx.o -o cmTC_c2928 && :
ld: unknown option: --color-diagnostics
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Source file was:
int main() { return 0; }
Performing C++ SOURCE FILE Test CXX_SUPPORTS_WE4062 failed with the following output:
Change Dir: /Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_a642e && [1/2][ 50%][0.013s] Building CXX object CMakeFiles/cmTC_a642e.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_a642e.dir/src.cxx.o
/Applications/Xcode_11_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Wno-unknown-warning-option -Werror=unguarded-availability-new -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -index-store-path "/Volumes/Compiler/swift/build/Ninja-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-x86_64/IndexStore" -fdiagnostics-color -Werror=switch -DCXX_SUPPORTS_WE4062 -arch x86_64 -isysroot /Applications/Xcode_11_4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk /we4062 -std=c++14 -o CMakeFiles/cmTC_a642e.dir/src.cxx.o -c src.cxx
clang: error: no such file or directory: '/we4062'
ninja: build stopped: subcommand failed.

Source file was:
int main() { return 0; }

I'm using xcode 11.4, on Catalina 10.5.5

EDIT: I'm on master. In the commit:

Merge: b25dab29254 f9128bac810
Author: Saleem Abdulrasool compnerd@compnerd.org
Date: Thu Jun 4 13:43:58 2020 -0700

Merge pull request #32182 from compnerd/uniformity

build: use the same pattern for detecting Darwin platforms

Xcode 11.4
Build version 11E146

cmake version 3.17.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).

1 Like

Supposedly adding --xcode parameter should fix it for the build-script: Swift compilation failed - #14 by yasserdeceukelier

I'm also facing it, but I'm facing it when building toolchains: ./swift/utils/build-toolchain

I'm not sure how to add this parameter to that. Any suggestions?

I don’t want to compile with xcode. I want to use ninja.

Edit: building toolchain doesn’t support (I believe) Xcode.