compnerd/swift-win32

no such module 'SwiftWin32'

universedocs opened this issue · 26 comments

I'm using Windows 10 through Parallels virtual machine in macOS BigSur in Mac. I've installed the December 14, 2020 toolchain snapshot from swift.org! I've set all the things as in swift getting started! The REPL is not working! The example projects are building, but not able to create .exe file due to the below error!

C:\Users\kumarmuthaiah\Documents\Projects>ninja -C build Calculator
ninja: Entering directory `build'
[1/1] Linking Swift executable Calculator\Calculator.exe
FAILED: Calculator/Calculator.exe Calculator/CMakeFiles/Calculator.dir/Calculator.swift.obj Calculator/Calculator.swiftmodule
cmd.exe /C "cd . && C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -output-file-map Calculator\CMakeFiles\Calculator.dir\Release\output-file-map.json -incremental -j 2 -emit-executable -o Calculator\Calculator.exe -emit-dependencies -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -O -libc MD -parse-as-library -sdk C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk -O -libc MD ..\Calculator\Calculator.swift -lSwiftWin32.lib -lSwiftWin32.lib && cmd.exe /C "cd /D C:\Users\kumarmuthaiah\Documents\Projects\build\Calculator && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_if_different C:/Users/kumarmuthaiah/Documents/Projects/Calculator/Calculator.exe.manifest C:/Users/kumarmuthaiah/Documents/Projects/build/Calculator""
..\Calculator\Calculator.swift:8:8: error: no such module 'SwiftWin32'
import SwiftWin32
^
ninja: build stopped: subcommand failed.

The REPL is not really needed to build this project. The error indicates that the SwiftWin32 module is not there. That is interesting since there should be a dependency for that. A workaround would be to do ninja -C build SwiftWin32 Calculator.

The thing is that the target_link_libraries here should be sufficient for the dependency.

What version of CMake are you using to build?

Closing the issue for now; feel free to re-open if you still run into this and can provide the additional information.

Thanks! ninja command you told not working! Check below. Can you tell me where "SwiftWin32" library is located? I check! As far as i know i see only "swiftWinSDK.lib" in "C:\Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\x86_64"

Extra information needed:
Regarding Swift on windows how far it is ready? Can we use it to develop full fledged applications? Does it support UICollectionView, etc., all UI kit classes? Does it support all Foundation classes, images, file access, camera access, etc.,? Can i access database like mongodb or realm db? Does it support networking? Does it support invoking web service? When we can expect? Can I see the roadmap online? Can i see the features online? I feel Swift is better than UWP for Windows, so that we can have single programming language for all platforms and destroy the competition which delays humanity progress! Actually we need cooperation to do it with single programming language! If we work for single and people buy single, then cost will reduce!

The commands I've executed are as follows:
cmake -B build -D BUILD_SHARED_LIBS=YES -D CMAKE_BUILD_TYPE=Release -D CMAKE_Swift_FLAGS="-sdk %SDKROOT%" -G Ninja -S .
ninja -C build SwiftWin32 UICatalog

CMake details:
c:\Users\kumarmuthaiah\Documents\Projects>cmake --version
cmake version 3.18.20081302-MSVC_2

Errors:
c:\Users\kumarmuthaiah\Documents\Projects>ninja -C build SwiftWin32 Calculator
ninja: Entering directory `build'
ninja: error: unknown target 'SwiftWin32'

c:\Users\kumarmuthaiah\Documents\Projects>ninja -C build Calculator SwiftWin32
ninja: Entering directory `build'
ninja: error: unknown target 'SwiftWin32'

SwiftWin32 is the library being built by this project itself. It is difficult to tell what is going on without a full verbose log. Please attach the full verbose log from a clean build, including the configure phase.

From the error messages, it seems that you are building something other than this project.

Regarding Swift on windows how far it is ready? Can we use it to develop full fledged applications? Does it support UICollectionView, etc., all UI kit classes? Does it support all Foundation classes, images, file access, camera access, etc.,? Can i access database like mongodb or realm db? Does it support networking? Does it support invoking web service? When we can expect? Can I see the roadmap online? Can i see the features online? I feel Swift is better than UWP for Windows, so that we can have single programming language for all platforms and destroy the competition which delays humanity progress! Actually we need cooperation to do it with single programming language! If we work for single and people buy single, then cost will reduce!

This is not a general purpose support channel for Swift on Windows. This is a personal project of mine to deal with UI aspects on Windows in Swift and to experiment with Swift. I think that your questions are better suited for an alternate forum for discussions/questions.

Saleem: SwiftWin32 is the library being built by this project itself. It is difficult to tell what is going on without a full verbose log. Please attach the full verbose log from a clean build, including the configure phase.
From the error messages, it seems that you are building something other than this project.

Kumar: I don't know much about windows development! Can you help me on how to turn verbose on? Can you clearly tell the steps to be done? I love to see this project takes off and goes well! It gives a better future to all!

Saleem: This is not a general purpose support channel for Swift on Windows. This is a personal project of mine to deal with UI aspects on Windows in Swift and to experiment with Swift. I think that your questions are better suited for an alternate forum for discussions/questions.

Kumar: It is a great effort you put for swift on Windows! I appreciate it! Is there anything you cannot answer? I felt to ask here since your project as been refered in swift.org which is a public place for swift loving/curious peoples! Those who love swift expect to be available in all platforms! If it is not refered in swift.org I will not be disturbing you! I feel this project will benefit everybody not you alone! We need to start feeling as a whole not ourselves alone! Why I need to talk in alternate forum, if it relates to swift on windows? I just mentioned swift for windows and its future and the current problems! I don't fear for Microsoft or competitors or status quo! I just need a good solution that benefits whole humanity, but not few! Swift for windows is a great thing! Hope you take it in positive way! I'm just encouraging your work! But still it is your freedom and you can do and take it whatever way you want!

Kumar: I don't know much about windows development! Can you help me on how to turn verbose on? Can you clearly tell the steps to be done? I love to see this project takes off and goes well! It gives a better future to all!

This isn't about Windows development, it is about industry standard tools. You can find documentation at https://cmake.org/cmake/help/latest/manual/cmake.1.html#options for CMake. Look for the log level information.

Alternatively, you can try to building with SPM as well (you will need to use the latest snapshot for building in any case).

Kumar: It is a great effort you put for swift on Windows! I appreciate it! Is there anything you cannot answer? I felt to ask here since your project as been refered in swift.org which is a public place for swift loving/curious peoples! Those who love swift expect to be available in all platforms! If it is not refered in swift.org I will not be disturbing you! I feel this project will benefit everybody not you alone! We need to start feeling as a whole not ourselves alone! Why I need to talk in alternate forum, if it relates to swift on windows? I just mentioned swift for windows and its future and the current problems! I don't fear for Microsoft or competitors or status quo! I just need a good solution that benefits whole humanity, but not few! Swift for windows is a great thing! Hope you take it in positive way! I'm just encouraging your work! But still it is your freedom and you can do and take it whatever way you want!

Thanks. While I do have the answers to the questions you are asking, the point is that this space is meant for specifically for this personal project. Making this place a location for general purpose discussion for Swift on Windows detracts from this project. Sure, it was mentioned on swift.org, but the fact remains that general discussions on Swift are better suited at the Swift Forums.

However, I also think that you should attempt to answer many of the questions that are clearly already been answered (either on the forums or the blog post) before simply asking the same questions over again. Answers take time and can be draining if they are the same questions asked repeated

You are very protective not to spend single second to help me! You making me spend more energy! There is something you missed to inform that causes error! why you moving away from cmake? Spm is the best approach and your examples work for spm instantly or i need to put extra effort? Im trying to run your example projects only not any other!

I dont know about cmake i cannot drain my energy without someone gives proper introduction on cmake! I tried getting verbose on not worked irritating!

Saying to search forum for already solved problem is easy to say but it is difficult since that is not human friendly and is not connected well!

As a developer Im saying you should have started with spm! something forced you to make it fast and hence it causes problems to user! users need to drain more energy! if you itself not respect others energy how come you expect others to see you?

How this issue can be invalid as marked in GitHub without properly investigating or giving proper reply?

There is something you missed to inform that causes error!

I'm sorry, I don't understand what you are saying here. I "missed to inform"? I didn't inform you of anything, I merely responded to a question.

why you moving away from cmake?

I am not moving away from CMake, I'm not sure why you believe that. I am trying to keep two different approaches working simultaneously:

  1. CMake - ideal for development and CI purposes. It really is significantly easier to work with CMake to generate the required layout to quickly iterate, as well as have partially completed work laying about while I continue to make progress.

  2. SPM is useful to have working in the case that someone wishes to use the library (SwiftWin32) in another project which may be using SPM. As I've been working towards getting SPM more usable on Windows, this becomes more useful. Additionally, having SPM support means that it is possible to actually use SourceKit LSP for completion, which some seem to desire.

Given that there are multiple different use cases, which are better served with the different build systems, I am forced to keep both as viable options. I would prefer not to mandate which build system people use, but rather have the infrastructure in place so that people can make an informed choice.

Spm is the best approach and your examples work for spm instantly or i need to put extra effort? Im trying to run your example projects only not any other!

You should read the documentation (which is prominent on the project page). It explains how to get setup with SPM if you want to try that approach. No, SPM does not "just work", though CMake should.

As a developer Im saying you should have started with spm

This is exactly why I am not forthcoming with answers - you presume to understand everything without having investigated what is going on. SPM is NOT the answer. I did the port to support SPM on Windows, and so I am a far more qualified to make that call, particularly when it comes to a personal project that is being done without compensation. Please look at the time lines of this project and the time lines for SPM. The SPM port was not even working when this project started and usable already.

SPM does not support the needs of a full GUI application on non-iOS targets. There is a long road to actually getting SPM working, and if you would like to work on that, it would be fantastic!

Examples of immediately important things which are not supported by SPM:

  1. Code signing
  2. additional file copying (e.g. executable manifests)
  3. auxiliary file support (e.g. custom Info.plist)

That list is not meant to be exhaustive, there are many others including the following:

  1. custom extension points
  2. execution of non-toolchain tools (e.g. mc, rc, etc)
  3. handling of foreign debug information formats (CodeView vs DWARF vs STABS)
  4. installation (staging the artifacts for distribution)
  5. packaging (stdlib needs to be packaged for distribution)
  6. ability to run arbitrary tools (e.g. building installers)

The issue is marked as being invalid as there is no documentation for anything actionable. The CI clearly demonstrates the CMake build working. If there is something actionable, I can certainly try to have a look or guide someone else to try to resolve the issue.

I'm not a swift programming language developer! Thanks for trying to get support for you! The love towards seeing Swift in Windows 10 made me comment like as above. I'm a freelance software engineer and trainer! I like to train Swift in Windows 10 since many don't have Linux or Mac. At least command line applications i need to teach if Swift based UI is not ready yet in windows 10. Some don't have memory (4GB RAM in students laptop in India) to install virtual OS. Hope you help! Is there any IDE in windows that allows us to debug things using your swift toolchain? Can you help me to solve the issues in running UI applications? I see in issues list others able to run! Can you help or point out to right person to get help! I know you are very busy and not getting help!

It should be possible to setup VSCode to debug with lldb. It should be a slight bit easier to debug the swift side of things with lldb, though I've also used WinDBG. That said, I haven't tried to setup VSCode for debugging as I don't use an IDE myself. That would largely be outside the realm of this project, though I think that there are people on the swift forums who may be interested in that.

Following instructions on the swift forums to get started would be most effective. Once you have the basic compilation process working which indicates that your setup is correct, getting swift/Win32 working would be much simpler.

The one thing to note is that this project requires the latest snapshot from the development branch, not the stable release. See the readme for details on the project requirements.

Now it is working and able to run Calculator, UICatalog and HelloWorld. You have missed to tell your users that have to download and copy the contents of "cassowary" and "SwiftCOM" to the projects "Packages" directory. Please mention it so that new users can identify it and not get into problems. I used the latest trunk based development snapshot of the tool chain! "swift build" command is working for command line applications. When we are adding support for UICollectionView? Full UI support planed? I'm a past Visual C++ programmer!

Hmm, you shouldn't have to download them. If you build with CMake, it should download it automatically when it builds. SPM will fetch all the dependencies when it builds as well. What occurred to make you build/fetch them yourself?

C:\Users\kumarmuthaiah\Documents\swift-win32-main>cmake -B build -D BUILD_SHARED_LIBS=YES -D CMAKE_BUILD_TYPE=Release -D CMAKE_Swift_FLAGS="-sdk %SDKROOT%" -G Ninja -S .
-- Building with sub-modules:
-- Cassowary rG
-- Swift/COM rG
-- Configuring done
CMake Error at Sources/CMakeLists.txt:1 (add_library):
Cannot find source file:

C:/Users/kumarmuthaiah/Documents/swift-win32-main/Packages/cassowary/Sources/Cassowary/Constraint.swift

Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx

CMake Error at Sources/CMakeLists.txt:14 (add_library):
Cannot find source file:

C:/Users/kumarmuthaiah/Documents/swift-win32-main/Packages/SwiftCOM/Sources/SwiftCOM/COMBase.swift

Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx

CMake Error at Sources/CMakeLists.txt:1 (add_library):
No SOURCES given to target: Cassowary

CMake Error at Sources/CMakeLists.txt:14 (add_library):
No SOURCES given to target: SwiftCOM

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

You need to do a clean build as the logs are incomplete otherwise. I suspect that you are not in a x64 native developer command prompt, and this the VS tools are not found.

I'm in that command prompt only. How to clean build?

That will not work. You MUST be in the developer command prompt, this is pretty thoroughly documented. Just remove the build directory and reconfigure for a clean build.

You need to let me know how to do it! I'm not touch with windows development! in year 2000 I've done Visual C++! "x64 native developer command prompt" or some other developer command prompt?

"x64 Native Tools Command Prompt for VS 2019" this is the shortcut i've executed. So it is developer command prompt right? i followed the instruction and created a shortcut in desktop to launch it in administrator mode

This is well documented in a number of places, from swift.org to the forums, to other resources. This has always been conveyed in a reasonable form. You should seek out and read those instructions. I don't see the value in repeating this information in every single document.

Anywhere mentioned how to reconfigure for a clean build.? Let me know i follow it

The CMake documentation should cover that. I would recommend any of the many amazing getting started videos on YouTube or docs.cmake.org or the many blog posts and even the numerous books. This is an industry standard tool.

Furthermore, I even described the process above.

OK fine i look into it! Thanks for your support!