compnerd/swift-win32

Can't compile example

Higher08 opened this issue · 13 comments

I have done and installed everything as in getting started on swift.org.
But when I try to execute make command (copied from Readme) I have this error

The C compiler

    "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx86/x86/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/Dmytro/Downloads/swift-win32-main/swift-win32-main/Examples/UICatalog/build/CMakeFiles/CMakeTmp

What I'm doing wrong?

With swift build --product UICatalog I have invalidManifestError (could not build C module "SwiftOverlayShims"
Also, when I run x86 Native Tools Command Prompt, UniversalCRTSdkDir is not defined. I don't think it's correct

You won't be able to build with the x86 toolset, this project currently is not 32-bit clean. Furthermore, once #699 is merged, the project exposes limitations in the Swift toolchain wrt calling convention handling that will prevent the correct argument handling resulting in a failure from within the callbacks from Win32 to handle the events.

The errors sound like you didn't follow the installation instructions correctly and the deployment of the modulemaps failed which results in being unable to access the system headers. I would say that you should uninstall Swift, reinstall Visual Studio (ensuring that you add the necessary C/C++ components or just install the C/C++ workload support) and then re-install the Swift toolchain.

I don't build with the x86 toolset, I'm trying to execute these commands from https://www.swift.org/getting-started/ (support files).

The following will modify your Visual Studio Installation, and as such will require to be run from an (elevated) “Administrator” x86 Native Tools for VS2019 Command Prompt.

I tried reinstalling VS, but this doesn't help. I'm using VS2022 with the latest MSVC, it's not a problem?
P.S in vs installer I selected CMake support and msvc only

P.S in vs installer I selected CMake support and msvc only

I think that this is the problem. You aren't installing all the necessary pieces of Visual Studio. The necessary components are listed on the getting started page. The easiest thing to do is to just install the C++ workload. Once that is installed properly, reinstall Swift.

Thanks, I didn't install Win 10 SDK (instead installed Win 11 SDK).
But now I have another error

-- Generating done
-- Configuring done
CMake Error: CMake can not determine linker language for target: UICatalog
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_Swift_FLAGS


CMake Generate step failed.  Build files cannot be regenerated correctly.

With swift build build succeeded, but .build directory is not even created and because of that it is unable to create symbolic link unable to create symbolic link
unable to create symbolic link at C:\Users\Dmytro\Documents\swiftdev\swift-win32\.build\debug: Error Domain=NSCocoaErrorDomain Code=256 "(null)"

I think that you’re using an older CMake. Make sure that you’re using the latest release.

The symlink error is not due to the directory not existing. You are not running as administrator nor do you have a GPO applied to allow you to create symbolic links. Yet another alternative is to enable developer mode.

This is all due to setup issues, most of this is covered in depth on the swift forums. Please search through them in the future.

It was not a problem with the installation. I ran the Cmake from the folder of the project itself, but I needed swift-win32. Maybe add this to the readme because it seems non-obvious?
Thanks, running x64 native tools as an administrator helped (although I had developer mode already enabled)

Patches to improve the documentation are welcome :)

Ok, I will open PR later)
Do I understand correctly that I can’t run an exe on a system without swift installed, even if I copy all the dlls?

The generated binary can be run on other Windows 10 machines if you copy the runtime and the other DLLs. The runtime redistributable is packaged as a separate MSI though it's not available as a separate download currently.

So, Swift doesn't allow to generate fat binaries with runtime like .net?

Correct. Static linking isn't yet possible for Windows, so that is also not yet an option. You should be able to build tooling to package up the dependencies though (this was the approach that Swift used initially on other platforms as well).