Error building the compiler (even with ninja)

Hello, I'm once again trying to build the compiler, this time using ninja:

utils/build-script --skip-ios --skip-watchos --skip-tvos --skip-build-benchmarks --skip-test-cmark --swift-darwin-supported-archs "$(uname -m)" --sccache --release-debuginfo --swift-disable-dead-stripping --test
Relevant part of build log
  • /opt/homebrew/bin/cmake --build /Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64 -- -j10 all swift-test-stdlib-macosx-arm64
    [47/1232][ 3%][1.316s] Building CXX object lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCOpts.cpp.o
    FAILED: lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCOpts.cpp.o
    /opt/homebrew/bin/sccache /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/llvm/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/tools/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/cmark/src -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64/src -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O2 -DNDEBUG -arch arm64 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target arm64-apple-macosx10.9 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -arch arm64 -F/../../../Developer/Library/Frameworks -O2 -g -std=c++14 -MD -MT lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCOpts.cpp.o -MF lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCOpts.cpp.o.d -o lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCOpts.cpp.o -c /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMARCOpts.cpp
    In file included from /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMARCOpts.cpp:21:
    /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/ARCEntryPointBuilder.h:256:25: error: no member named 'addFnAttribute' in 'llvm::AttributeList'
    AttrList = AttrList.addFnAttribute(M.getContext(), Attribute::NoUnwind);
    ~~~~~~~~ ^
    1 error generated.
    [48/1232][ 3%][1.333s] Building CXX object lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCContract.cpp.o
    FAILED: lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCContract.cpp.o
    /opt/homebrew/bin/sccache /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/llvm/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/tools/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/cmark/src -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64/src -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O2 -DNDEBUG -arch arm64 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target arm64-apple-macosx10.9 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -arch arm64 -F/../../../Developer/Library/Frameworks -O2 -g -std=c++14 -MD -MT lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCContract.cpp.o -MF lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCContract.cpp.o.d -o lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMARCContract.cpp.o -c /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMARCContract.cpp
    In file included from /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMARCContract.cpp:15:
    /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/ARCEntryPointBuilder.h:256:25: error: no member named 'addFnAttribute' in 'llvm::AttributeList'
    AttrList = AttrList.addFnAttribute(M.getContext(), Attribute::NoUnwind);
    ~~~~~~~~ ^
    1 error generated.
    [50/1232][ 4%][1.514s] Building CXX object lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMMergeFunctions.cpp.o
    FAILED: lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMMergeFunctions.cpp.o
    /opt/homebrew/bin/sccache /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -DSWIFT_LLVM_SUPPORT_IS_AVAILABLE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/swift/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/llvm/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/llvm-project/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/tools/clang/include -I/Users/simonjavora/Documents/Work/iOS/swift-project/cmark/src -I/Users/simonjavora/Documents/Work/iOS/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64/src -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O2 -DNDEBUG -arch arm64 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -fno-exceptions -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target arm64-apple-macosx10.9 -isysroot /Users/simonjavora/Downloads/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -arch arm64 -F/../../../Developer/Library/Frameworks -O2 -g -std=c++14 -MD -MT lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMMergeFunctions.cpp.o -MF lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMMergeFunctions.cpp.o.d -o lib/LLVMPasses/CMakeFiles/swiftLLVMPasses.dir/LLVMMergeFunctions.cpp.o -c /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMMergeFunctions.cpp
    /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMMergeFunctions.cpp:1291:36: error: no member named 'getParamAttrs' in 'llvm::AttributeList'
    NewArgAttrs.push_back(NewPAL.getParamAttrs(ParamIdx));
    ~~~~~~ ^
    /Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/LLVMMergeFunctions.cpp:1318:52: error: no member named 'getRetAttrs' in 'llvm::AttributeList'
    NewPAL.getRetAttrs(),
    ~~~~~~ ^
    2 errors generated.
    [56/1232][ 4%][4.325s] Building CXX object lib/Localization/CMakeFiles/swiftLocalization.dir/LocalizationFormat.cpp.o
    ninja: build stopped: subcommand failed.
    ERROR: command terminated with a non-zero exit status 1, aborting

The first error seems to be

/Users/simonjavora/Documents/Work/iOS/swift-project/swift/lib/LLVMPasses/ARCEntryPointBuilder.h:256:25: error: no member named 'addFnAttribute' in 'llvm::AttributeList'
    AttrList = AttrList.addFnAttribute(M.getContext(), Attribute::NoUnwind);
               ~~~~~~~~ ^

I haven't seen this error around anywhere, so no idea what it could even mean. I am using the Xcode version found on ci.swift.org on an M1 Pro. Can anybody help?

More on frustration with building the compiler

From my point of view, getting the compiler to even build is a big barrier to entry for newcomers (hi!). As an iOS developer, I'm quite used to Xcode, so obviously I wanted to use the --xcode option at first. I've never been able to successfully build the compiler that way and I'm starting to wonder whether it works for anyone.

There is at least one post that suggest that using ninja is preferred anyway, but if that's the case, I don't understand why the --xcode option is even offered... threads about build errors with this option come up fairly often (1, 2, 3), libswift isn't available when building with --xcode, which I was very interested in since it meant being able to write Swift and not C++, etc...

It is demotivating to set aside the free time and disk space to try to learn enough of the compiler to be able to contribute only to be stopped before the I can even get started.

There was a recent llvm rebranching on swift repository so I'd suggest you to run an update-checkout (normally is good to delete the llvm-project dir on your checkout folder) after that you should be able to build just fine =]

1 Like

What do you think about updating https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md to discourage people from using --xcode flag in the first place, marking it as unsupported?

1 Like

normally is good to delete the llvm-project dir on your checkout folder

Thank you! That was it, the compiler now builds (with the original invocation)!

I think that would be sad to see. This might be a naive way of looking at it, but couldn't the Xcode build just be added to CI if it's not there already? I don't know about projects of this size, but it seems like a good way of preventing regressions...

Edit: after applying [DNM] Disable use of Clang flag -fswift-async-fp= by DougGregor · Pull Request #39573 · apple/swift · GitHub I was even able to build with --xcode! While that's awesome, I'm already afraid when something else will break it :sweat_smile:

1 Like

Is there a way to get autocomplete support with a ninja build (I'm editing on macOS)?

I'm editing in VSCode with the official C++ extension. Autocomplete is not super reliable with it, but it didn't really work for me in Xcode either. The benefit of using VSCode is that you can get syntax highlighting (and sometimes even autocomplete) for other file types widely used in the repository, like .ll, and CMakeLists.txt etc. It also feels much more responsive and less laggy to me than Xcode with large codebases.

1 Like

I've also tried using VSCode but have had problems with setting up correct include paths for IntelliSense. Have you found a way around that?

As far as I understand, that C++ extensions automatically detects the presence of compile_commands.json, which are required for autocomplete to work. You just need to build the project first for these files to be generated, and to open the directory one level above swift, so that build directory is visible too in the opened VSCode workspace. That's where these .json files are located, as per this clang-tidy section in the build docs.

1 Like

Thank you! I've spent a lot of time trying to build with Xcode; even with Ninja and VSCode I got autocomplete to work after about 2 weeks of trying.

I think GettingStarted.md should definitely be changed to make first-time contributions easier, and hopefully bring in more contributors into the Swift project.

1 Like

I totally agree, but it's hard to pick a good direction for how it should change when everything's working sufficiently well for existing contributors. A fresh perspective from new contributors is always appreciated, we need to gather this feedback as some actionable steps for improvement. If you know of something that's specifically missing there, please submit a PR, or let's discuss it here on the forums (maybe in a separate thread?).

I'd definitely start with marking --xcode flag as unsupported until a separate job is added on CI to prevent regressions in this build configuration.

2 Likes