compnerd/swift-win32

WinSDK Build Error

fdncred opened this issue · 2 comments

I didn't want to pile on in the CMake error issue but I tried building the swift-win32 repo with 5.3 and just now with the dev release from 9/22 and both give the same error.

cmake seems to work

C:\Users\username\source\repos\swift-win32>cmake -B build -D BUILD_SHARED_LIBS=YES -D CMAKE_BUILD_TYPE=Release -D CMAKE_Swift_FLAGS="%SWIFTFLAGS%" -G Ninja -S .
-- The C compiler identification is MSVC 19.27.29112.0
-- The CXX compiler identification is MSVC 19.27.29112.0
-- The Swift compiler identification is Apple 5.3
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Swift compiler: C:/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe
-- Check for working Swift compiler: C:/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/swiftc.exe - works
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/username/source/repos/swift-win32/build

ninja seems to fail

ninja: Entering directory `build'
[1/2] Linking Swift shared library bin\SwiftWin32.dll
FAILED: bin/SwiftWin32.dll Sources/CMakeFiles/SwiftWin32.dir/Application/_TriviallyConstructible.swift.obj 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/Application/Information.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Application/LaunchKeyOptions.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/Responder.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/Scene.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/SceneConfiguration.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/SceneDelegate.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/SceneSession.swift.obj Sources/CMakeFiles/SwiftWin32.dir/UI/SceneSizeRestrictions.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/TextInputTraits.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/WindowScene.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/Error.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+UIExtensions.swift.obj Sources/CMakeFiles/SwiftWin32.dir/Support/WindowClass.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 12 -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  @CMakeFiles\SwiftWin32.rsp    -Xlinker -implib:lib\SwiftWin32.lib  && cd ."
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
<unknown>:0: error: cannot load underlying module for 'WinSDK'
ninja: build stopped: subcommand failed.

I have the latest Windows sdk installed 10.0.19041.0 but I'm not sure if it's using it properly.

[EDIT]
I take it back. I can see with cmake-gui.exe that it does find the win sdk because it has this defined
C:/Program Files (x86)/Windows Kits/10/bin/10.0.19041.0/x64/mt.exe

ok. i think i figured out this problem. The readme.md on this repo doesn't tell you everything. I stumbled upon the getting started with swift page and it mentions this key bit of info.

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"

and now i get this with ninja, which appear to be warnings.

ninja -C build SwiftWin32 UICatalog
ninja: Entering directory `build'
[1/2] Linking Swift shared library bin\SwiftWin32.dll
..\Sources\UI\View.swift:137:15: warning: immutable value 'hPreviousParent' was never used; consider replacing with '_' or removing it
    guard let hPreviousParent: HWND = SetParent(view.hWnd, self.hWnd) else {
          ~~~~^~~~~~~~~~~~~~~
          _
..\Sources\Support\Error.swift:42:28: warning: '_wcserror' is deprecated: This function or variable may be unsafe. Consider using _wcserror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
      if let description = _wcserror(errno) {
                           ^
   Creating library lib\SwiftWin32.lib and object lib\SwiftWin32.exp
[2/2] Linking Swift executable bin\UICatalog.exe
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "LibcOverlayShims.h"
         ^
C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk\usr\lib\swift\shims/LibcOverlayShims.h:103:10: warning: '_open' is deprecated: This function or variable may be unsafe. Consider using _sopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
  return _open(path, oflag, (int)mode);
         ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt/corecrt_io.h:420:24: note: '_open' has been explicitly marked deprecated here
        _Check_return_ _CRT_INSECURE_DEPRECATE(_sopen_s)
                       ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include/vcruntime.h:320:55: note: expanded from macro '_CRT_INSECURE_DEPRECATE'
        #define _CRT_INSECURE_DEPRECATE(_Replacement) _CRT_DEPRECATE_TEXT(    \
                                                      ^
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.27.29110\include/vcruntime.h:310:47: note: expanded from macro '_CRT_DEPRECATE_TEXT'
#define _CRT_DEPRECATE_TEXT(_Text) __declspec(deprecated(_Text))
                                              ^
   Creating library bin\UICatalog.lib and object bin\UICatalog.exp

Correct, this repository is for the Swift/Win32 package. It assumes that you have setup the toolchain properly, I don't think it makes sense to have installation instructions for Swift as part of this project. If you would like to improve the installer for Windows, compnerd/swift-build is the correct place for that.

These are, as you stated, warnings. You should have a UICatalog.exe in the build directory that you should be able to run now. Feel free to open another issue if you run into an issue with the library or demo programs.