swift: swift repl on windows 11 not work

Describe the bug I downloaded and installed the latest swift. But when I followed the docs on https://www.swift.org/getting-started/#on-windows-1, it crashed.

Steps To Reproduce Steps to reproduce the behavior:

  1. Download and install swift-5.7 on windows 11
  2. Execute set SWIFTFLAGS=-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows
  3. Execute swift repl -target x86_64-unknown-windows-msvc %SWIFTFLAGS%

Expected behavior swift repl works as expected.

Screenshots image

Environment (please fill out the following information)

  • OS: Microsoft Windows [Version 10.0.22000.856]
  • Xcode Version/Tag/Branch: N.A.

Additional context

shell logs
C:\Users\Liu.D.H>swift --version
compnerd.org Swift version 5.7 (swift-5.7-RELEASE)
Target: x86_64-unknown-windows-msvc

C:\Users\Liu.D.H>where swift
C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swift.exe

C:\Users\Liu.D.H>swift

Welcome to Swift!

Subcommands:

  swift build      Build Swift packages
  swift package    Create and work on packages
  swift run        Run a program from a package
  swift test       Run package tests
  swift repl       Experiment with Swift code interactively

  Use `swift --help` for descriptions of available options and flags.

  Use `swift help <subcommand>` for more information about a subcommand.


C:\Users\Liu.D.H>echo %errorlevel%
0

C:\Users\Liu.D.H>set SWIFTFLAGS=-sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows

C:\Users\Liu.D.H>ver

Microsoft Windows [Version 10.0.22000.856]

C:\Users\Liu.D.H>swift repl -target x86_64-unknown-windows-msvc %SWIFTFLAGS%
Welcome to compnerd.org Swift version 5.7 (swift-5.7-RELEASE).
Type :help for assistance.
1> 1+2
Assertion failed: false && "called into swift language runtime stub", file D:\a\1\s\llvm-project\lldb\source\Plugins\LanguageRuntime\Swift\SwiftLanguageRuntime.cpp, line 392
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
 #0 0x00007ff71b784bd5 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe+0x24bd5)
 #1 0x00007ffdefb5cd84 (C:\Windows\System32\ucrtbase.dll+0x7cd84)
 #2 0x00007ffdefb5dd61 (C:\Windows\System32\ucrtbase.dll+0x7dd61)
 #3 0x00007ffdefb5f7ea (C:\Windows\System32\ucrtbase.dll+0x7f7ea)
 #4 0x00007ffdefb5f6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #5 0x00007ffdefb5f981 (C:\Windows\System32\ucrtbase.dll+0x7f981)
 #6 0x00007ffd53ce1039 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x6d1039)
 #7 0x00007ffd58ef8f54 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58e8f54)
 #8 0x00007ffd58efe9cb PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58ee9cb)
 #9 0x00007ffd58efbf7a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58ebf7a)
#10 0x00007ffd58ef63cb PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58e63cb)
#11 0x00007ffd539f6bfc PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3e6bfc)
#12 0x00007ffd53a05852 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3f5852)
#13 0x00007ffd539d3246 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3c3246)
#14 0x00007ffd5397e67a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x36e67a)
#15 0x00007ffd5397c53e PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x36c53e)
#16 0x00007ffdefb06c0c (C:\Windows\System32\ucrtbase.dll+0x26c0c)
#17 0x00007ffdf07454e0 (C:\Windows\System32\KERNEL32.DLL+0x154e0)
#18 0x00007ffdf1e8485b (C:\Windows\SYSTEM32\ntdll.dll+0x485b)

C:\Users\Liu.D.H>echo %errorlevel%
-2147483645

C:\Users\Liu.D.H>

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Little success. This is not a true solution, but a workaround that makes swift repl partially work on my Windows PC. Assuming Swift is installed on its default paths:

  1. if SDKROOT environment variable not set, then set it to C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk (just once in your Windows system environment variables)
  2. instead of running swift repl, you run lldb "--repl=-sdk %SDKROOT% -target x86_64-unknown-windows-msvc" (you can make this as a swiftrepl.cmd file and put it into a folder on your path)
  3. as first command you enter :expr (void*)LoadLibraryA("C:/Program Files/swift/runtime-development/usr/bin/swiftCore.dll")

This makes the Swift basic stuff start to work.

lldb "--repl=-sdk %SDKROOT% -target x86_64-unknown-windows-msvc"
Welcome to compnerd.org Swift version 5.7 (swift-5.7-RELEASE).
Type :help for assistance.
1> :expr (void*)LoadLibraryA("C:/Program Files/swift/runtime-development/usr/bin/swiftCore.dll")
(void *) $0 = 0x00007ffa2a090000
1> 1+2
$R0: Int = 3
2> let str="test"
str: String = "test"
3> str.uppercased()
$R3: String = "TEST"

Anyway, something is still not working:

4> print("test")
5>

(print does not print anything)

This works for me. But why this works?

image

I have the same issue. Could not get the Swift toolchain working in Windows 11.