Issues Installing Swift on Windows 10

I'm attempting to install & compile Swift programs with the Swift compiler on Windows 10.

I first downloaded & installed the Swift compiler for Windows from the official Swift website. I have Visual Studio 2022 Community Edition, with the Desktop development with C++ package installed.

I then followed the official Windows tutorial on the Swift website, and tried both the Windows Package Manager method and the Traditional method. In each case, I couldn't access any of the Swift commands in either the Visual Studio Native Command Prompt or the standard Windows Command Prompt. swift and swiftc are unrecognized commands.

Albeit, I did create an Environment Variable for SDKROOT with C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk (which does appear to contain the Swift libraries), yet it did not appear to fix the issue.

I also made sure that the visualc.modulemap and visualc.apinotes files that I was copying using the VS Native Command Prompt according to the tutorial had the correct naming of vcruntime.modulemap and vcruntime.apinotes, according to the following post.

Additionally, if I send an echo %PATH% command to a Command Prompt to see whether I have a Swift path in the global environment variable, I saw a C:\Program Files\Swift\runtime-development\usr\bin path present in the resultant path list. That path appears to contain a variety of DLL files relating to Swift and a single executable called plutil.exe.

I then followed the following tutorial, where the instructor followed most of the same steps described in the Traditional method of the official Swift website tutorial, and attempted to compile a swift file to an executable. Yet, my swift and swiftc commands still remained unaccessible in any Command Prompt.

I then followed the following tutorial, where the instructor creates a makefile and attempts to build a swift file using that. However, attempting to run the nmake build command in a Command Prompt on a makefile called build simply resulted in the message 'build' is up-to-date. I'm not familliar with the makefile program building methods, so I may very well be missing something here. The swift and swiftc commands remained unaccessible.

What is the proper way to install Swift on a Windows 10 system? Does Swift only work with Visual Studio 2019, and not 2022?

Thanks for reading my post, any guidance is appreciated.

Visual Studio 2022 is fine.

One of the tutorials you mentioned uses a make file which is not the vanilla way of working with Swift. You should work with the Swift Package Manager as described on the Swift website without any manual setting of SDKROOT, and no copying of modulemap files etc. is necessary with a current Swift version (on the Swift website is says this method is for older Swift versions only). The commands to use the Swift Package Manager should be available after the installation of Swift because the installer sets the according paths. At least “swift --version” should give you some result.

Swift on Windows has been (and still is) evolving fast and you should not rely on older posts, but stick with the description on the Swift website. Be sure not to set any additional environment variable etc. without any additional insight.

If you managed to compile a program in the command line you then should have a look at Visual Studio Code with the Swift extension by the Swift Server Group.

2 Likes

Thanks for your reply;

I wanted to try out the Switf Package Manager, however I'm really confused as to how exactly I'm supposed to access it...

On the website it says it supposedly comes with a Swift 3.0 installation. I installed Swift on my Windows system from the link in my original post, so I should be able to access it via the command prompt, but like I said in my original post I can't access any Swift commands on any command prompt. Even attempting swift --version results in swift being an unrecognized command.

Am I not supposed to run Swift commands in the regular Windows command prompt, but a specific command prompt?

It appears it was finally solved. I completely reinstalled everything relating to Swift, but this time I followed the following guide, and installed the Swift toolchain via the Command Prompt instead of the installer from the website. I see now that there are also many more files in the Swift Libraries folder that previously weren't there, so something got messed up the first time... I'm finally able to access the swift commands via the command prompt.

Regardless, that's a really good guide for installing Swift on Windows and other systems.

So your installation did not set the according paths, if this is indeed the case maybe the installer should do an according check and display an according error message if possible?

CC: @stevapple , @compnerd

That does appear to be the case, as after installing via the command prompt I noticed the presence of the SDKROOT path in the environment variable settings that I removed manually prior to resintalling, as well as the presence of several Swift paths in the echo %PATH% list. It appears that they were inserted when I installed via the command prompt, allowing me to access the swift.exe executable properly.

What's even stranger is the fact that swift.exe wasn't even present in the Libraries folder when I first installed it using the installer from the website... it only appeared after the command prompt method.

But it may also have been something wrong that was done on my part when I was first installing using the installer from the website, it's a bit hard to tell at this point.