Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SourceKitD fails to load standard library with iOS Simulator SDK 18.2 #1374

Open
rovo79 opened this issue Feb 11, 2025 · 4 comments
Open

SourceKitD fails to load standard library with iOS Simulator SDK 18.2 #1374

rovo79 opened this issue Feb 11, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@rovo79
Copy link

rovo79 commented Feb 11, 2025

Describe the bug
The Swift VS Code extension (swiftlang.swift-vscode) fails to load the standard library, causing the SourceKitD provider to fail. This occurs when trying to work with Swift files in VS Code.

To Reproduce
Steps to reproduce the behavior:

  1. Open VS Code with a Swift project
  2. Configure swift.SDK path in settings.json to point to iOS Simulator SDK
  3. Open a Swift file
  4. Extension fails with error: "sourcekitd request failed: error response (Request Failed): Loading the standard library failed"

Expected behavior
The Swift extension should properly initialize and provide language services (formatting, intellisense, etc.) for Swift files.

Environment

  • OS: macOS 15.2
  • Swift: swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
    Target: arm64-apple-macosx15.0
  • Visual Studio Code version: 1.97.0
  • vscode-swift version: 2.0.0

Additional context
Settings.json configuration:

  • Using iOS Simulator SDK path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.2.sdk
  • Platform: iphonesimulator
  • Target: arm64-apple-ios18.2-simulator

Error occurs during extension activation with 'onLanguage:swift' trigger.

RAW output:

activationEvent: 'onLanguage:json'
2025-02-11 05:53:24.059 [info] ExtensionService#_doActivateExtension swiftlang.swift-vscode, startup: false, activationEvent: 'onLanguage:swift'
2025-02-11 05:53:25.617 [error] [swiftlang.swift-vscode] provider FAILED
2025-02-11 05:53:25.742 [error] Error: sourcekitd request failed: error response (Request Failed): Loading the standard library failed
    at handleResponse (/Users/NAME/.vscode/extensions/swiftlang.swift-vscode-2.0.0/node_modules/vscode-jsonrpc/lib/common/connection.js:565:48)
    at handleMessage (/Users/NAME/.vscode/extensions/swiftlang.swift-vscode-2.0.0/node_modules/vscode-jsonrpc/lib/common/connection.js:345:13)
    at processMessageQueue (/Users/NAME/.vscode/extensions/swiftlang.swift-vscode-2.0.0/node_modules/vscode-jsonrpc/lib/common/connection.js:362:17)
    at Immediate.<anonymous> (/Users/NAME/.vscode/extensions/swiftlang.swift-vscode-2.0.0/node_modules/vscode-jsonrpc/lib/common/connection.js:334:13)
    at processImmediate (node:internal/timers:483:21)
@award999
Copy link
Contributor

as a workaround, does it work if you set the swift.swiftSDK setting? Not sure the ID you need, maybe arm64-apple-ios. See #1335 (comment)

@rbenegal
Copy link
Contributor

Thanks for reporting this @rovo79, could you please also mention how you are setting the platform to iphonesimulator and target to arm64-apple-ios18.2-simulator? I am unable to reproduce any issues with loading the standard library by only specifying a swift.sdk path (which is different from swift.swiftSDK) that points to the iOS SDK path in Xcode.app.

@rovo79
Copy link
Author

rovo79 commented Feb 13, 2025

@rbenegal I've set it in settings.json:

{
  "swift.sourcekit-lsp.trace.server": "messages",
  "swift.SDK": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.2.sdk",
  "swift.platform": "iphonesimulator",
  "swift.targets": ["WaterRings"],
  "swift.buildArguments": [
    "-sdk",
    "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator18.2.sdk",
    "-target",
    "arm64-apple-ios18.2-simulator"
  ],
  "[swift]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "swiftlang.swift-vscode"
  }
}

@rbenegal
Copy link
Contributor

Thank you for providing the details. I'm able to reproduce some version of this now, and I think it may have to do with SourceKit trying to use macOS settings with an iOS SDK specified with swift.SDK, as I also see this in the SourceKit indexer logs:

[1:53:25 PM]  <unknown>:0: error: unable to load standard library for target 'arm64-apple-macosx10.13'

This should be fixed with support added for target triples in Swift 6.1 and some version of a fix from #1335 will also be needed to get code editing support for other platforms. I'm not sure if there is a way to do this with Swift 6 or earlier.

For now, it seems like the way around it is to use a 6.1 toolchain (currently still under development- so a development snapshot would be required from https://www.swift.org/install/macos/) with setting swift.swiftSDK, for example:

{
"swift.swiftSDK": "arm64-apple-ios18.2-simulator",
"swift.path": "/Library/Developer/Toolchains/swift-6.1-DEVELOPMENT-SNAPSHOT-2025-01-13-a.xctoolchain/usr/bin",
}

should enable code editing support. As well, I'm not sure if simulator specific code editing support is supported by SourceKit-LSP but general non-macOS code editing features should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

3 participants