Build swift error: undefined symbols

Hi, My computer is M1 pro, using Xcode 13.4.1,branch release/5.6, and I use utils/build-script -r --lldb to build lldb, but I get some errors:

ld: warning: ignoring file /opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/libpython3.9.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_PyMemoryView_FromMemory", referenced from:
      (anonymous namespace)::BinaryPythonFile::Write(void const*, unsigned long&) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyErr_NormalizeException", referenced from:
      lldb_private::python::PythonException::PythonException(char const*) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyImport_ImportModule", referenced from:
      lldb_private::python::PythonModule::Import(llvm::Twine const&) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyUnicode_AsEncodedString", referenced from:
      lldb_private::python::PythonException::PythonException(char const*) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyUnicode_FromStringAndSize", referenced from:
      lldb_private::python::PythonString::FromUTF8(llvm::StringRef) in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)
  "_PyBytes_Size", referenced from:
      lldb_private::python::PythonBytes::GetSize() const in liblldbPluginScriptInterpreterPython.a(PythonDataObjects.cpp.o)

is there any thing wrong?

Maybe because the python3 framework is built for arm64 and the compiler build for x86_64?

You need to install Python that will have both arm64 and x86_64 slices, the easiest way I found is to download universal installer from official website, unpack it with pkgutil --expand and tar xvf Payload, grab the Python.framework, go to the directory with your old python framework (first line in your log) and replace it with the new one.

On a side note, macOS also has python with both arm64 and x86_64 slices at /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework, but idk how to force cmake to use this exact framework for linking. Also each Xcode bundels it's own Python framework.

One other problem I encountered is that the built lldb might contain a wrong rpath to the python library which will make it crash on launch. rpaths can be inspected with otool -L and otool -l commands, if needed they can be fixed with install_name_tool -change command.