Building Swift compiler from source fails when not using Ninja

I'm trying to build Swift from source using the guide at I downloaded all of the repositories and made my first invocation to build-script using the --xcode flag. There was a failure when running tests for CMark that halted compilation, and I found the cause.

The build products for CMark are located in the following folder:


But the Python scripts in the tests for CMark only check this directory, which omits the last path component ("RelWithDebInfo"):


I confirmed this was the cause by modifying one of the Python scripts called in the third test for CMark (, line 47) to look for [ "libcmark.dylib, RelWithDebInfo/libcmark.dylib" ] instead of just [ "libcmark.dylib" ]. Subsequently, the third test and a few others succeeded, but some more were broken because they searched for a cmark file in the wrong directory (same situation as libcmark.dylib). I don't have the time or patience to hunt down where that error occurs in the Python code, and fixing the symptom instead of the problem is not a good idea.

I then tried building using Ninja instead of Xcode, and it worked just fine (it's compiling as I make this post). I'm worried because I'm going to make a lot of changes to the compiler's code as I debug it. I plan to overhaul autodiff and fix all the bugs breaking Swift for TensorFlow, which is an incredibly difficult task. If I can't use an IDE, I won't be as productive. Has anyone else had this build failure (is it something new or exclusive to Apple silicon?), or do you have suggestions for how I can work just as productively as if I were using Xcode?

Update: compiling with --xcode seems to work when I omit the --test flag.


See also:

Note the following from that last thread:

Thanks. The Xcode build without tests just succeeded, but the way.

SR-13635 is exactly the set of tests that failed for me.

Now I'm getting the following error when I press Cmd + B with the Xcode project open:

clang-13: error: no such file or directory: '/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/Debug/lib/libLLVMSupport.a'
clang-13: error: no such file or directory: '/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/Debug/lib/libLLVMDemangle.a'
Command Ld failed with a nonzero exit code
Full log

Ld /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Debug/bin/swift-serialize-diagnostics normal (in target 'swift-serialize-diagnostics' from project 'Swift')
cd /Users/philipturner/Documents/Swift-Compiler/swift-project/swift
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2022-01-09-a.xctoolchain/usr/bin/clang++ -target arm64-apple-macos12.1 -isysroot /Applications/ -L/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Debug/bin -L/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/RelWithDebInfo/lib/Debug -L/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/RelWithDebInfo/lib -F/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Debug/bin -filelist /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/tools/swift-serialize-diagnostics/ -Xlinker -object_path_lto -Xlinker /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/tools/swift-serialize-diagnostics/ -stdlib=libc++ -target arm64-apple-macosx10.9 -Xlinker /Applications/ -Xlinker /Applications/ -Xlinker /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/Debug/lib/libLLVMDemangle.a -Wl,-search_paths_first -Wl,-headerpad_max_install_names /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Debug/lib/libswiftLocalization.a /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/Debug/lib/libLLVMSupport.a -lm /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/llvm-macosx-arm64/Debug/lib/libLLVMDemangle.a -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/tools/swift-serialize-diagnostics/ -o /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/Debug/bin/swift-serialize-diagnostics

Any ideas how to fix this? Should I edit with Xcode but still compile with Ninja from command line? The error happens when I try each of the recommended schemes in

Not entirely sure, but I think that is a problem with LLVM paths when building llvm in a different mode than swift (in this case llvm RelWithDebugInfo and swift in Debug) note that you are building with --release-debuginfo so llvm libraries will probably be at RelWithDebugInfo directory but error is that it doesn't find them in the Debug directory(which is swift build mode). You probably find those libraries in the RelWithDebugInfo folder.

A work around you may be able to do it to build all in debug mode if the goal is only to build, this command SKIP_XCODE_VERSION_CHECK=1 ./swift/utils/build-script --xcode --debug --skip-build-benchmarks --swift-darwin-supported-archs "$(uname -m)" --sccache --skip-ios --skip-tvos --skip-watchos should work.

That seems to be the problem! All the executables I need are in the RelWithDebugInfo/lib directory instead of the Debug directory, which doesn't even have a lib folder. I'll test your command soon.

Now I got this problem, where the build tried to reference the lib/Debug folder instead of the plain Debug folder:

clang: error: no such file or directory: '/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/lib/Debug/libswiftCompilerModules-bootstrapping1.a'
Command Ld failed with a nonzero exit code

I opened up the Xcode project and pressed Cmd + B. It seems to have encountered that error just as a warning and continued with the build, so hopefully it will work!

Update: the same error happened later on in the build. I just wasted 30% of my MBP's battery on that build when it already started at 80%, and I have a full day ahead!

clang-13: error: no such file or directory: '/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/lib/Debug/libswiftCompilerModules-bootstrapping1.a'

This is an issue that should be fixed by now, see [SR-15705] Compiler build failed (PhaseScriptExecution CMake PostBuild\ Rules) - Swift for more info. I would suggest to try pass --bootstrapping=off

I don’t follow… if it’s fixed, then why is it necessary to pass --bootstrapping=off?

Bootstrapping was off by default in Xcode build because it was not supported so it would never try bootstrapping when --xcode and it should build just fine. Fix printing Xcode version from CMake when building with Xcode by cbjeukendrup · Pull Request #40870 · apple/swift · GitHub enabled bootstrapping for Xcode, but by the error message something may not be working as expected since it failing. So what I'm simply suggesting is that if the goal is build the compiler with --xcode enforce --bootstrapping=off should do it as a workaround at least util we figure out the cause of the bootstrapping issue.

Best Regards,

It's still failing. From the command line, I tried this:

./swift/utils/build-script --xcode --debug --skip-build-benchmarks --swift-darwin-supported-archs "$(uname -m)" --sccache --skip-ios --skip-tvos --skip-watchos --bootstrapping=off

And ended up with this:

clang: error: no such file or directory: '/Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/lib/Debug/libswiftCompilerModules-bootstrapping1.a'
Command Ld failed with a nonzero exit code


The following build commands failed:
	Ld /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/bootstrapping1/Debug/bin/swift-frontend normal (in target 'swift-frontend-bootstrapping1' from project 'Swift')
(1 failure)
ERROR: command terminated with a non-zero exit status 65, aborting

Did I do anything wrong? Or do you have the capacity to test it out yourself and reproduce my error?

1 Like

I successfully built with --bootstrapping=off this morning. I did have to nuke my build directory first.

I'll try doing that. In the meantime, what machine specifications (platform, CPU architecture) were you using?

M1 Mac mini, building for arm64.

I have M1 Max Macbook Pro. You only had to nuke the sub-folder for Xcode-DebugAssert right? I'm free to keep the others like Xcode-RelWithDebInfoAssert?

I deleted the entire build directory. I don’t know if there’s a more limited subset you can delete.

Before deleting all there are a couple of options to try first because delete all will make you need to rebuild everything again: So you can try using --reconfigure to force cmake to re-generate everything or delete only swift-macosx-arm64 because llvm, cmark and driver probably don't need rebuilding =]

Already deleted the Xcode-DebugAssert, although I just moved the other two (Xcode release, Ninja release) out of the directory. Xcode-DebugAssert is in the trash, so I could retain it. At this point, I'd rather not mess with the build.

It built successfully both from the command line and in Xcode!