Recently I've came across this lovely language, I love the syntax and I wanted to see if I could make a simple Hello World application for Windows, but compiled on Linux. Other programming languages have this feature, such as GoLang for example which makes it extremely easy to make a Windows executable from Linux. I should also make it clear that I do not use Windows in any capacity, and am only interested in compiling for it because it is very popular and necessary if I'm going to use Swift for applications in the future.
However, from the resources I've found about cross compiling to Windows, nothing has worked, Wine won't run Swift and won't install the Windows 10 SDK. There is an ISO file, which contains msi files and other stuff, but I don't really know how to extract it properly or what files Swift needs from it. There's seemingly no dedicated swift-windows-gnu SDK and I'm not sure about mingw64, from what I've seen, Swift doesn't have support for that out of the box, do I really have to recompile Swift with that functionality? I've successfully been able to install Swift on Wine, that's one step closer, right? But running Swift on Wine gives me this error: wine: Call from 00006FFFFFC6A918 to unimplemented function ADVAPI32.dll.SaferiIsExecutableFileType, aborting
This is kind of an open ended question and from the looks of things, I'll need to either make a Windows 10 VM or dual boot Windows to actually cross compile and that's something I reaaally don't want to do. The recommended "Swift SDK" only supports cross-compilation across Linux. I have Wine and was thinking of using that to run main.exe to test, If there's anything you guys could do to help, that would be appreciated. If I have to recompile something, I'll do whatever it takes. Perhaps I am mistaken and compiling to Windows from Linux is easier now in 2025 than it was years ago? Please let me know!
The most mature port for Windows is the native Windows support. That does use some relatively new features (RS5 is the baseline). There is no WIndows SDK that is currently available on Linux. However, it would be possible to build the (Swift) SDK for Windows for Linux (it really is just that you need to build with the same compiler). There is current work in progress which will hopefully make the SDK a bit more portable and you would be able to simply grab the SDK from the Windows builds.
However, the Swift SDK alone is insufficient to build for Windows. It requires a copy of the Windows SDK and Visual Studio toolset (though we only need the toolset for the MSVC runtime headers and import libraries).
The generated binaries would also not be very easy to run under Wine as they would use the same function that you are already hitting issues against wine with (e.g. ADVAPI32 being incomplete). You will eventually need/want a real Windows installation.
The reason that Go/rust are easier to work with for cross-compiling is because they do not build against the Microsoft libraries/headers and thus do not get the same level of integration as Swift does. One of the benefits of Swift is the deep systems integration which requires using the Microsoft vended SDK.
If you are keen on using MinGW, there was a port but that has been dormant for quite some time and would take some effort to revive.
It's a shame that things are the way they are right now, I can always develop now for Linux only and just wait for proper support in the future, or continue to use other languages like Go in the meantime. I guess in a way, I can compile for WIndows, but that would require me to get a virtual machine set up or something like that. I'm not scared of losing storage space or anything or my internet speed, I just think having to install 10+ GB just to compile for Windows is a bit ridiculous (considering that I don't personally use it on a day to day basis, but I guess a Windows VM would be inevitable at some point).
I'm personally not too knowledgeable about MinGW and have no idea how much it would take to get it working with Swift, that seems out of my depth. I was hoping to just pick up Swift and use it like other programming languages, I recently compiled a Raylib project in Go for Windows, on Linux and sent it to a friend and I also ran that in Wine and that worked just fine, but as for Swift, for the past few days, I've been wrapping my head around topics like this in order to determine if this programming language is the right one for me.
If I'm desperate, I guess I'll go make that VM then, but as for now, I can do without it, I suppose. Hopefully things get more user-friendlier in the future.
I think that the fact that this is not user-friendly is a misconception. The reality is that Swift is designed to integrate with existing languages. This makes the calculus slightly different. It is effectively free to reuse existing libraries without having to create bindings. As a result, we can (and do) directly use the Windows SDK. This gives us the ability to immediately start using new functionality in Windows as Microsoft releases it.
Wine does not immediately get new functionality, and often times does not even get old functionality for a while. A similar thing exists with MinGW. Both of these solutions require re-implementing the features that Microsoft has implemented. Instead, we directly rely on Microsoft to implement features and we simply use them (including any new optimizations that they may release).
This of course means that you need access to Microsoft's SDK, which Microsoft chooses to only release on Windows. This is similar to how Apple chooses to release their SDK only on Apple OSes. This is a vendor choice and not really a limitation of the language nor an attempt to make things less friendly for users.
Considering that the MS Windows C/C++ SDK is available online, would it be possible for us to put together a Swift Windows SDK bundle, which allows cross-compiling Swift packages for Windows from linux/macOS, similar to how I and others have been doing with Android for years? If so, I think that would be worth doing, perhaps with the swift-sdk-generator, for people like @poweroff who want to use that.
I know you told me on github that you had cross-compiled some Swift code from linux to Windows in some capacity years ago, so it was certainly possible in some way then.
It is technically possible. However, it is unclear if this is permissible by the license agreement. IANAL, so you will need to seek your own counsel for that determination. I do not think that we can do this with the swift-sdk-generator unless we are able to get some legal counsel about this.
Would we need to get legal council just to produce a tool that lets people generate their own personal windows sdk not for distribution? I guess that question also needs legal counsel. If we were allowed to it’d basically produce the same result just without distributing Microsoft’s files ourselves