Swift 5.4 Windows

Status of swift 5.4 on windows on my machine (Visual Studio 2019 and all required components are available, bla.swift is a simple print("bla") ):

  1. swiftc bla.swift:
    clang: error: no such file or directory: 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64\swiftrt.obj'
    :0: error: link command failed with exit code 1 (use -v to see invocation)

  2. swiftc bla.swift -sdk %SDKROOT% -I %SDKROOT%/usr/lib/swift -L %SDKROOT%/usr/lib/swift/windows

Works.

  1. swift package init --type executable

Works.

  1. swift build (above package)

C:\Users\Gon Solo\tmp\swift: error: manifest parse error(s):
:1:10: note: in file included from :1:
#include "dispatch.h"
^
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\dispatch/dispatch.h:66:10: note: in file included from C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\dispatch/dispatch.h:66:
#include <dispatch/time.h>
^
C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\include\dispatch/time.h:67:9: error: missing '#include <stdint.h>'; 'uint64_t' must be declared before it is used
typedef uint64_t dispatch_time_t;
^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include\stdint.h:25:28: note: declaration here is not visible
typedef unsigned long long uint64_t;
^
:0: error: could not build C module 'CDispatch'
:1:10: note: in file included from :1:
#include "DispatchOverlayShims.h"

One question and one remark:
Q: Is there any advice how to get 4. to work?
R: As long as I am not able to build a simple package without fiddling I consider swift on windows not usable. I'm happy to provide details to get this working.

1 Like

I suspect that there is something incorrect with the VS installation. There is likely is mismatch between the Windows SDK and the CRT headers (which are part of the compiler for whatever reason). Either that or the module.modulemap were not updated (see the support files part of the instructions for installation).

A few things:

I omitted the "recommended" and "In order to make the Windows SDK accessible to Swift" parts since they seemed to be not needed for a basic installation. Now I follows the instructions by word and get the following errors:

  1. "swift bla.swift":

:0: error: could not load the swift standard library

  1. "swiftc bla.swift":

C:\Users\Gon Solo\tmp\swift>swiftc bla.swift
clang: error: no such file or directory: 'C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows\x86_64\swiftrt.obj'
:0: error: link command failed with exit code 1 (use -v to see invocation)

I note that there is no directory "C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\swift\windows".

The interpreter is known to have issues in the installed mode. For the swiftc invocation, you need to add -sdk %SDKROOT%.

However, after following the full set of instructions, you should be able to build using either swiftc directly with the flags, with other build systems (e.g. CMake) or the Swift Package Manager.

  1. "swiftc -sdk $(SDKROOT) bla.swift" works. The compiled executable works too.

2a. "swift package init --type executable" works and gives the expected directory structure.
2b. "swift build" works too and the resulting binary under .build/debug works too.

Thank you very much. I'm going to test a bigger project now.

Terms of Service

Privacy Policy

Cookie Policy