vscode-swift icon indicating copy to clipboard operation
vscode-swift copied to clipboard

Run Swift Script command doesn't work on Windows

Open svanimpe opened this issue 3 years ago • 9 comments

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

svanimpe avatar Sep 27 '22 12:09 svanimpe

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.

stevapple avatar Sep 27 '22 12:09 stevapple

Also running into the same issue.

I can run swiftc successfully at a PowerShell prompt:

image

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

image

I noticed the following settings:

image

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.

dharmatech avatar Feb 11 '23 05:02 dharmatech

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.

adam-fowler avatar Feb 13 '23 15:02 adam-fowler

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.

compnerd avatar Feb 13 '23 15:02 compnerd

Just wanted to clarify.

Compiling and running

Compiling with swiftc at a PowerShell prompt works fine and the resulting executable works:

image

Here's the output from evaluating that code:

image

Running with swift

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

image

runs into the issue:

image

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 avatar Feb 14 '23 05:02 dharmatech

@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.

compnerd avatar Feb 14 '23 05:02 compnerd

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?

Taschi120 avatar Jul 13 '24 19:07 Taschi120

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.

adam-fowler avatar Jul 13 '24 19:07 adam-fowler