Swift repl on windows: Error: could not create a swift AST context

Hi all,

I've installed Swift on Windows 10 (specifically, Windows 10 21H2 (AMD64) build 19044.5011, if that matters), with all the VS dependencies, but whenever I run the swift REPL (swift repl) I get the following output:

==== LLDB swift-healthcheck log. ===
This file contains the configuration of LLDB's embedded Swift compiler to help diagnosing module import and search path issues. The swift-healthcheck command is meant to be run *after* an error has occurred.
lldb version 17.0.6
Swift version 6.0.2 (swift-6.0.2-RELEASE)
Cannot create Swift scratch context (couldn't load the Swift stdlib)SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration(SwiftASTContext*)0000013DC1863C40:
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Swift/C++ interop                : off
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Swift/Objective-C interop        : off
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Architecture                     : x86_64-unknown-windows-msvc
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   SDK path                         : C:\Users\Ethin
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Runtime resource path            : C:\Users\Ethin Probst\AppData\Local\Programs\Swift\Toolchains\6.0.2+Asserts\usr\lib\swift
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Runtime library paths            : (2 items)
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin Probst\AppData\Local\Programs\Swift\Runtimes\6.0.2\usr\bin
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin Probst\AppData\Local\Programs\Swift\Toolchains\6.0.2+Asserts\usr\lib\swift\windows
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Runtime library import paths     : (4 items)
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin Probst\AppData\Local\Programs\Swift\Toolchains\6.0.2+Asserts\usr\lib\swift\windows
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin Probst\AppData\Local\Programs\Swift\Toolchains\6.0.2+Asserts\usr\lib\swift\windows\x86_64
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin\usr\lib\swift\windows
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --     C:\Users\Ethin\usr\lib\swift\windows\x86_64
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Framework search paths           : (0 items)
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Import search paths              : (0 items)
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Extra clang arguments            : (0 items)
SwiftASTContextForExpressions::lldb_private::SwiftASTContext::LogConfiguration() --   Plugin search options            : (0 items)
Welcome to Swift version 6.0.2 (swift-6.0.2-RELEASE).
Type :help for assistance.
1> print("Hello, world!")
error: could not create a Swift AST context

1>

Is the REPL on Windows broken or did I screw up the install somewhere?

Unfortunately, there was a regression with the REPL on Windows with Swift 6. There is an open PR that does make it work at ExpressionParser: inherit the environment for the REPL by compnerd · Pull Request #9334 · swiftlang/llvm-project · GitHub but it does seem like it may be currently stuck.

CC: @al45tair

I should also note that I can't build anything. If I do swift package init --type executable and then swift run I get:

error: 'swift-hello-world': Invalid manifest (compiled with: ["C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\ETHINP~1\\AppData\\Local\\Temp\\TemporaryDirectory.8dGzex\\vfs.yaml", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\", "-libc", "MD", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "6", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "6.0.0", "C:\\Users\\Ethin Probst\\source\\swift-hello-world\\Package.swift", "-o", "C:\\Users\\ETHINP~1\\AppData\\Local\\Temp\\TemporaryDirectory.bMRyNS\\swift-hello-world-manifest.exe"])
<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc'
error: 'swift-hello-world': Invalid manifest (compiled with: ["C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\ETHINP~1\\AppData\\Local\\Temp\\TemporaryDirectory.9uux0J\\vfs.yaml", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\", "-libc", "MD", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\x86_64", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows", "-L", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.2\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows\\x86_64", "-use-ld=lld", "-swift-version", "6", "-I", "C:\\Users\\Ethin Probst\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.2+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "6.0.0", "C:\\Users\\Ethin Probst\\source\\swift-hello-world\\Package.swift", "-o", "C:\\Users\\ETHINP~1\\AppData\\Local\\Temp\\TemporaryDirectory.M3DRJo\\swift-hello-world-manifest.exe"])
<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc'

Are you running on a VM on ASi? The standard library for x64 should be installed by default on x64 hardware.

Nope, I'm running on bear metal. I think it's installed; there's a Library and SDKs directory under platform\windows.platform\developer. But Swift seems to have no idea where the stdlib is at. I just followed the standard install instructions for using winget, though I did need to repair the install afterwards since it didn't look like it installed everything on first run.

I would reboot and reinstall. There are a few cases where I have seen the installer not install part of the files and haven't been able to isolate what is happening.

I would if this weren't the (second) installation I've performed. The first wouldn't allow me to remove it because it gave me error code 2318, which from my research is a MAX_PATH problem (and I've enabled long paths I'm pretty sure). I had to forcefully remove it to actually uninstall it. But I can try again I suppose.

Okay, so I got it to work, but it took a couple tries. I would strongly encourage you guys to switch to another installer framework like InnoSetup or something if MSIs are this much of a problem.

This isn't an MSI problem. There is something that we are missing and it is unclear what. The MSI and MSIX are the standard installer framework that is used for everything inbox so this seems very much an oversight on our part.