Setting up CI for testing library support for Windows

I just read the Swift Blog article about the release of the downloadable Swift toolchain images on Windows and felt addressed by the section about making libraries compatible with Windows:

One of the things that makes Swift easy to use is libraries: publishing new libraries and packages for Swift on Windows or porting existing ones is another way to get involved and help make working with Swift an ever greater delight.

I'd love to make my own libraries compatible with Windows and maybe help with some popular ones. To do this, I'd like to start simple with a pure Swift library without any dependencies (HandySwift), but since the blog post also states that Swift Package Manager isn't there yet on Windows, I wonder how I can set up a CI (e.g. on GitHub Actions or CircleCI) to continuously test that my library is building fine and the tests are passing on Windows.

I assume I have to first download and install the newly released command line tools, but what else to do? Can I just run swift test -v like I can on Linux after installing Swift? Or do I need to do some magic with Cmake? And what about libraries with subdependencies?

Having some guidance on that topic might help getting the library support for Windows.

You can try trunk toolchains instead of the 5.3 release version, SwiftPM already works quite well in those toolchains. I'm not sure if the installers published on swift.org include SwiftPM though, installers by @compnerd certainly do have SwiftPM included.
https://compnerd.visualstudio.com/swift-build/_build?definitionId=7

Yeap, that should work on Windows as well.

1 Like

This sounds great! I think that your experience would be very useful to hear about.

This is true, swift-package-manager is not as thoroughly vetted as the rest of the ecosystem on Windows. This remains the case even on trunk, but it requires usage to actually find the issues and get them fixed.

You would need a build system, so I've tended to use CMake in the past to actually build the libraries.

swift test is part of swift package manager. There is on going work to make swift-package-manager work on trunk. CMake would be required to work with the 5.3 releases. That should be largely straightforward as newer CMake (3.16+) should support building Swift projects with Ninja. It is possible to have CMake use external builds or build it as part of a project if you like.

Edit: For GitHub Actions, @Max_Desiatov filed https://github.com/actions/virtual-environments/issues/1652

2 Likes

This other thread contains some more information for anyone wanting to stick to the stable 5.3 release:

@SDGGiesbrecht I have now started to move my first project over to use your tool Workspace, the goal is to get a streamlined project structure and make use of some of Workspace's features, including adding tests for Windows (and maybe even Android?). I'm struggling with the documentation as reported in multiple issues on GitHub, but I think I'm making progress step by step. You can follow my progress on the first project here.

I'll give another update as soon as I can give some insights into if my libraries are working on Windows as expected. I might also write a blog post about how to ensure a Swift library works on Windows.

Thanks @Jeehut. I tried to answer the questions in the issues you mentioned. I will come back to deal with the bugs and improve the documentation as soon as I have the time. An emergency just made my home uninhabitable, so my search for a place to live is taking priority over everything else at the moment.

Sure, thank you and take your time, there's no reason to hurry. Your emergency is much more important of course, I hope everything will turn out fine!

Terms of Service

Privacy Policy

Cookie Policy