A Swift Takes Flight

Hello fellow developers,

After the Swift/Win32 post, I figure that some people may be curious as to the actual state of Swift for Windows. Well, I would like to share a small status update to that end.

This has been a rather interesting and fun journey. I feel that up until this point, we have been making progress, but the surface area is pretty high, particularly for a single person to take on. I have been chipping away at this for a while now. However, as of today, I think that the situation is about to change. I have finally managed to get the compiler, the support libraries, the runtime, standard library, libdispatch, and now, Foundation to build and run on Windows! This is still dependent on a couple of patches that will no doubt need to be cleaned up before they are ready to be merged. But, with Foundation at least running on Windows, Swift on Windows becomes viable for a large number of developers and enables others to start contributing to the effort as well.

I would really like to thank a number of people for their invaluable help through this, including in no particular order, @Michael_Gottesman, @millenomi, @John_McCall, @Joe_Groff, @Slava_Pestov, @jrose, @graskind for their suggestions, conversations, discussions (and sometimes serving as someone that I would need to vent to!). I'm sure that I am missing a many good others who have helped along the way. The task would have been a great deal more challenging (nearly impossible!) without their assistance.

There are still a number of patches in flight across the board - the compiler, Foundation, tests, build system, etc, but should be mostly a matter of polishing off the patches and getting them merged. Additionally, I am still slowly chipping away at the remaining test failures in the Swift test suite. With the outstanding patch, we are now under 100 test failures (that is in a test suite of ~5100 tests!). As to the test failures, the bulk of them are in the driver tests, the reflection tests (due to the reflection support not being able to read the PE/COFF image), and the remainder are smatterings all over the place. Additionally, I have been going through the test suite and enabling them where ever possible even across Linux, which should give us a fairly good coverage to ensure that things on Windows are stable.

Finally, a small parting screenshot of plutil running on Windows :slight_smile:

CC: @tkremenek @Chris_Lattner3

69 Likes

CC: @spevans, @jakepetroules, @pvieito, @Torust

Again, this is very exciting and thank you for the great work.

I’ll apologise for my lack of help with this in the past few months as I’m coming to the end of a Masters thesis. Once that’s done, however, I have a personal project that will use Swift on Windows, and as part of that I hope I’ll have some time to help with getting the package manager/llbuild running. It seems like you have most of the rest already done (although of course I’ll help with any bugs I find along the way)!

4 Likes

This is astounding work. :clap: Does SwiftPM work? Do you need any help with that?

3 Likes

Hi @compnerd,

thanks for all your long-standing efforts to port Swift to Windows!

I think the ball is now in Apple's court. Given the claimed goal of cross platform availability of Swift I think it would be a great move of Apple to make the Windows support "official" by — for instance — sponsoring an official Windows-CI (and one for FreeBSD while we are on it ;)). What do you think, @Chris_Lattner3 @tkremenek?

Kind regards,

Lars

5 Likes

No, s-p-m is not yet ported. However, most of the projects have been CMake based so far (or were converted to CMake). That really would make things easier IMO. Either way, help is absolutely welcome!

Awesome! Hope to see a nightly toolchain with Foundation coming soon :slight_smile:

I would love to help getting Swift PM working.

2 Likes

Fantastic work, thank you @compnerd!

Having no experience with native development in Windows and no knowledge of the inner workings of WinSDK, I'm wondering if it would be a hard undertaking to create higher level automated scripts to aid building on Windows would be? I've tried following the instructions on the Windows build guide in the repo but got stumped by a few configurations I might have done wrong, I feel like having any sort of scripting would allow more people to approach contributing to the Windows port. Do you think making something akin to utils/build-script feasible?

Again, fantastic work and thanks for the contributions, I can't wait to code Swift on Windows first class!

No, building automation would not really be a hard undertaking, just a broad one. It would effectively need to replace build-script, for which there is already a SR open! I think that porting that to something else like python might make it more amenable to working on multiple platforms (and should be something other than swift to ease the pain of bootstrapping on different targets).

In the mean time, you can use the nightlies that I have set up at https://dev.azure.com/compnerd/windows-swift

I'm sure that others would be excited to have help cleaning up build-script and making it more portable if you're interested in that.

3 Likes

I’m confused… AFAIK build-script is python…

Sorry, I meant build-script-impl.

So excited to know that Foundation at last here! A huge bow to those who helped with that! Guys, you are my heroes :smiley:

Can we expect nightlies with Foundation soon?

There are a couple of patches that I'm trying to get in to the tree that enable this. Once those are in, I will add the Foundation build to the nightlies.

5 Likes

What an amazing feat. Thanks so much for working on this contribution :slight_smile:

Wow Saleem, this is truly phenomenal, congratulations!!

8 Likes

Following your progress is very exciting. Well done!

I do not know if there is a need to create a new thread for this, so I will leave it here.

I have combined the info, that I find useful if you want try swift on windows, but you don't know where to begin, and you are not very good at windows (just like me).

Main info in Readme was taken from compnerd's azure readme, and slightly modified

@abesmon: I think the information is still a bit uncomplete, and I am still not able to get the Swift compiler running:

  • It should be noted that the commands (including "curl") should be run from the Developer Command Prompt of Visual Studio, so the environment variables are known etc.
  • ...but the environment variable VCToolsInstallDir is still not known in my Developer Command Prompt, do I have to additionally install the VC Tools, and if yes, where do I get them?
  • curl cannot be used with a proxy, in that case one has to open the Developer Command Prompt and execute "echo %UniversalCRTSdkDir%" etc. to get the paths and put those files there manually.
  • There also exist the installers (msi files), it is not clear what they do i.e. what additional actions should be executed.

This should not sound negative, everyone is doing a great job, but I think it should be trivial to set up Swift on Windows and it still is not. There should be an installer that guides through the whole process (and it should consider a proxy). It should also be easy to set up a distribution of your program with all needed files included.

Thank you for all the feedback! I agree, it's supposed to be trivial to setup Swift, and it's still not, and thats why I made this repo, and thats why such feedback matters :slight_smile: I'l try to extend readme to cover the topics you mentioned above in a day or two, so stay in tune.

Fast reply about your points:

  • curl need not to be executed via VS Prompt, unless you need env. variables. Thats true. And i covered it in my readme, but seems need to pay more attention to explain that.
  • Some variables appear only when specific VS Components installed during VS installation, and i'l try to figure out what which ones, and i'l add it to readme.
  • Didn't know that. I'l be grateful if you could cover that point
  • Yup, i also noticed msi files, but i can't cover question about them. I hope, maybe @compnerd can explain what are those and how to work with them. Also, if you have any info about them, you are welcome to explain everything :smiley:

@abesmon: Installing the *.modulemap and *.apinotes files when curl cannot be used because of a proxy:
1)You can easily get those files by using a web browser with those URLs.
2) To know where to put those files, open the Visual Studio Developer Command Prompt and execute e.g.:
echo %UniversalCRTSdkDir%
The destination paths (including the file names!) are then clear from the curl commands.