Lldb & Swift 5.10 repl 'suddenly' stopped working, macos 12.0.1

Bizarre problem, wonder if anyone else has run into this.

I'm running macOS 12 which still has system Python 2.7. However my shell starts a conda environment by default with Python 3.9.12

A few weeks ago I installed Swift 5.10 using the package installer, to run from the command line.

In Xcode 13.4.1 I use the Toolchains dialog to select Swift 5.10 Release 2024-03-04

In the shell (zsh) I invoke

export TOOLCHAINS=swift

to select the 5.10 toolchain. Swift --version shows 5.10 as expected.

FOR WEEKS I have been running swift repl and swift test from the command line,
with no problems. I frequently run swift --version to make sure I really have 5.10. No changes to OS in those weeks.

TODAY, in swift repl , I was having trouble getting the compiler to parse an expression (it says it's too complicated!), and the compiler seemed stuck for a long time, so I killed the repl session (lldb) using the Activity Monitor.

From that point forward I cannot run swift repl or lldb from the command line. The start of the long error message :

dyld[33556]: Library not loaded: @rpath/Python3.framework/Versions/3.9/Python3
  Referenced from: /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB
  Reason: tried: '/usr/lib/swift/Python3.framework/Versions/3.9/Python3' (no such file)

(then follows a cavalcade o' folders, various permutations of Toolchains names...)

My interpretation of this is that the lldb framework is trying to use python from a directory under /usr/lib/swift. /usr/lib/swift exists , but has old content, couple files I have no clue about :

lrwxr-xr-x  1 root  wheel       71 Oct 17  2021 libswiftCreateML.dylib -> /System/Library/Frameworks/CreateML.framework/Versions/Current/CreateML
-rwxr-xr-x  1 root  wheel  1362544 Oct 17  2021 libswiftRemoteMirror.dylib

So what gives? I deleted the toolchain directory and reinstalled Swift 5.10, no change.

My sense is that Swift no longer relies on the macOS system python (good!), but now expects a separate distribution. My system python (2.7) and conda python (3.9) should be totally irrelevant.

This makes no sense: I was running Swift 5.10 in repl mode for weeks, if it was finding python , where did the python distro go? Why did killing lldb make this go permanently awry?

Thanks in advance,
Randy

P.S. It just occurred to me that /usr/lib/ is read-only in this OS. In fact all my files in /usr/lib are dated Oct 17 2021, that must be the date I upgraded to the current macOS 12.0 . So if the swift installer expects to put anything in /usr/lib/swift, not going to happen.

This is what I can provide for you.

For the downloaded Swift 5.10 release toolchain

export TOOLCHAINS=swift

otool -L $(xcrun -f lldb)
/Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/usr/bin/lldb (architecture x86_64):
	@rpath/LLDB.framework/Versions/A/LLDB (compatibility version 1.0.0, current version 15.0.0)
	...

otool -l $(xcrun -f lldb)
...
Load command 21
          cmd LC_RPATH
      cmdsize 56
         path @loader_path/../../../SharedFrameworks (offset 12)
Load command 22
          cmd LC_RPATH
      cmdsize 64
         path @loader_path/../../System/Library/PrivateFrameworks (offset 12)
Load command 23
          cmd LC_RPATH
      cmdsize 64
         path @loader_path/../../Library/PrivateFrameworks (offset 12)

So it will reference this file /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB.

otool -L /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB
/Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLDB (architecture x86_64):
	@rpath/LLDB.framework/Versions/A/LLDB (compatibility version 1.0.0, current version 15.0.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
	@rpath/Python3.framework/Versions/3.9/Python3 (compatibility version 3.9.0, current version 3.9.0)
	...

otool -l /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks/LLDB.framework/Versions/A/LLD
Load command 42
          cmd LC_RPATH
      cmdsize 72
         path @loader_path/../../../../../../../../Library/Frameworks/ (offset 12)
Load command 43
          cmd LC_RPATH
      cmdsize 72
         path @loader_path/../../../../../Developer/Library/Frameworks/ (offset 12)
Load command 44
          cmd LC_RPATH
      cmdsize 72
         path @loader_path/../../../../Developer/Library/Frameworks/ (offset 12)
Load command 45
          cmd LC_RPATH
      cmdsize 48
         path @loader_path/../../../../Frameworks (offset 12)
Load command 46
          cmd LC_RPATH
      cmdsize 40
         path @loader_path/../../../ (offset 12)
Load command 47
          cmd LC_RPATH
      cmdsize 72
         path /Library/Developer/CommandLineTools/Library/Frameworks (offset 12)
Load command 48
          cmd LC_RPATH
      cmdsize 80
         path /Applications/Xcode.app/Contents/Developer/Library/Frameworks/ (offset 12)
Load command 49
          cmd LC_RPATH
      cmdsize 64
         path @loader_path/../../../../../../usr/lib/swift/host (offset 12)
42 -> /Library/Frameworks (No Python3 here)
43 -> /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Developer/Library/Frameworks/ (Folder Not Exist)
44 -> /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/Developer/Library/Frameworks/ (Folder Not Exist)
45 -> /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/Frameworks (Folder Not Exist)
46 -> /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks (No Python3 here)
47 -> /Library/Developer/CommandLineTools/Library/Frameworks (Found Python3 here)
48 -> ...
49 -> ...

You can run the above command and see why "Python3.framework" can not be found in your rpath.

In my case, it will locate and use python3.framework found in /Library/Developer/CommandLineTools/Library/Frameworks/

Make sure it can find one in the above rpath location. Or you can fix it by manually inserting a new rpath to the LLDB binary.

Help it can help solve your issue.

Kyle, thanks very much. That is correct, I did not have a Python3 framework anywhere in the paths listed. Interestingly. when I run otool I see no reference to /usr/lib/swift as you show, and yet the lldb error message implies that is the first alternate path tried.

I did fix the problem :

The path @rpath is clearly /Library/Developer/Toolchains/swift-5.10-RELEASE.xctoolchain/System/Library/PrivateFrameworks

So I just give it what it asks for :

Make directory @rpath/Python3.framework/Versions/3.9

Then make a link to my existing conda installation :

cd @rpath/Python3.framework/Versions/3.9
sudo ln -s /Users/zauhar/opt/miniconda3/lib/libpython3.9.dylib Python3

Now I can again run swift 5.10 repl and lldb from the command line .

So it's 'fixed', but I am still baffled as to how Swift 5.10 repl worked for several weeks without my having to do this? There is no system-supplied Python3 in MacOS 12.

To paraphrase Three Body Problem : 'Computer science doesn't exist. Computer science never existed'

Thanks,
Randy