Swift installation problem on Windows

Powershell regards curl to be an alias (short name) of Invoke-WebRequest, and its interface is different from the real curl CLI. That’s why you’re getting such error output.

With any other shell, you should get the correct output. If you tend to use PowerShell, there’s also a simple solution: just replace curl with curl.exe, and PowerShell will correctly refer to it as the curl CLI.

Thanks I would never have guessed. curl ran OK with regular command prompt.

Now if I enter the next command in regular prompt:

start /w vs_community.exe --passive --wait --norestart --nocache ^
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

I get error message "cannot find vs-community.exe", although I have Visual Studio 2019 installed and running perfectly... I saw on the Internet that it has been renamed "devenv.exe", but this sounds fishy...

I also tried the same command in power shell, but then I get lots of syntax error messages (???):

At line:2 char:5

  • --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Com ...
  • ~
    

Missing expression after unary operator '--'.
At line:2 char:5

  • --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Com ...
  • ~~~~~~~~~~~
    

Unexpected token 'installPath' in expression or statement.
At line:3 char:5

  • --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  • ~
    

Missing expression after unary operator '--'.
At line:3 char:5

  • --add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
  • ~~~
    

Unexpected token 'add' in expression or statement.
At line:4 char:5

  • --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64
  • ~
    

The commands must be run under cmd, not PowerShell. They are fundamentally incompatible, and you cannot create a script which runs under both.

It is fine if you don't want to install another version of Visual Studio, but make sure that you are installing the C++ Desktop workload (which is likely ~25-30G) in addition to the C# workload. The instructions are designed to minimally install Visual Studio (that is the C++ Build tools, and Windows SDK) and so may actually not give you a fully working Visual Studio installation.

The Swift errors indicate that you do not have the necessary components installed. Once you have adjusted the Visual Studio installation, you will need to re-install Swift.

Thanks Saleem,

I just want to install swift on Windows so that I can recompile my Swift programs on Windows, and I am following exactly the instructions written on the Swift.org page. I am OK with using the regular prompt command for the installation, and I have no problem installing the "C++ Desktop workload" or any other missing componant, even though I don't know how. Can you tell me what command I should type in after:

curl -sOL https://aka.ms/vs/16/release/vs_community.exe

(which runs fine) and:

start /w vs_community.exe --passive --wait --norestart --nocache ^
--installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community" ^
--add Microsoft.VisualStudio.Component.Windows10SDK.19041 ^
--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64

Which produces error messages...

Thanks in advance
--Max

As you already have Visual Studio partly installed, I don’t know of a good (safe) way to automate it. You could just go to “Add Remove Programs”, find “Visual Studio Installer” and modify the installation. Add in the C++ workload (or you can try to add just the necessary components). Once the new items are installed, repair the swift installation from the “Add Remove Programs” dialog.

Thanks for your patience Saleem,

"C++ Desktop workload" does not show up in any of the installation options I see in the "Workloads" page (see attached screenshot), and if I look up the keyword "Desktop" in the page "Individual Components", no component shows up...

"Desktop Development with C++" is the workload you are looking for (third row on the right).

Thanks Saleem; (actually the option was checked, but I had not rebooted the computer).

Now the command works. Then I ran

c:> del /q vs_community.exe
c:> pip install six

Then I downloaded and installed swift, then I ran:

c:> winget install Swift.Toolchain

and I got following command to work fine:

c:\Users\Max> swift —version
compnerd.org Swift version 5.6.2 (swift-5.6.2-RELEASE)
Target: x86_64-unknown-windows-msvc

However, if I enter the command "swift", I now get following error message (note that I did install python and it seems to work fine):

c:\Users\Max> swift
Python path configuration:
PYTHONHOME = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
PYTHONPATH = (not set)
program name = 'python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe'
sys.base_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.base_exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.platlibdir = 'lib'
sys.executable = 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\lldb.exe'
sys.prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.exec_prefix = 'C:/hostedtoolcache/windows/Python/3.10.2/x64'
sys.path = [
'C:\Users\Max\AppData\Local\Programs\Python\Python310\python310.zip',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\DLLs',
'C:/hostedtoolcache/windows/Python/3.10.2/x64\lib',
'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00002748 (most recent call first):

Hmm, I thought the changes for python made it into 5.6.2. In any case, that is semi expected. Use the compiler not the interpreter. There are some more issues to be resolved there (the details are on the forums).

Thanks Saleem,

Actually I dont need to use the REPL, and I managed to build packages and compile my Swift programs on Windows and they run perfectly on my PC.
However, when I sent them to a colleague, he got a series of error messages about missing components: "swiftCRT.dll", "swiftCore.dll", "Foundation.dll", "swiftWinSDK.dll". There might be other missing components but he gave up at this point...

Anyways:

  • do you know the list of all the .dll files that are required to run the compiled .exe on Windows 10, so they can run on any Windows 10 PC?
  • almost none of the users of my programs are computer savvy; it would be too much to ask them to install some developer tools or ask them to manage Visual Studio installer components... If I just copy these required .dll files in the same directory as my compiled .exe programs, will that solve the "missing .dll file" problems?

—Max

If you installed Swift through the installer, you can find all the runtime stuff in %systemdrive%\Library\Swift-development\bin.

I also suppose that if you can inspect the installer, you should be able to extract the runtime MSI which can copy the files and set up environment variables for you automatically.

1 Like

Depending on the version of the toolchain, the runtime is available in %ProgramFiles%\swift\runtime-development\usr\bin.

1 Like

Thanks Saleem,

I have nor problem installing multiple dev tools to compile the Swift programs for Windows on my dev PC.

However, I cannot ask my "clients" (students in literature studies) who are using these programs to install dev tools, as they are not computer savvy and anyways have very limited access rights to the university's lab computers.

Is there any way to compile the Swift programs so that the .exe files include all the libraries necessary to run autonomously?

If not, can I just add all necessary files (.dll ?) to my distribution .zip directory, and if so, which ones?

Thanks
--Max

Unfortunately static linking still has some problems on Windows, and you can distribute the DLLs along (yeah that works). The Swift runtime libraries are in either the path I or @compnerd mentioned above, depending on the Swift toolchain version you’re using.

Also notice that if you’re using Foundation or using Swift 5.5 or earlier, you may need to copy ICU runtime libraries too.

1 Like

OK, I have added the 13 .dll files inside the same directory as my .exe.

I had installed swift-5.6.2-RELEASE on my dev Windows PC to compile the programs; do you know where the ICU runtime libraries are typically located? I could not find any ICU directory nor file.

As I am not using any Swift post v5.5 functionality (async) nor construct (@Sendable closure) in my source code, I assume that the ICU .dll files are not required.

ICU will be required if you used Foundation. :eyes: You’re likely using it unless you explicitly opt it out of your code.

ICU libraries should be located in %systemdrive%\Library\icu-69.1\usr\bin for Swift 5.6.2, go and check them out.

1 Like

OK done. Thanks stevapple
--Max

You can. If you are feeling adventurous, you can also use dark from the WiX toolset to extract the runtime and ICU MSIs from the installer package. Those contain all the runtime distribution components. I would like to see the MSIs available as a separate entity for redistribution (that is equivalent to the MSVCRT redistributable that you can download from Microsoft).

@mishal_shah can probably speak to what is needed for supporting additional download options.

See my comment in another topic.

See also this comment by @compnerd.