LLDB not honoring minimum platform version for SPM packages

I'm running LLDB from Xcode in a project with SPM dependencies. The app runs fine, but when trying to debug no variable watches are displayed and issuing commands just output errors like:

error: warning: Failed to load linked library swiftSwiftOnoneSupport of module SwiftOnoneSupport - errors:
Failed to find "libswiftSwiftOnoneSupport.dylib" in paths:
,  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator
  /usr/lib/swift
Failed to find "libswiftSwiftOnoneSupport.dylib" on RPATH, error: dlopen failed for unknown reasons.



error: <EXPR>:3:1: error: cannot find 'x' in scope
x
^

I've found instructions on this forum to enable logs and I've found more errors below:

 SwiftASTContext("MyAppWithPackages")::CreateInstance(Module)
 SwiftASTContext("MyAppWithPackages")::SetTriple("x86_64-apple-ios14.5.0-simulator") setting to "x86_64-apple-ios14.5.0-simulator"
 SwiftASTContext("MyAppWithPackages")::SetTriple("x86_64-apple-ios14.5.0-simulator") setting to "x86_64-apple-ios14.5.0-simulator"
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- Found 9 AST file data entries.
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "MyAppWithPackages" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxCoreData" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxSwift" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxCocoa" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxRelay" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxCoreData" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxSwift" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxCocoa" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- SDK path from module "RxRelay" was "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk".
 SwiftASTContext("MyAppWithPackages")::DeserializeAllCompilerFlags() -- Picking SDK path "".
 SwiftASTContext("MyAppWithPackages")::CreateInstance() -- Found serialized triple x86_64-apple-ios8.0-simulator.
 SwiftASTContext("MyAppWithPackages")::SetTriple("x86_64-apple-ios8.0-simulator") setting to "x86_64-apple-ios8.0-simulator"
 SwiftASTContext("MyAppWithPackages")::CreateInstance() -- No serialized SDK path.
 SwiftASTContext("MyAppWithPackages")::CreateInstance() -- Host SDK path is /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk.
 SwiftASTContext::GetResourceDir() -- trying toolchain path: 
 SwiftASTContext::GetResourceDir() -- trying Xcode path: /Applications/Xcode.app/Contents
 SwiftASTContext::GetResourceDir() -- trying Xcode-based lib path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift
 SwiftASTContext::GetResourceDir() -- found Swift resource dir via Xcode contents path + default toolchain relative dir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift
 SwiftASTContext("MyAppWithPackages")::GetASTContext() -- Using Clang module cache path: /Users/brunno/Library/Developer/Xcode/DerivedData/ModuleCache.noindex
 SwiftASTContext("MyAppWithPackages")::GetASTContext() -- SDK version: 14.5
 SwiftASTContext("MyAppWithPackages")::GetASTContext() -- Using prebuilt Swift module cache path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/prebuilt-modules/14.5
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules("MyAppWithPackages") retrieved 9 AST Data blobs from the symbol vendor.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "MyAppWithPackages" from Swift AST section 1 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxCoreData" from Swift AST section 2 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxSwift" from Swift AST section 3 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxCocoa" from Swift AST section 4 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxRelay" from Swift AST section 5 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxCoreData" from Swift AST section 6 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxSwift" from Swift AST section 7 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxCocoa" from Swift AST section 8 of 9.
 SwiftASTContext("MyAppWithPackages")::RegisterSectionModules() -- parsed module "RxRelay" from Swift AST section 9 of 9.
 SwiftASTContext("MyAppWithPackages")::GetModule("MyAppWithPackages")
 SwiftASTContext("MyAppWithPackages")::GetModule("MyAppWithPackages") -- <module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/Apptimize.h"
        ^

error: /Users/brunno/Library/Developer/Xcode/DerivedData/MyAppWithPackages-dkydaoxeegtwiccrxjvetzwpndty/Build/Products/Debug-iphonesimulator/Apptimize.framework/Headers/Apptimize.h:16:2: error: "The Apptimize library uses features only available in iOS SDK 11.0 and later."
#error "The Apptimize library uses features only available in iOS SDK 11.0 and later."
 ^

error: could not build Objective-C module 'Apptimize'

 SwiftASTContext("MyAppWithPackages")::CreateInstance((Module*)0x7fc4cad18f28, "MyAppWithPackages") = 0x7fc4cc030ca0
 SwiftASTContext("MyAppWithPackages")::() -- Failed to create module context - <module-includes>:1:9: note: in file included from <module-includes>:1:
#import "Headers/Apptimize.h"
        ^

error: /Users/brunno/Library/Developer/Xcode/DerivedData/MyAppWithPackages-dkydaoxeegtwiccrxjvetzwpndty/Build/Products/Debug-iphonesimulator/Apptimize.framework/Headers/Apptimize.h:16:2: error: "The Apptimize library uses features only available in iOS SDK 11.0 and later."
#error "The Apptimize library uses features only available in iOS SDK 11.0 and later."
 ^

error: could not build Objective-C module 'Apptimize'

To me it seems the error arises from the fact that it chose "x86_64-apple-ios8.0-simulator" for the environment when it doesn't satisfy the minimum support version for all packages.

Is this caused by an error in the packages specification? Or a bug?
How is the serialized triple chosen?

I could reproduce it with just a pair of dependencies in a simple project -> GitHub - brunnobga/swift-lldb-error-repro

LLDB deserializes the compiler invocation from the binary .swiftmodule files in "MyAppWithPackages". There are 9 of these and the last one wins. It looks like in your case the last .swiftmodule has a x86_64-apple-ios8.0-simulator deployment target. Can you look at your linker invocation for MyAppWithPackages and see what the last -add_ast_path option points to? Does that swiftmodule really have such a low deployment target?

I think I found a way to avoid this situation altogether: Initialize the Swift CompilerInstance with the triple from the load commands. by adrian-prantl · Pull Request #3634 · apple/llvm-project · GitHub

1 Like

Thank you for looking into this and for the clarifications above. I've checked the linker command and it does list RxRelay as the last one, which is declared with iOS8.

In my actual project I was able to fork the dependency equivalent to the last module and bump its deployment target, so I'm getting by with this workaround for now.

Will this change come as part of toolchain of a future Xcode version?

Sorry it took me this long to reply.

As soon as it's merged, the change will show up in the nightly toolchain builds downloadable from swift.org if you want to get notified when it lands in Xcode you can file an Apple feedback ticket about this issue (and send me the #) and it will get updated when the fix is available.