Swift compilation failed

I cloned the source from GitHub and when I run this command,
utils/build-script --release-debuginfo

it’s giving an error.

-- Swift Benchmark Suite:
--   SWIFT_EXEC = /Volumes/SSD-KSVSK/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/swiftc
--   SWIFT_LIBRARY_PATH = /Volumes/SSD-KSVSK/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift
--   CLANG_EXEC = /Library/Developer/CommandLineTools/usr/bin/clang
--   ONLY_PLATFORMS = macosx;iphoneos;appletvos;watchos
--   found platforms: macosx
--   found sdks:
--     /Library/Developer/CommandLineTools/SDKs/MacOSX10.13.sdk
CMake Warning at docs/CMakeLists.txt:130 (message):
  LitRe not found; code examples won't be tested.

-- Configuring incomplete, errors occurred!
See also "/Volumes/SSD-KSVSK/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeOutput.log".
See also "/Volumes/SSD-KSVSK/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeError.log".
utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting
KUSHALs-MacBook-Pro:swift-master kushalksvs$ utils/build-script --release-debuginfo

These are the last few lines in the output.
Also This is CMakeError.log

Performing C++ SOURCE FILE Test LINKER_SUPPORTS_COLOR_DIAGNOSTICS failed with the following output:
Change Dir: /Volumes/SSD-KSVSK/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/CMakeFiles/CMakeTmp

Run Build Command:"/usr/local/bin/ninja" "cmTC_a55fe"
[1/2] Building CXX object CMakeFiles/cmTC_a55fe.dir/src.cxx.o
[2/2] Linking CXX executable cmTC_a55fe
FAILED: cmTC_a55fe 
: && /Library/Developer/CommandLineTools/usr/bin/clang++  -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fcolor-diagnostics -DLINKER_SUPPORTS_COLOR_DIAGNOSTICS -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ -Wl,--color-diagnostics CMakeFiles/cmTC_a55fe.dir/src.cxx.o  -o cmTC_a55fe   && :
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; }

What to do now ?
I did this following the README.

What version of Xcode are you using to try to build Swift?

I had Xcode 9.2 installed and I built it using Ninja as per the documentation.
When I run this command,

utils/build-script --release-debuginfo

I got the above output.
I installed Xcode 9.3 Beta and then again ran this command. It gives me the same error.
Maybe I should clean before compiling again ?

Blowing away the build folder when switching Xcode’s is a little drastic but works for me. There’s also --reconfigure to build-script, which might be more surgical.

Can you also run xcode-select -p to make sure that the 9.3 beta is the current Xcode selected? The command flag it’s complaining about seems to be a relatively recent change, at least from LLVM’s bug reports.

CC @Bob_Wilson, who might know more (or know someone who does) about which linker is part of which Xcode, and when that flag was supported.

1 Like

I downloaded the Xcode 9.3 beta version, moved it to Applications and then ran this command.

sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer

When I do

xcodebuild -version

it shows me this.

Xcode 9.3
Build version 9Q127n

I am building swift using the option --clean right now. I will try the --release-debug option after this.
What is the difference between these ? Any documentation ?

I don’t know, I only use build-script for initial configuration. I doubt that --clean blows aways CMake’s configuration, it likely just erases build artifacts. I would try to rm -rf the build folder and re-run.

@Rostepher would know more, as well as the status of any build-script documentation.

Also this happened when I compiled using --clean


I’m saying that --clean is probably not sufficient for what you want to do, since you care about configuration and not build artifacts. --reconfigure has a chance of working, but the best bet is to blow away the build directory.


I did blow away the build directory and building using

utils/build-script --release-debuginfo

as per the README. Build running …

What about that python 3 bug ? that’s valid ?

Apple’s linker does not support --color-diagnostics (in any version). The strange thing here is that it appears to be failing in the CMake check to see if that option is supported. The failure should not be fatal.


Solution that worked for me:

  1. Select xcode 9.3
    sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
  2. Open a virtual environment using python 2. As I use Anaconda,
    conda create -n python2 python=2.7 anaconda
    or you can do
    virtualenv --python=/usr/bin/python2.7 <path/to/new/virtualenv/>
  3. Activate the virtual environment by using either of these commands.
    source activate <virtualenv>
    source ./<path/to/new/virtualenv/bin/activate>
  4. Then continue the build process. ( as per README )
    utils/build-script --release-debuginfo

I think there should be a line in README indicating that python 2 must be used.
Am I wrong ?

Thank You.

Facing the same exact problem of
ld: unknown option: --color-diagnostics

@Bob_Wilson: Any suggestions on how I can fix it ?

Swift generally requires the latest Xcode beta to run. Right now, it requires the Xcode 10 beta.

I'm hitting the same problem.

  • Xcode 10 beta installed and selected:
$ xcode-select -p
$ xcodebuild -version
Xcode 10.0
Build version 10L176w
  • Swift toolchain installed
  • tried utils/build-script, utils/build-script --release-debuginfo, utils/build-script --reconfigure, utils/build-script --clean, all no luck.

Any suggestions?

Sorry, I have no idea what might cause this.

I was getting this exact error too and solved it by specifying the --xcode argument.

The README says that this option is only supported on macOS, but is it also true that macOS only supports building with Xcode?

I'm facing the same problem when running build-toolchain, which does not have the --xcode argument.