VS Code won't run Swift on Windows

If you are running on Windows under parallels on macOS with ASi, then you are likely using the wrong installer. The ARM64 installer is not linked off the main download page yet (CC: @mishal_shah). I would recommend that you grab a recentish build from GitHub - thebrowsercompany/swift-build: Swift toolchain builds by The Browser Company if you want to run in that environment. Otherwise, you end up running the x64 binaries under emulation (PRISM) which does not cover the entire modern x64 landscape.

The arm64 toolchains are available on Swift.org - Install Swift

1 Like

Oh right, that is different from download.swift.org :man_facepalming:

@compnerd @adam-fowler @plemarquand It seems to work for most of my students, but one student can run but not debug a Swift Package (the dialog window is too small but I think it's complaining about not finding xctest). I think I created the diagnostic file that was mentioned earlier in this thread so I put both the package and the diagnostic file here:

https://reed.craft.me/mNPn7MxGApfWV2

We tried both Swift 5.10 and the Swift 6 snapshot but both produce the same error. I tried adding the directory containing the path to the xctest.dll to the Windows Path environment variable but that didn't help either. Any ideas?

Thanks,
Dave

Interesting, the XCTest path in the diagnostics looks correct, though they're using a newer Swift 6 snapshot than I have on my Windows machine so I'll have to update and double check.

Is there anything in their launch.json related to debugging?

The only time I've seen this is when there is a debug session already running, so restarting VS Code to be sure there are no other debugging sessions running. Another thing to check is if they have developer mode enabled.

@plemarquand thank you. we tried it with both Swift 5.10 that the winget command installed and then when that didn't work, we tried it with Swift 6 but the error dialog looks the same. I believe there is no launch.json. Selecting the testing (chemistry beaker icon) in the side bar of Visual Studio Code brings up an option where there are three buttons for the tests (run, debug, and test coverage) - at least when the code is a Swift Package even if there's not a launch.json file and works for me and for the other students. Pressing the Run button works and it shows the tests passed but pressing the Debug button does not work for this student.

I've asked the student to double-check that developer mode is turned on - I think it is or I don't think they would have gotten the other winget commands that installed everything to succeed (but I've used Windows more in the last 3 months getting this working than I've used Windows in the last 25 years so I could be wrong about that).

@plemarquand he said developer mode was enabled and even toggled it off and on.

I would suggest trying to get debugging to first work from the command line. If you can launch lldb and move up to lldb -- <program>, setting breakpoints, etc. it would help ensure that the environment is sane before trying to get it working under VSCode.

1 Like

@compnerd I'm not certain of the steps to debug unit tests, but I was able to create an executable with "swift package init --type executable" and then use "swift build, cd .build/debug, and then lldb file.exe in my Parallels/Windows 11 environment so I can try that with the student Tuesday on his computer. If you know the steps to do it with a regular swift package, I'm also happy to try that but I wasn't certain what executable to use within the .build directory for that.

@compnerd @plemarquand we were able to debug swift package of type executable using the PowerShell (set breakpoints, examined variables, stepped) using lldb commands. If we open that package in VSCode on his computer and tried to debug, we got errors:

Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)  
<unknown>:0: error: PCH was compiled with module cache path 'C:\Users\zapla\downloads\SCLI\SCLI\.build\x86_64-unknown-windows-msvc\debug\ModuleCache\3GXNRWEOZ3IE1', but the path is currently 'C:\Users\zapla\Downloads\SCLI\SCLI\.build\x86_64-unknown-windows-msvc\debug\ModuleCache\3GXNRWEOZ3IE1'
<unknown>:0: error: missing required module 'SwiftShims'
<unknown>:0: error: PCH was compiled with module cache path 'C:\Users\zapla\downloads\SCLI\SCLI\.build\x86_64-unknown-windows-msvc\debug\ModuleCache\3GXNRWEOZ3IE1', but the path is currently 'C:\Users\zapla\Downloads\SCLI\SCLI\.build\x86_64-unknown-windows-msvc\debug\ModuleCache\3GXNRWEOZ3IE1'
<unknown>:0: error: missing required module 'SwiftShims'

Does the missing SwiftShims mean something isn't installed or perhaps VSCode isn't finding something?

Thanks,
Dave

I see a difference in case in 'Downloads' versus 'downloads'. Looks like a bug in Swift Package Manager that's not taking into account case insensitive file systems. Could you raise an issue there for me?

@dschaefer2 Do you want an issue in the VSCode Swift extension or at swift.org?

Nope, here: Issues · swiftlang/swift-package-manager · GitHub

The issue is with swift build which is part of the swift-package-manager.

Thanks!

@dave256 If that error is indeed the issue then perhaps you can work around it by:

  1. Deleting C:\Users\zapla\Downloads\SCLI\SCLI\.build\ completely
  2. Moving the project to a lowercase location like C:\Users\zapla\projects\SCLI
  3. Rebuild and try again.

Hopefully this clears out the cache and negates any case sensitivity.

@dschaefer2 bug filed: issue building on case-insensitive file systems · Issue #7938 · swiftlang/swift-package-manager · GitHub

@plemarquand Yes, I thought of that as soon as @dschaefer2 pointed out the issue that I hadn't pick up on. I've already asked the student to stop by again so we can try that.

@dschaefer2 I still wonder if it's an issue in VSCode rather than swift-package-manager. It seemed to work from the Windows terminal but not from VSCode for packages of type executable. We still get a simple "Error code 1" for a regular Swift Package in VSCode.

@plemarquand @dschaefer2 @compnerd

Putting the package in a directory that was all lower case allowed us to use VSCode to debug a swift package of type executable with breakpoints and examining the variables, but if we put a regular swift package in that same all lower case directory, it does not work. It builds in VSCode although there are some warnings (see output below) but just pops up an error wanting to open the launch.json dialog rather than running/debugging it as it does for me and the other students using Windows except this one student.

Building for debugging...
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTests09RectangleD0C8testInityyF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTests09RectangleD0C8testMoveyyF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTests09RectangleD0C9testScaleyyF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTestsAAC7testSqryyKF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTests09RectangleD0CMn (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s24SwiftExamplePackageTestsAACMn (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageTests.build\runner.swift.o: locally defined symbol imported: $s019SwiftExamplePackageC15DiscoveredTests05__alldE0Say6XCTest0G4CaseCm04testH5Class_SaySS_yAEKctG0fE0tGyF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackagePackageDiscoveredTests.build\all-discovered-tests.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage3sqryS2dF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleV7centerX0E1Y5width6heightACSd_S3dtcfC (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleV8topLeftX0eF1Y5width6heightACSd_S3dtcfC (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleVN (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleVSQAAMc (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleV4move2dx2dyySd_SdtF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
lld-link: warning: C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackageTests.build\SwiftExamplePackageTests.swift.o: locally defined symbol imported: $s19SwiftExamplePackage9RectangleV5scale2sx2syySd_SdtF (defined in C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\.build\x86_64-unknown-windows-msvc\debug\SwiftExamplePackage.build\SwiftExamplePackage.swift.o) [LNK4217]
[26/26] Linking C:\Users\zapla\swift\SwiftExamplePackage\SwiftExamplePackage\…  
Build complete! (23.11s)

Those warnings are typical at the moment. But they are warnings and the job did report "Build Complete" so it should be fine. I'll hand it back to @plemarquand for the VSCode side.

The case sensitivity issue is still a swiftpm issue since it should work no matter for any case sent from the command line or vscode. We need to add code to do proper conversions.

1 Like

@plemarquand

I installed the official Swift 6 Arm release in Parallels on my M1 Mac and now I'm in the same situation as the one student - I can run tests, but not debug them. I tried it with both the new Testing framework (which it now finds without editing the Package.swift file) and with XCTest but neither work when using the debug option. Any ideas on how we can get this working? Thanks. Since I can reproduce it on a computer I always have access to it will be easier for me to help track the issue down.

Here is what I see in the Output tab if I select Swift:

09:47:12: Swift version 6.0 (swift-6.0-RELEASE)
Swift Path: C:\Users\dreed\AppData\Local\Programs\Swift\Toolchains\6.0.0+Asserts\usr\bin
Toolchain Path: C:\Users\dreed\AppData\Local\Programs\Swift\Toolchains\6.0.0+Asserts\usr
Runtime Library Path: C:\Users\dreed\AppData\Local\Programs\Swift\Runtimes\6.0.0\usr\bin
Default Target: aarch64-unknown-windows-msvc
Default SDK: C:\Users\dreed\AppData\Local\Programs\Swift\Platforms\6.0.0\Windows.platform\Developer\SDKs\Windows.sdk\
XCTest Path: C:\Users\dreed\AppData\Local\Programs\Swift\Platforms\6.0.0\Windows.platform\Developer\Library\XCTest-development\usr\bin64a
09:47:12: SourceKit-LSP setup
09:47:15: NSP: add: c:\Users\dreed\Desktop\NSP
09:47:15: NSP: Resolving Dependencies: starting ... 
09:47:15: Exec Task: (NSP) swift package resolve
09:47:15: NSP: focus: c:\Users\dreed\Desktop\NSP
09:47:17: NSP: Resolving Dependencies: ... done.
09:47:22: Exec Task: (NSP) swift build --build-tests -Xlinker -debug:dwarf -Xswiftc -diagnostic-style=llvm
09:47:24: NSP: XCTest Debug Config: {"type":"swift-lldb","request":"launch","sourceLanguages":["swift"],"name":"XCTest: Test NSP","cwd":"c:\\Users\\dreed\\Desktop\\NSP","args":["NSPTests.NSPTests/testSeries"],"preLaunchTask":null,"terminal":"console","program":"c:\\Users\\dreed\\Desktop\\NSP\\.build\\debug\\NSPPackageTests.xctest","env":{"Path":"C:\\Users\\dreed\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.0\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\bin64a;C:\\Program Files\\Parallels\\Parallels Tools\\Applications;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Git\\cmd;C:\\Users\\dreed\\AppData\\Local\\Programs\\Python\\Python39-arm64\\Scripts\\;C:\\Users\\dreed\\AppData\\Local\\Programs\\Python\\Python39-arm64\\;C:\\Users\\dreed\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\dreed\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Users\\dreed\\.dotnet\\tools;C:\\Users\\dreed\\AppData\\Local\\Programs\\Swift\\Runtimes\\6.0.0\\usr\\bin\\;C:\\Users\\dreed\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.0+Asserts\\usr\\bin\\;"},"testType":"XCTest"}
09:47:27: Error: "Debugger not started"

What is Python version? liblldb.dll depends on python39.dll