About swift-win32 build

Hi,

I installed Swift 5.3 and set up the environment by referring to On Windows@Getting Started.
A simple console app could use swiftc to create an .exe.

Next, I downloaded and built a demo calculator example.
As a result, CMake worked, but I got the following error on ninja:
Is there anything I overlooked?

Thanks.

C:\swift-win32>ninja -C build SwiftWin32 Calculator
ninja: Entering directory `build'
[1/2] Linking Swift shared library bin\SwiftWin32.dll
FAILED: bin/SwiftWin32.dll 
Sources/CMakeFiles/SwiftWin32.dir/Application/Application.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Application/ApplicationDelegate.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Application/ApplicationMain.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AlertAction.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AlertController.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AnimationCurve.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Button.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Color.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ContentContainer.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Control.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/DatePicker.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Device.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/EdgeInsets.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Font.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Label.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ProgressView.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Screen.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Slider.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Stepper.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Switch.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TextField.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TextView.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TraitCollection.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TraitEnvironment.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/View.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewController.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewControllerTransitionCoordinator.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewControllerTransitionCoordinatorContext.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Window.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/WindowClass.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/AffineTransform.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Point.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Rect.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Size.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/BatteryMonitor.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/Logging.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/Rect+UIExtensions.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/PropertyWrappers.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/String.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/WindowsHandle.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/WinSDK+Extensions.swift.obj swift/SwiftWin32.swiftmodule lib/SwiftWin32.lib
cmd.exe /C "cd . && C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -output-file-map Sources\CMakeFiles\SwiftWin32.dir\Release\output-file-map.json -incremental -j 4 -emit-library -o bin\SwiftWin32.dll -module-name SwiftWin32 -module-link-name SwiftWin32 -emit-module -emit-module-path swift\SwiftWin32.swiftmodule -emit-dependencies -DSwiftWin32_EXPORTS -sdk C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -I C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift -L C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift/windows -O -libc MD   -Xcc -DNONAMELESSUNION -Xcc -DCOBJMACROS  ..\Sources\Application\Application.swift ..\Sources\Application\ApplicationDelegate.swift ..\Sources\Application\ApplicationMain.swift ..\Sources\UI\AlertAction.swift ..\Sources\UI\AlertController.swift ..\Sources\UI\AnimationCurve.swift ..\Sources\UI\Button.swift ..\Sources\UI\Color.swift ..\Sources\UI\ContentContainer.swift ..\Sources\UI\Control.swift ..\Sources\UI\DatePicker.swift ..\Sources\UI\Device.swift ..\Sources\UI\EdgeInsets.swift ..\Sources\UI\Font.swift ..\Sources\UI\Label.swift ..\Sources\UI\ProgressView.swift ..\Sources\UI\Screen.swift ..\Sources\UI\Slider.swift ..\Sources\UI\Stepper.swift ..\Sources\UI\Switch.swift ..\Sources\UI\TextField.swift ..\Sources\UI\TextView.swift ..\Sources\UI\TraitCollection.swift ..\Sources\UI\TraitEnvironment.swift ..\Sources\UI\View.swift ..\Sources\UI\ViewController.swift ..\Sources\UI\ViewControllerTransitionCoordinator.swift ..\Sources\UI\ViewControllerTransitionCoordinatorContext.swift ..\Sources\UI\Window.swift ..\Sources\UI\WindowClass.swift ..\Sources\CG\AffineTransform.swift ..\Sources\CG\Point.swift ..\Sources\CG\Rect.swift ..\Sources\CG\Size.swift ..\Sources\Support\BatteryMonitor.swift ..\Sources\Support\Logging.swift ..\Sources\Support\Rect+UIExtensions.swift ..\Sources\Support\PropertyWrappers.swift ..\Sources\Support\String.swift ..\Sources\Support\WindowsHandle.swift ..\Sources\Support\WinSDK+Extensions.swift    -Xlinker -implib:lib\SwiftWin32.lib  -lComCtl32.lib  -lUser32.lib  -ldispatch.lib  -lFoundation.lib && cd ."
..\Sources\UI\TextField.swift:68:21: error: cannot find type 'PARAFORMAT' in scope
      var pfFormat: PARAFORMAT = PARAFORMAT()
                    ^~~~~~~~~~
..\Sources\UI\TextField.swift:69:43: error: cannot find type 'PARAFORMAT' in scope
      pfFormat.cbSize = UINT(MemoryLayout<PARAFORMAT>.size)
                                          ^~~~~~~~~~
..\Sources\UI\TextField.swift:70:31: error: cannot find 'PFM_ALIGNMENT' in scope
      pfFormat.dwMask = DWORD(PFM_ALIGNMENT)
                              ^~~~~~~~~~~~~

ninja: build stopped: subcommand failed.

Issues related to Swift/WIn32 belong on the Swift/Win32 repository.

In this particular case, your toolchain is just at an older point, and the associated modulemap for the Windows SDK needs to be updated.

Thank you for your reply.

I re-downloaded the toolchain and updated the modulemap as below, but the result was the same.

copy %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap"
copy %SDKROOT%\usr\share\visualc.apinotes "%VCToolsInstallDir%\include\visualc.apinotes"
copy %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"

I have tried the following methods I found on this site.

copy %SDKROOT%\usr\share\ucrt.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt\module.modulemap"
copy %SDKROOT%\usr\share\visualc.modulemap "%VCToolsInstallDir%\include\module.modulemap"
copy %SDKROOT%\usr\share\ucrt.modulemap "%VCToolsInstallDir%\include\visualc.apinotes"
copy %SDKROOT%\usr\share\winsdk.modulemap "%UniversalCRTSdkDir%\Include\%UCRTVersion%\um\module.modulemap"

The result is a different error.

C:\swift-win32>ninja -C build SwiftWin32 Calculator
ninja: Entering directory `build'
[1/2] Linking Swift shared library bin\SwiftWin32.dll
FAILED: bin/SwiftWin32.dll Sources/CMakeFiles/SwiftWin32.dir/Application/Application.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Application/ApplicationDelegate.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Application/ApplicationMain.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AlertAction.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AlertController.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/AnimationCurve.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Button.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Color.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ContentContainer.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Control.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/DatePicker.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Device.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/EdgeInsets.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Font.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Label.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ProgressView.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Screen.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Slider.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Stepper.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Switch.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TextField.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TextView.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TraitCollection.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/TraitEnvironment.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/View.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewController.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewControllerTransitionCoordinator.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/ViewControllerTransitionCoordinatorContext.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Window.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/WindowClass.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/AffineTransform.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Point.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Rect.swift.obj Sources/CMakeFiles/SwiftWin32.dir/CG/Size.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/BatteryMonitor.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/Logging.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/Rect+UIExtensions.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/PropertyWrappers.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/String.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/WindowsHandle.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/WinSDK+Extensions.swift.obj swift/SwiftWin32.swiftmodule lib/SwiftWin32.lib
cmd.exe /C "cd . && C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -output-file-map Sources\CMakeFiles\SwiftWin32.dir\Release\output-file-map.json -incremental -j 4 -emit-library -o bin\SwiftWin32.dll -module-name SwiftWin32 -module-link-name SwiftWin32 -emit-module -emit-module-path swift\SwiftWin32.swiftmodule -emit-dependencies -DSwiftWin32_EXPORTS -sdk C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -I C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift -L C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift/windows -O -libc MD   -Xcc -DNONAMELESSUNION -Xcc -DCOBJMACROS  ..\Sources\Application\Application.swift ..\Sources\Application\ApplicationDelegate.swift ..\Sources\Application\ApplicationMain.swift ..\Sources\UI\AlertAction.swift ..\Sources\UI\AlertController.swift ..\Sources\UI\AnimationCurve.swift ..\Sources\UI\Button.swift ..\Sources\UI\Color.swift ..\Sources\UI\ContentContainer.swift ..\Sources\UI\Control.swift ..\Sources\UI\DatePicker.swift ..\Sources\UI\Device.swift ..\Sources\UI\EdgeInsets.swift ..\Sources\UI\Font.swift ..\Sources\UI\Label.swift ..\Sources\UI\ProgressView.swift ..\Sources\UI\Screen.swift ..\Sources\UI\Slider.swift ..\Sources\UI\Stepper.swift ..\Sources\UI\Switch.swift ..\Sources\UI\TextField.swift ..\Sources\UI\TextView.swift ..\Sources\UI\TraitCollection.swift ..\Sources\UI\TraitEnvironment.swift ..\Sources\UI\View.swift ..\Sources\UI\ViewController.swift ..\Sources\UI\ViewControllerTransitionCoordinator.swift ..\Sources\UI\ViewControllerTransitionCoordinatorContext.swift ..\Sources\UI\Window.swift ..\Sources\UI\WindowClass.swift ..\Sources\CG\AffineTransform.swift ..\Sources\CG\Point.swift ..\Sources\CG\Rect.swift ..\Sources\CG\Size.swift ..\Sources\Support\BatteryMonitor.swift ..\Sources\Support\Logging.swift ..\Sources\Support\Rect+UIExtensions.swift ..\Sources\Support\PropertyWrappers.swift ..\Sources\Support\String.swift ..\Sources\Support\WindowsHandle.swift ..\Sources\Support\WinSDK+Extensions.swift    -Xlinker -implib:lib\SwiftWin32.lib  -lComCtl32.lib  -lUser32.lib  -ldispatch.lib  -lFoundation.lib && cd ."
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\visualc.apinotes:1:1: error: not a mapping
//===--- ucrt.modulemap ---------------------------------------------------===//
^
:1:10: note: in file included from :1:
#include "AssertionReporting.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:
#include "SwiftStdint.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: could not build module 'visualc'
#include <stdint.h>
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:10: note: while building module 'ucrt' imported from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:
#include <stddef.h>
         ^
:1:10: note: in file included from :1:
#include "complex.h"
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:10: note: in file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:10:10: error: could not build module 'visualc'
#include <vcruntime.h>
         ^
:0: error: could not build C module 'SwiftShims'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\visualc.apinotes:1:1: error: not a mapping
//===--- ucrt.modulemap ---------------------------------------------------===//
^
:1:10: note: in file included from :1:
#include "AssertionReporting.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:
#include "SwiftStdint.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: could not build module 'visualc'
#include <stdint.h>
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:10: note: while building module 'ucrt' imported from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:
#include 
         ^
:1:10: note: in file included from :1:
#include "complex.h"
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:10: note: in file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:10:10: error: could not build module 'visualc'
#include <vcruntime.h>
         ^
:0: error: could not build C module 'SwiftShims'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\visualc.apinotes:1:1: error: not a mapping
//===--- ucrt.modulemap ---------------------------------------------------===//
^
:1:10: note: in file included from :1:
#include "AssertionReporting.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:
#include "SwiftStdint.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: could not build module 'visualc'
#include <stdint.h>
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:10: note: while building module 'ucrt' imported from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:
#include <stddef.h>
         ^
:1:10: note: in file included from :1:
#include "complex.h"
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:10: note: in file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:10:10: error: could not build module 'visualc'
#include <vcruntime.h>
         ^
:0: error: could not build C module 'SwiftShims'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\visualc.apinotes:1:1: error: not a mapping
//===--- ucrt.modulemap ---------------------------------------------------===//
^
:1:10: note: in file included from :1:
#include "AssertionReporting.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:10: note: in file included from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/AssertionReporting.h:16:
#include "SwiftStdint.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStdint.h:28:10: error: could not build module 'visualc'
#include <stdint.h>
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:10: note: while building module 'ucrt' imported from C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/SwiftStddef.h:25:
#include <stddef.h>
         ^
:1:10: note: in file included from :1:
#include "complex.h"
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:10: note: in file included from C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt/complex.h:12:
#include <corecrt.h>
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt\corecrt.h:10:10: error: could not build module 'visualc'
#include <vcruntime.h>
         ^
:0: error: could not build C module 'SwiftShims'
ninja: build stopped: subcommand failed.

Is there any other solution?

The result isn't the same at all - the error message is very different :slight_smile:

I believe that you copied the wrong command - you have copied ucrt.modulemap to visualc.apinotes which is the reason for the failure here.

I downloaded and installed the toolchain (October 15, 2020).
As a result, I was able to create an .exe.
Thank you very much.

Terms of Service

Privacy Policy

Cookie Policy