Unable to build Swift on Mac using Ninja

Hey everyone,

I'm unable to build Swift on the Mac using Ninja, but I can build it using Xcode. Did a bit of digging online and couldn't find any answers. Would love some pointers on how to get it to work. I'm getting a segmentation fault: 11 error, with the below output.

Xcode 12.2.1 (10E1001)
macOS 10.14.4

3.	With parser at source location: /Users/benn/git/swift-source/swift/stdlib/public/core/ArrayBody.swift:78:9
0  swift                    0x00000001074dfc75 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001074def35 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001074e0258 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6fb74b5d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffeec20aec8 _sigtramp + 2087281544
5  swift                    0x000000010468e151 createAccessorFunc(swift::SourceLoc, swift::ParameterList*, swift::GenericParamList*, swift::ParameterList*, swift::TypeLoc, swift::SourceLoc, swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::AccessorKind, swift::AbstractStorageDecl*, swift::Parser*, swift::SourceLoc) + 97
6  swift                    0x000000010468d3ae swift::Parser::parseGetSet(swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::GenericParamList*, swift::ParameterList*, swift::TypeLoc, swift::Parser::ParsedAccessors&, swift::AbstractStorageDecl*, swift::SourceLoc) + 1422
7  swift                    0x000000010468f090 swift::Parser::parseDeclVarGetSet(swift::Pattern*, swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::SourceLoc, swift::SourceLoc, bool, swift::DeclAttributes const&, llvm::SmallVectorImpl<swift::Decl*>&) + 1056
8  swift                    0x0000000104681007 swift::Parser::parseDeclVar(swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::DeclAttributes&, llvm::SmallVectorImpl<swift::Decl*>&, swift::SourceLoc, swift::StaticSpellingKind, swift::SourceLoc) + 3111
9  swift                    0x000000010467d6c3 swift::Parser::parseDecl(swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, llvm::function_ref<void (swift::Decl*)>) + 1139
10 swift                    0x000000010468b8df swift::Parser::parseDeclItem(bool&, swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, llvm::function_ref<void (swift::Decl*)>) + 527
11 swift                    0x000000010468a2c1 swift::Parser::parseDeclList(swift::SourceLoc, swift::SourceLoc&, swift::Diag<>, swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::IterableDeclContext*) + 257
12 swift                    0x000000010468510c swift::Parser::parseDeclStruct(swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, swift::DeclAttributes&) + 1500
13 swift                    0x000000010467db10 swift::Parser::parseDecl(swift::OptionSet<swift::Parser::ParseDeclFlags, unsigned int>, llvm::function_ref<void (swift::Decl*)>) + 2240
14 swift                    0x00000001046c1c78 swift::Parser::parseBraceItems(llvm::SmallVectorImpl<swift::ASTNode>&, swift::BraceItemListKind, swift::BraceItemListKind) + 2104
15 swift                    0x000000010466fb8f swift::Parser::parseTopLevel() + 383
16 swift                    0x0000000103cebbf8 parseIntoSourceFileImpl(swift::SourceFile&, unsigned int, bool*, swift::SILParserState*, swift::PersistentParserState*, swift::DelayedParsingCallbacks*, bool, bool) + 760
17 swift                    0x0000000103ceb8ee swift::parseIntoSourceFile(swift::SourceFile&, unsigned int, bool*, swift::SILParserState*, swift::PersistentParserState*, swift::DelayedParsingCallbacks*, bool) + 78
18 swift                    0x0000000103c835ab swift::CompilerInstance::parseLibraryFile(unsigned int, swift::CompilerInstance::ImplicitImports const&, swift::PersistentParserState&, swift::DelayedParsingCallbacks*) + 299
19 swift                    0x0000000103c8307f swift::CompilerInstance::parsePartialModulesAndLibraryFiles(swift::CompilerInstance::ImplicitImports const&, swift::PersistentParserState&, swift::DelayedParsingCallbacks*) + 319
20 swift                    0x0000000103c81ea6 swift::CompilerInstance::parseAndCheckTypesUpTo(swift::CompilerInstance::ImplicitImports const&, swift::SourceFile::ASTStage_t) + 166
21 swift                    0x0000000103c81747 swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 615
22 swift                    0x0000000103a4c495 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1605
23 swift                    0x0000000103a4adf2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2978
24 swift                    0x00000001039f1b59 main + 729
25 libdyld.dylib            0x00007fff6f98f3d5 start + 1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
[1018/1740][ 58%][597.144s] Building CXX object tools/SourceKit/tools/complete-test/CMakeFiles/complete-test.dir/complete-test.cpp.o
ninja: build stopped: subcommand failed.
utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

Weird... try running a clean build with build-script -r --skip-build-benchmarks --clean.

Also, make sure you're up to date: run update-checkout --clone and also make sure your clone of the swift repo is up to date.

Also, have you made any changes to the parser?

When you build from inside Xcode, it doesn't build everything - it depends on which scheme you've selected. ALL_BUILD will build everything where as swift will only build the compiler. If you build from command line (eg: build-script -x -r --skip-build-benchmarks then yes it will build everything. Is that what you were doing?

No I haven't made any changes to the parser, and haven't yet done build-script -x -r --skip-build-benchmarks. I wanted to try getting everything to build using ninja (since it's faster) so I can run some unit tests, but I'll try your suggestions. Thanks!