vscode-swift
vscode-swift copied to clipboard
Run Swift Script command doesn't work on Windows
The "swift: Run Swift Script" command doesn't work on Windows, as is to be expected.
It shows the same error as when running swift file.swift on the command line:
<unknown>:0: error: could not load the swift standard library
Environment: Swift 5.7 on Windows 11
Seems to duplicate https://github.com/swift-server/vscode-swift/issues/416#issuecomment-1245374734?
It should be a Swift Driver bug which is pure toolchain-related. Once the Swift Driver bug is fixed, we should be able to use the feature.
Also running into the same issue.
I can run swiftc successfully at a PowerShell prompt:

However, if I use the Run Swift Script command in vscode, I get the following:

I noticed the following settings:

I tried setting the SDK to:
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk
and the Runtime Path to:
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows
and
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift
however, setting those don't appear to resolve the issue.
The last time I looked running swift scripts on Windows was broken ie running swift <file>. @compnerd should be able to give us the latest details on that. Maybe they are fixed in the 5.8 development build.
No, the underlying issue is LLDB, not Swift. There has been no one who has stepped up to help work on LLDB, so this is still not available.
Just wanted to clarify.
Compiling and running
Compiling with swiftc at a PowerShell prompt works fine and the resulting executable works:

Here's the output from evaluating that code:

Running with swift
However, running test.swift directly via swift at a PowerShell prompt

runs into the issue:

Test file
The file test.swift contains:
print("abc")
Comments
Since the same error is occurring at the prompt when using swift directly, it seems as if the issue may not be with vscode-swift, but in some other place.
@dharmatech correct. swift ... is running the swift file as a script, which runs it through the interpreter, which is using LLDB. swift compiles the code, doesn't interpret it.
Do I understand the above comments correctly: Running Swift with LLDB is not currently possible on Windows at all, and Swift code thus cannot be debugged on Windows?
Do I understand the above comments correctly: Running Swift with LLDB is not currently possible on Windows at all, and Swift code thus cannot be debugged on Windows?
No this is about running swift as a script. You can use LLDB to debug Swift executables.