Not able to build the swift compiler

I was trying to build the swift compiler, by following the step by step procedure from the this documentation. Then, when I reached the 3rd step of The actual build, then I got this error:

CMake Error at /opt/homebrew/Cellar/cmake/3.24.2/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler

"/Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: /Users/shreyanshsharma/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftsyntax-macosx-arm64/CMakeFiles/CMakeTmp

Run Build Command(s):/opt/homebrew/bin/ninja cmTC_dd424 && [1/2][ 50%][0.022s] Building C object CMakeFiles/cmTC_dd424.dir/testCCompiler.c.o
[2/2][100%][0.038s] Linking C executable cmTC_dd424
FAILED: cmTC_dd424 
: && "/Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" --target=arm64-apple-macosx10.9 -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_dd424.dir/testCCompiler.c.o -o cmTC_dd424   && :
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:13 (project)

Please help me out!

Hey @Shreyansh,
Couple of questions, what does xcode-select -p returns?
Also, which version of Xcode is Xcode 2? Are your command line tools correctly installed(did you try running xcode-select --install after selecting Xcode 2)?
We have seen something similar in Build failure locally, you can take a look there see if there is any useful info, this could be likely a mismatch of tools since you probably have more than one Xcode in your machine. So my guess would be try to make sure that everything is pointing to the correct one.

Hello @LucianoPAlmeida
Thanks for looking into the problem!

xcode-select -p

returns
/Applications/Xcode 2.app/Contents/Developer

and Xcode 2 is Xcode 14.0 (14A309)

xcode-select --install 

says:
xcode-select: error: command line tools are already installed, use "Software Update" in System Settings to install updates

Now how do I proceed?

Is hard to say... is definitely something with tooling cmake is using to build things or something in your system. Which macOS version is it?
When you run the command you should see something like

-- CMake (/opt/homebrew/Cellar/cmake/3.22.2/bin/cmake) Version: 3.22.2
-- CMake Make Program (/opt/homebrew/bin/ninja) Version: 1.10.2
-- C Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang) Version: 13.0.0.13000029
-- C++ Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++) Version: 13.0.0.13000029

Could you send what appears in your output? (Just search on terminal for -- CMake)
Also given you have an Xcode 2, you probably have another version of Xcode right? Could you try select that one xcode-select -s ${PATH}, run command line install and try a new build-script invocation adding --clean?

@LucianoPAlmeida,
Thank You very much for still holding up with the problem!

As you've asked:
The mac OS version I'm using is Ventura 13.0, the other version of xcode (Xcode 14.0.1 (Build version 14A400)) you are talking about is not able to run the build script, that is why I installed an older version(Xcode 14.0.0 (14A309)) of it in the first place.

This was what showed up in the terminal when I ran the command:

-- The C compiler identification is AppleClang 14.0.0.14000029
-- The Swift compiler identification is Apple 5.7
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-- Check for working C compiler: /Applications/Xcode 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - broken

after this the error showed up!

Ok that seems to be the root cause of the issue.

Why it wasn't able to run it? Did it give some error?

I imagine it was "error: using unsupported Xcode version", because Xcode 14.0.1 isn't listed.

There's an open pull request that would improve this contributor experience.

1 Like

This is awesome! I think a lot of people stumble on that. I definitely did so many times the by default always have SKIP_XCODE_VERSION_CHECK=1

@LucianoPAlmeida , So what do I do now to fix this issue ?

I would try to remove this Xcode 2 completely, xcode-select -s the original one, xcode-select --install to make sure tools are installed and then run the build-script command with --clean but more importantly SKIP_XCODE_VERSION_CHECK=1.
Example:
SKIP_XCODE_VERSION_CHECK=1 ./swift/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

1 Like