I'm trying to build Swift from source using the guide at GettingStarted.md. 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:
I confirmed this was the cause by modifying one of the Python scripts called in the third test for CMark (cmark.py, 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.
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
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'
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.
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?
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?
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.