Compiling Swift 5.2.4 release version from source failed

Hi there. I'm trying to make a Mach-O binary parsing tool which make use of the reflection part of code in Swift repository. I tried to compile Swift 5.2.4 release version from source but the compilation always fails when the process moved to compiling Swift (LLVM is successfully compiled).

Here is what I did:

at the parent directory of Swift source directory execute

$ > ./swift/utils/update-checkout --tag swift-5.2.4-RELEASE

and then at the Swift source directory tried both ninja

$ > utils/build-script --release-debuginfo

and Xcode

$ > utils/build-script --release-debuginfo --Xcode

and all of them are failed at compiling Swift

This is the error info when build with Ninja

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.59)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode 11.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Performing C++ SOURCE FILE Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS failed with the following output:
Change Dir: /Users/wezzard/Repositories/com.github/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_169b9 && [1/2][ 50%][0.028s] Building CXX object CMakeFiles/cmTC_169b9.dir/src.cxx.o
[2/2][100%][0.047s] Linking CXX executable cmTC_169b9
FAILED: cmTC_169b9 
: && "/Applications/Xcode 11.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"  -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++14 -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 -fdiagnostics-color -DLINKER_SUPPORTS_COLOR_DIAGNOSTICS -isysroot "/Applications/Xcode 11.4.1.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_169b9.dir/src.cxx.o  -o cmTC_169b9   && :
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: /Users/wezzard/Repositories/com.github/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/local/bin/ninja cmTC_a8e08 && [1/2][ 50%][0.015s] Building CXX object CMakeFiles/cmTC_a8e08.dir/src.cxx.o
FAILED: CMakeFiles/cmTC_a8e08.dir/src.cxx.o 
"/Applications/Xcode 11.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++"    -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++14 -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 -fdiagnostics-color -Werror=switch -DCXX_SUPPORTS_WE4062 -isysroot "/Applications/Xcode 11.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk"   /we4062 -o CMakeFiles/cmTC_a8e08.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; }

This is the error info when build with Xcode:

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.59)
Target: x86_64-apple-darwin19.5.0
Thread model: posix
InstalledDir: /Applications/Xcode 11.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Performing C++ SOURCE FILE Test CXX_SUPPORTS_WE4062 failed with the following output:
Change Dir: /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/xcodebuild -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_5e8dd -configuration Debug -hideShellScriptEnvironment && Command line invocation:
    "/Applications/Xcode 11.4.1.app/Contents/Developer/usr/bin/xcodebuild" -project CMAKE_TRY_COMPILE.xcodeproj build -target cmTC_5e8dd -configuration Debug -hideShellScriptEnvironment

User defaults from command line:
    HideShellScriptEnvironment = YES

Build settings from command line:
    TOOLCHAINS = default

Prepare build
note: Using legacy build system
=== BUILD TARGET cmTC_5e8dd OF PROJECT CMAKE_TRY_COMPILE WITH CONFIGURATION Debug ===

Check dependencies

Write auxiliary files
/bin/mkdir -p /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64
write-file /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/cmTC_5e8dd.LinkFileList

CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/src.o src.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp
    /Applications/Xcode\ 11.4.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ -target x86_64-apple-macos10.15 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wno-shorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -DCMAKE_INTDIR=\"Debug\" -isysroot /Applications/Xcode\ 11.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -Wno-infinite-recursion -Wno-move -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-range-loop-analysis -Wno-semicolon-before-method-body -I/Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/Debug/include -I/Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/DerivedSources-normal/x86_64 -I/Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/DerivedSources/x86_64 -I/Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/DerivedSources -F/Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/Debug -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++14 -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 -Werror=switch -DCXX_SUPPORTS_WE4062 /we4062 -MMD -MT dependencies -MF /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/src.d --serialize-diagnostics /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/src.dia -c /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/src.cxx -o /Users/wezzard/Repositories/com.github/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp/CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/src.o
clang: error: no such file or directory: '/we4062'

** BUILD FAILED **


The following build commands failed:
	CompileC CMAKE_TRY_COMPILE.build/Debug/cmTC_5e8dd.build/Objects-normal/x86_64/src.o src.cxx normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)


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

How can I get out of this error and get Swift compiled?

Looks like another person had a similar issue here: Error building toolchain (unknown option --color-diagnostics). Did you run utils/update-checkout --tag? Otherwise, the other project repositories (llvm-project etc.) will not be at the correct tags.

Ah yes indeed. That was my fix. I had to check them out at a specific tag, and it all worked. My bad for not posting that it worked for me after.

Yes. I've execute ./swift/utils/update-checkout --tag swift-5.2.4-RELEASE just as I mentioned in my post.

Finally, I solved this issue by removing sphinx from my computer. Swift build script have bug on generating docs with sphinx, and this leads to a fatal error which causes build failures.

Terms of Service

Privacy Policy

Cookie Policy