Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swift repl on windows 11 not work #61062

Closed
liudonghua123 opened this issue Sep 13, 2022 · 17 comments
Closed

swift repl on windows 11 not work #61062

liudonghua123 opened this issue Sep 13, 2022 · 17 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. platform support REPL swift 5.7 Windows Platform: Windows

Comments

@liudonghua123
Copy link

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>
@liudonghua123 liudonghua123 added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Sep 13, 2022
@liudonghua123
Copy link
Author

Since I could not find the %ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Python37_64 after I installed Python37_64 in Visual Studio Installer, maybe the location is changed as https://docs.microsoft.com/en-us/visualstudio/python/installing-python-support-in-visual-studio?view=vs-2019#install-locations, So I installed the official Python37_64. But it's the same error.

C:\Users\Liu.D.H>set PATH=C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python37;%PATH%

C:\Users\Liu.D.H>where python
C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python37\python.exe
C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\python.exe
C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python38\python.exe
C:\Users\Liu.D.H\AppData\Local\Microsoft\WindowsApps\python.exe
C:\msys64\mingw64\bin\python.exe

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 0x00007ff7d8a14bd5 (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 0x00007ffd54b61039 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x6d1039)
 #7 0x00007ffd59d78f54 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58e8f54)
 #8 0x00007ffd59d7e9cb PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58ee9cb)
 #9 0x00007ffd59d7bf7a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58ebf7a)
#10 0x00007ffd59d763cb PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x58e63cb)
#11 0x00007ffd54876bfc PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3e6bfc)
#12 0x00007ffd54885852 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3f5852)
#13 0x00007ffd54853246 PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x3c3246)
#14 0x00007ffd547fe67a PyInit__lldb (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\liblldb.dll+0x36e67a)
#15 0x00007ffd547fc53e 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>

@Microtribute
Copy link

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

@stevapple
Copy link
Contributor

stevapple commented Sep 13, 2022

@Microtribute The toolchain should work well on both Windows 10 and 11. (In fact the toolchain was built against Windows 11 SDK) If anything but REPL was broken, feel free to file a new issue.

The REPL seems broken on Windows — both Windows 10 and 11, VS 2019 and 2022. Ideally after Swift 5.7 a single swift repl is enough for bringing it up, but any evaluation will crash.

@Microtribute
Copy link

@stevapple Thank you. Indeed. REPL doesn't work.

@honzaskypala
Copy link

honzaskypala commented Sep 20, 2022

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)

@liudonghua123
Copy link
Author

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

@bmaciag
Copy link

bmaciag commented Oct 4, 2022

@Microtribute The toolchain should work well on both Windows 10 and 11. (In fact the toolchain was built against Windows 11 SDK) If anything but REPL was broken, feel free to file a new issue.

The REPL seems broken on Windows — both Windows 10 and 11, VS 2019 and 2022. Ideally after Swift 5.7 a single swift repl is enough for bringing it up, but any evaluation will crash.

Any idea when this will be fixed?

@AlightYoung
Copy link

Same issue.

@kiagenwa
Copy link

same issue, but on Windows 10.

@elhe26
Copy link

elhe26 commented Dec 14, 2022

same issue on windows 10.

Edit:
I'm also getting <unknown>:0: error: could not load the swift standard library when running swift hello.swift.

@compnerd
Copy link
Member

This works for me. But why this works?

Because it is working around the LLDB issue that is currently the cause of this problem. The library search path is not honoured when loading the libraries, and the failure to load the library is silently ignored resulting in undefined references in the JIT'ed environment. The issue here is within LLDB and needs to be resolved.

@Wahid7852
Copy link

Same issue here

@GERMANOCARELLA
Copy link

Hi,
I have same issue. Wich are dll libraries must be loaded?

@lethal233
Copy link

Hi there, I have the exact same issue.

@christianfo
Copy link

Same issue for me.

@compnerd
Copy link
Member

compnerd commented Mar 28, 2023

Duplicate of #56026

@compnerd compnerd closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2023
@compnerd compnerd marked this as a duplicate of #56026 Mar 28, 2023
@compnerd
Copy link
Member

Unfortunately, GH does not transfer the subscribers when an issue is marked as duplicate. Just leaving a note here for those that are interested in this that I could use a bit of help with testing (I believe that this should be usable now with a recent snapshot). There are instructions for testing in #56026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. platform support REPL swift 5.7 Windows Platform: Windows
Projects
None yet
Development

No branches or pull requests