Building Swift compiler from source fails when not using Ninja

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/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -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/Swift.build/Debug/swift-serialize-diagnostics.build/Objects-normal/arm64/swift-serialize-diagnostics.LinkFileList -Xlinker -object_path_lto -Xlinker /Users/philipturner/Documents/Swift-Compiler/swift-project/build/Xcode-RelWithDebInfoAssert/swift-macosx-arm64/tools/swift-serialize-diagnostics/Swift.build/Debug/swift-serialize-diagnostics.build/Objects-normal/arm64/swift-serialize-diagnostics_lto.o -stdlib=libc++ -target arm64-apple-macosx10.9 -Xlinker /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libz.tbd -Xlinker /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libcurses.tbd -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/Swift.build/Debug/swift-serialize-diagnostics.build/Objects-normal/arm64/swift-serialize-diagnostics_dependency_info.dat -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 GettingStarted.md.

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) · Issue #57984 · apple/swift · GitHub 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,
Luciano

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

** BUILD FAILED **


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.

1 Like

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

Hello, what is your compiler instruction @philipturner

@philipturner Because I had the same error as you