Late last year, The Browser Company posted about them bringing Arc Browser to Windows, but with a twist... The Windows version of Arc is built with Swift- it's one of the biggest if not the biggest pieces of software built on Windows using Swift, and also happens to be the browser I'm using to type out this post. The Browser Company was also generous enough to publish Swift WinRT as an open source project for other folks to use in their own projects to bring apps over to Windows in a familiar language.
Ever since March, I've been trying to get Swift WinRT to work with their sample project, but I've had no success. In fact, I even purchased a whole new Windows Laptop just to try Swift on Windows and see if I could start building for Windows devices. But I kept running into errors and bugs when trying to compile, and eventually had to give up on trying to get this to work. The lack of documentation on how to use this framework is a little unfortunate, and it's rather niche so there aren't nearly as many resources online either, and while I have tried to reach out to some folks on the team working on the project from The Browser Company, I've had no luck in getting a reply.
But that was until this week. A few days ago, I saw a tweet from Fernando Barbat, a fellow software engineer on Twitter, about him building a Swift project on Windows using the framework from the Browser Company, so I instantly shot a reply and got in touch with him to hear from him about how he got it working, because it's certainly not often you get to see someone building apps with this. After a couple of days of back and forth, I finally got it to work thanks to his guidance!
I wanted to make this process a little easier for new folks who want to try tinkering with this, so I decided I'll make a step by step tutorial on how to get the sample project running.
I will not be guiding you on how to write code using Swift WinRT. This blog post will instead focus on how you can set things up in your environment so that you can get building with Swift on Windows. I may post blog posts in the future about the coding parts if I'm able to make anything cool, because I too am just getting started.
Enough chit chat, let's get to work now!
Note: For this to work, at this current point in time, you will need an x86 machine with an Intel or AMD processor. ARM64 is currently not supported, however it should be in the future.
Our code editor of choice for this is going to be Visual Studio Code, however you will need to install Visual Studio Community edition to install the required C++ components. So let's start with that.
Download the Visual Studio Community installer.
Open the VisualStudioSetup Installer
Go through the steps as shown on screen.
When prompted to components you'd like to install, choose the following:
5. On the pane on the right side, make sure you have ticked the following things, in addition to what came pre-selected:
C++ Universal Platform Tools
Windows 11 SDK
Windows 10 SDK (10.0.17763)
6. Click Install
You'll also need to install the Swift toolchain. Now this is the important part, and also where I messed up. You need a version of the toolchain from the Browser Company, with Swift 6, not Swift 5.10.0.
If you have a version of the toolchain from Apple, delete it, and install the one from here.
As of July 19th 2024, This is the version that worked for me, and I would suggest you download the same too: https://github.com/thebrowsercompany/swift-build/releases/tag/20240716.0
Now, download the files for the sample project from GitHub.
Unzip this and keep it ready for use later.
To get the project up and running, we need to move onto VSCode and set things up there.
Install VSCode.
Once you open VSCode, go to extensions
Install the Swift extension and CodeLLDB
4. Go to file -> Open Folder... -> and choose the folder we unzipped earlier.
5. Click Ctrl + Shift + B
7. Select swift: Build Debug
8. All the Swift components will finish downloading and compiling, this may take some time, so grab a cup of coffee and get some other work done until this finishes.
9. Once that is done, go to Run and Debug on the menu on the left.
10. Select Debug once again
11. Click the Green Run Button and watch the app launch in moments.
That's all there is to it! You now have Swift running on a Windows App for the first time.
Special thanks once again to Fernando for helping me set this up!
From here on, you should be able to mess around with the code and see what works for you best. I'm also going to be spending some time with this and trying to build some cool stuff here and there. I'm excited for what the future of SwiftWinRT is, I hope it stabilizes soon and we get to see some more amazing apps like Arc on Windows. Until then, keep tinkering.
(P.S. Gotta love the fact this article comes on the day when Windows machines worldwide are undergoing BSODs)
Kommentare