Unable to build Swift on M1 MBA

Hi there...

This is my first post ever here so please redirect me as necessary. I was curious if I could build Swift locally in the hopes that I could work on a starter bug eventually but I have not been able to successfully do so on my new M1 MBA. I've tried multiple times, both trying to build with ninja and with Xcode and I keep running into either of two errors:

CMake Error at /Users/danielle/projects/swift-project2/llvm-project/llvm/cmake/modules/AddLLVM.cmake:859 (add_executable):
  Error evaluating generator expression:

    $<TARGET_OBJECTS:swiftRuntime-macosx-x86_64>

  Objects of target "swiftRuntime-macosx-x86_64" referenced but no such
  target exists.
Call Stack (most recent call first):
  /Users/danielle/projects/swift-project2/llvm-project/llvm/cmake/modules/AddLLVM.cmake:1452 (add_llvm_executable)
  cmake/modules/AddSwiftUnittests.cmake:11 (add_unittest)
  unittests/runtime/CMakeLists.txt:93 (add_swift_unittest)

... or:

[12/1638][  0%][3.109s] Generating ../../../lib/swift/macosx/libswiftCompatibility50.a
FAILED: lib/swift/macosx/libswiftCompatibility50.a
cd /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/stdlib/toolchain/Compatibility50 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo -create -output /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/./lib/swift/macosx/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/arm64/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/arm64e/libswiftCompatibility50.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /Users/danielle/projects/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (x86_64) and can't be in the same fat output file
[19/1638][  1%][4.930s] Building CXX object stdlib/toolchain/Com.../swiftCompatibility51-macosx-arm64.dir/ProtocolConformance.cpp.o
ninja: build stopped: subcommand failed.
ERROR: command terminated with a non-zero exit status 1, aborting

I have been following the README at swift/GettingStarted.md at main · apple/swift · GitHub but I can't tell if I'm doing something wrong or if it is omitting anything.

Any advice?

danielle kefford

It's trying to build the runtime for x86_64; if you're using --swift-darwin-supported-archs "$(uname -m)", that should normally build the code for arm64 and skip x86_64. Maybe the build is happening under Rosetta 2? You may want to check out this thread and see if that resolves your issue. :slight_smile:

1 Like

Hai Varun!!!

That definitely solved my problem with respect to Intel vs. ARM issues... but I'm still unable to build but it's something else this time:

FAILED: bin/swift-demangle-yamldump
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Wno-unknown-warning-option -Werror=unguarded-availability-new -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 -index-store-path "/Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/IndexStore" -fdiagnostics-color -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -g -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -target arm64-apple-macosx10.9 tools/swift-demangle-yamldump/CMakeFiles/swift-demangle-yamldump.dir/swift-demangle-yamldump.cpp.o -o bin/swift-demangle-yamldump -L/Users/danielle/projects/swift-project/build/Ninja-DebugAssert/llvm-macosx-arm64/./lib   -L/Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/./lib/swift/macosx -Wl,-rpath,@executable_path/../lib/swift/macosx  /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/llvm-macosx-arm64/lib/libLLVMSupport.a  lib/libswiftDemangling.a  -lm  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/lib/libz.tbd  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/usr/lib/libcurses.tbd  /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/llvm-macosx-arm64/lib/libLLVMDemangle.a && :
ld: warning: ignoring file /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/llvm-macosx-arm64/lib/libLLVMSupport.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/llvm-macosx-arm64/lib/libLLVMDemangle.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "llvm::raw_ostream::flush_nonempty()", referenced from:
      llvm::raw_ostream::flush() in swift-demangle-yamldump.cpp.o
  "llvm::raw_ostream::SetBufferAndMode(char*, unsigned long, llvm::raw_ostream::BufferKind)", referenced from:
      llvm::raw_ostream::SetUnbuffered() in swift-demangle-yamldump.cpp.o
  "llvm::raw_ostream::write(char const*, unsigned long)", referenced from:
      llvm::raw_ostream::operator<<(llvm::StringRef) in swift-demangle-yamldump.cpp.o
      llvm::raw_ostream::operator<<(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in swift-demangle-yamldump.cpp.o
  "llvm::raw_ostream::write(unsigned char)", referenced from:
      llvm::raw_ostream::operator<<(char) in swift-demangle-yamldump.cpp.o
  "llvm::SmallVectorBase<unsigned int>::grow_pod(void*, unsigned long, unsigned long)", referenced from:
      llvm::SmallVectorTemplateCommon<llvm::cl::OptionCategory*, void>::grow_pod(unsigned long, unsigned long) in swift-demangle-yamldump.cpp.o
  "llvm::raw_string_ostream::~raw_string_ostream()", referenced from:
      getNodeTreeAsYAML(llvm::StringRef, swift::Demangle::Node*) in swift-demangle-yamldump.cpp.o
      std::__1::enable_if<has_ScalarTraits<llvm::StringRef>::value, void>::type llvm::yaml::yamlize<llvm::StringRef>(llvm::yaml::IO&, llvm::StringRef&, bool, llvm::yaml::EmptyContext&) in swift-demangle-yamldump.cpp.o
  "llvm::EnableABIBreakingChecks", referenced from:
      llvm::VerifyEnableABIBreakingChecks in swift-demangle-yamldump.cpp.o
  "llvm::cl::basic_parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::basic_parser(llvm::cl::Option&)", referenced from:
      llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::parser(llvm::cl::Option&) in swift-demangle-yamldump.cpp.o
  "llvm::cl::basic_parser<bool>::basic_parser(llvm::cl::Option&)", referenced from:
      llvm::cl::parser<bool>::parser(llvm::cl::Option&) in swift-demangle-yamldump.cpp.o
  "llvm::cl::GeneralCategory", referenced from:
      llvm::cl::Option::Option(llvm::cl::NumOccurrencesFlag, llvm::cl::OptionHidden) in swift-demangle-yamldump.cpp.o
  "llvm::cl::GenericOptionValue::anchor()", referenced from:
      vtable for llvm::cl::OptionValue<bool> in swift-demangle-yamldump.cpp.o
      vtable for llvm::cl::OptionValueBase<bool, false> in swift-demangle-yamldump.cpp.o
      vtable for llvm::cl::OptionValueCopy<bool> in swift-demangle-yamldump.cpp.o
  "llvm::cl::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool)", referenced from:
      _main in swift-demangle-yamldump.cpp.o
  "llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::done()", referenced from:
      llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::opt<char [9], llvm::cl::desc>(char const (&) [9], llvm::cl::desc const&) in swift-demangle-yamldump.cpp.o
      llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::opt<char [11], llvm::cl::desc>(char const (&) [11], llvm::cl::desc const&) in swift-demangle-yamldump.cpp.o
  "llvm::cl::Option::addArgument()", referenced from:
      llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::done() in swift-demangle-yamldump.cpp.o
  "llvm::cl::Option::addOccurrence(unsigned int, llvm::StringRef, llvm::StringRef, bool)", referenced from:
      vtable for llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > in swift-demangle-yamldump.cpp.o
  "llvm::cl::Option::anchor()", referenced from:
      vtable for llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > in swift-demangle-yamldump.cpp.o
  "llvm::cl::Option::setArgStr(llvm::StringRef)", referenced from:
      void llvm::cl::applicator<char [9]>::opt<llvm::cl::opt<bool, false, llvm::cl::parser<bool> > >(llvm::StringRef, llvm::cl::opt<bool, false, llvm::cl::parser<bool> >&) in swift-demangle-yamldump.cpp.o
      void llvm::cl::applicator<char [11]>::opt<llvm::cl::opt<bool, false, llvm::cl::parser<bool> > >(llvm::StringRef, llvm::cl::opt<bool, false, llvm::cl::parser<bool> >&) in swift-demangle-yamldump.cpp.o
  "llvm::errs()", referenced from:
      demangleSTDIN(swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
  "llvm::outs()", referenced from:
      _main in swift-demangle-yamldump.cpp.o
      demangleSTDIN(swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
      demangle(llvm::raw_ostream&, llvm::StringRef, swift::Demangle::Context&, swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::ScalarTraits<llvm::StringRef, void>::input(llvm::StringRef, void*, llvm::StringRef&)", referenced from:
      std::__1::enable_if<has_ScalarTraits<llvm::StringRef>::value, void>::type llvm::yaml::yamlize<llvm::StringRef>(llvm::yaml::IO&, llvm::StringRef&, bool, llvm::yaml::EmptyContext&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::ScalarTraits<llvm::StringRef, void>::output(llvm::StringRef const&, void*, llvm::raw_ostream&)", referenced from:
      std::__1::enable_if<has_ScalarTraits<llvm::StringRef>::value, void>::type llvm::yaml::yamlize<llvm::StringRef>(llvm::yaml::IO&, llvm::StringRef&, bool, llvm::yaml::EmptyContext&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::endDocuments()", referenced from:
      std::__1::enable_if<has_MappingTraits<(anonymous namespace)::YAMLNode, llvm::yaml::EmptyContext>::value, llvm::yaml::Output&>::type llvm::yaml::operator<<<(anonymous namespace)::YAMLNode>(llvm::yaml::Output&, (anonymous namespace)::YAMLNode&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::beginDocuments()", referenced from:
      std::__1::enable_if<has_MappingTraits<(anonymous namespace)::YAMLNode, llvm::yaml::EmptyContext>::value, llvm::yaml::Output&>::type llvm::yaml::operator<<<(anonymous namespace)::YAMLNode>(llvm::yaml::Output&, (anonymous namespace)::YAMLNode&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::preflightDocument(unsigned int)", referenced from:
      std::__1::enable_if<has_MappingTraits<(anonymous namespace)::YAMLNode, llvm::yaml::EmptyContext>::value, llvm::yaml::Output&>::type llvm::yaml::operator<<<(anonymous namespace)::YAMLNode>(llvm::yaml::Output&, (anonymous namespace)::YAMLNode&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::postflightDocument()", referenced from:
      std::__1::enable_if<has_MappingTraits<(anonymous namespace)::YAMLNode, llvm::yaml::EmptyContext>::value, llvm::yaml::Output&>::type llvm::yaml::operator<<<(anonymous namespace)::YAMLNode>(llvm::yaml::Output&, (anonymous namespace)::YAMLNode&) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::Output(llvm::raw_ostream&, void*, int)", referenced from:
      getNodeTreeAsYAML(llvm::StringRef, swift::Demangle::Node*) in swift-demangle-yamldump.cpp.o
  "llvm::yaml::Output::~Output()", referenced from:
      getNodeTreeAsYAML(llvm::StringRef, swift::Demangle::Node*) in swift-demangle-yamldump.cpp.o
  "llvm::Regex::Regex(llvm::StringRef, llvm::Regex::RegexFlags)", referenced from:
      demangleSTDIN(swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
  "llvm::Regex::~Regex()", referenced from:
      demangleSTDIN(swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
  "llvm::cl::basic_parser_impl::getOptionWidth(llvm::cl::Option const&) const", referenced from:
      llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::getOptionWidth() const in swift-demangle-yamldump.cpp.o
  "llvm::cl::basic_parser_impl::printOptionInfo(llvm::cl::Option const&, unsigned long) const", referenced from:
      llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::printOptionInfo(unsigned long) const in swift-demangle-yamldump.cpp.o
  "llvm::yaml::IO::getContext() const", referenced from:
      std::__1::enable_if<has_ScalarTraits<llvm::StringRef>::value, void>::type llvm::yaml::yamlize<llvm::StringRef>(llvm::yaml::IO&, llvm::StringRef&, bool, llvm::yaml::EmptyContext&) in swift-demangle-yamldump.cpp.o
  "llvm::Regex::match(llvm::StringRef, llvm::SmallVectorImpl<llvm::StringRef>*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) const", referenced from:
      demangleSTDIN(swift::Demangle::DemangleOptions const&) in swift-demangle-yamldump.cpp.o
  "llvm::StringRef::find_first_of(llvm::StringRef, unsigned long) const", referenced from:
      llvm::yaml::needsQuotes(llvm::StringRef) in swift-demangle-yamldump.cpp.o
  "llvm::StringRef::find_first_not_of(llvm::StringRef, unsigned long) const", referenced from:
      llvm::yaml::isNumeric(llvm::StringRef) in swift-demangle-yamldump.cpp.o
      llvm::yaml::isNumeric(llvm::StringRef)::'lambda'(llvm::StringRef)::operator()(llvm::StringRef) const in swift-demangle-yamldump.cpp.o
  "vtable for llvm::raw_ostream", referenced from:
      llvm::raw_ostream::raw_ostream(bool, llvm::raw_ostream::OStreamKind) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::raw_string_ostream", referenced from:
      llvm::raw_string_ostream::raw_string_ostream(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::cl::GenericOptionValue", referenced from:
      llvm::cl::GenericOptionValue::GenericOptionValue() in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::cl::opt<bool, false, llvm::cl::parser<bool> >", referenced from:
      llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::~opt() in swift-demangle-yamldump.cpp.o
      llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::opt<char [9], llvm::cl::desc>(char const (&) [9], llvm::cl::desc const&) in swift-demangle-yamldump.cpp.o
      llvm::cl::opt<bool, false, llvm::cl::parser<bool> >::opt<char [11], llvm::cl::desc>(char const (&) [11], llvm::cl::desc const&) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::cl::Option", referenced from:
      llvm::cl::Option::~Option() in swift-demangle-yamldump.cpp.o
      llvm::cl::Option::Option(llvm::cl::NumOccurrencesFlag, llvm::cl::OptionHidden) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >", referenced from:
      llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::parser(llvm::cl::Option&) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for llvm::cl::parser<bool>", referenced from:
      llvm::cl::parser<bool>::parser(llvm::cl::Option&) in swift-demangle-yamldump.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[388/2164][ 17%][586.705s] Building CXX object stdlib/public/R...akeFiles/swiftReflection-macosx-arm64.dir/TypeRefBuilder.cpp.o
ninja: build stopped: subcommand failed.
ERROR: command terminated with a non-zero exit status 1, aborting

I think you can consider this thread closed since there is something else wrong and I probably have to create another thread, yes?. In the mean time, thank you so much for helping!

danielle kefford

WAIT!... I still have an architecture problem... dammit. I think ninja is the problem this time. Ugh... I think I have to completely blast Homebrew and all the tooling again...

While iterating on a failing build, you may want to try using --release --no-assertions since that's generally faster to build compared to --release-debuginfo or --debug. Once that's working alright, you can create a separate build with --release-debuginfo or something else, so that you have access to debuginfo when working on the compiler or another project.

1 Like

Ugh... now I'm back to this error again:

[1140/2164][ 52%][1066.372s] Generating ../../../lib/swift/macosx/libswiftCompatibility50.a
FAILED: lib/swift/macosx/libswiftCompatibility50.a
cd /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/stdlib/toolchain/Compatibility50 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo -create -output /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/./lib/swift/macosx/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/lib/swift/macosx/x86_64/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/lib/swift/macosx/arm64/libswiftCompatibility50.a /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/lib/swift/macosx/arm64e/libswiftCompatibility50.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /Users/danielle/projects/swift-project/build/Ninja-DebugAssert/swift-macosx-arm64/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file
[1147/2164][ 53%][1072.349s] Building CXX object lib/ClangImporter/CMakeFiles/swiftClangImporter.dir/ImportDecl.cpp.o
ninja: build stopped: subcommand failed.
ERROR: command terminated with a non-zero exit status 1, aborting

@quephird just to be careful, have you tried a preset from the bots? 0. OSS - Swift Incremental RA - macOS (main) (Apple Silicon) #525 [Jenkins] looks like that is building. To build like the bot, I would suggest that you use the same preset:

14:08:12 ++ /Users/buildnode/jenkins/workspace/oss-swift-incremental-RA-macos-apple-silicon/swift/utils/build-script --preset=buildbot_incremental,tools=RA,stdlib=RA,apple_silicon

I would also run just to be careful.

./swift/utils/update-checkout --scheme main --clone

@quephird I suspect that one of your tools is still running via Rosetta. If you open activity monitor while it's building, you can verify if this is the issue by seeing if clang, python, your terminal, etc. is running under "Intel" or "Apple". If they are all running as "Apple" maybe it's a configuration problem, but I doubt it (I suspect you will see that one of these is running under "Intel").

You can use activity monitor to work your way up to see what processes is the culprit. Make sure you check that iTerm (or whatever terminal you're using), python, and clang are all running natively.

Terms of Service

Privacy Policy

Cookie Policy