swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
734 stars 50 forks source link

Run Swift Script command doesn't work on Windows #423

Open svanimpe opened 1 year ago

svanimpe commented 1 year ago

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

stevapple commented 1 year ago

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.

dharmatech commented 1 year ago

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.

adam-fowler commented 1 year ago

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.

compnerd commented 1 year ago

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.

dharmatech commented 1 year ago

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.

compnerd commented 1 year ago

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

Taschi120 commented 2 months ago

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?

adam-fowler commented 2 months ago

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.