Example of a Cross-Platform macOS/Windows Application Developed Using Swift 6

Hey there,

This is the source code and documentation for a cross-platform macOS/Windows application implemented in Swift 6. It’s an LLM client. I’ve been playing with it for some time in my spare time and I’m happy to share it publicly now!
https://github.com/fbarbat/fellmonger

My main goal was to learn about architectural patterns and developer experience for cross-platform Swift. I found some really cool pointers from The Browser Company and @compnerd about how that was possible and how to get started but I still felt like I needed deeper hands-on experience.

How would “real life” Swift Windows code look like? How would the developer experience be? What would be shareable and what wouldn't? How would be a Swift Windows app be released and packaged? What would be the major trade offs when following this approach? How would Swift 6 fit in all of this?

I tried to condense down everything I learned about cross-platform Swift in this GitHub repo. If you have questions please let me know! Happy to improve it so we can all have more learning resources in the Swift community about how to follow this cool approach. Let me know if you have any thoughts about it!

17 Likes

I would love to give this a try but it's exposing how outdated my Windows skills are :sweat_smile:

I've got a Windows machine with Swift 5.10 (which I believe I installed via winget, if that matters) but I've seen your Package.swift files are tools-version: 6.0.

So I downloaded Swift 6 and ran the installer - but I'm not sure how to actually switch Swift versions on Windows! When I run swift --version in a shell it still reports 5.10.

On macOS I use Xcodes or xcode-select - or even just env DEVELOPER_DIR=... xcrun swift but I don't even know where things get installed on Windows.

What's the recommended way to deal with multiple Swift versions on Windows?

I haven't tried having multiple versions of Swift at the same time in Windows. The easiest thing to do is to make sure you uninstall them all (be it from an uninstaller and/or winget) and only install the most recent one for Swift 6, which is this one as of now. Note I stuck to the Browser Company toolchain of Swift since that’s why they suggested in their examples. It might work with the official one but I haven tried it yet.
If you really need to keep more than one installation, you could write a batch script that changes the path accordingly but probably not worth if you are just testing out this tech.
You should verify the PATH in the environment variables is pointing to the right directory.

I have ventured to experiment with swift 6 on a windows 11 vm that runs in a Mac M1 chip (ARM)
I have followed the simple install instructions using either manual config or widget cli.

And I can't get "swift build" on a simple hello world.

error: 'hello_world': Invalid manifest (compiled with: ["C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.1+Asserts\\usr\\bin\\swiftc.exe", "-vfsoverlay", "C:\\Users\\cdeda\\AppData\\Local\\Temp\\TemporaryDirectory.uNpAeu\\vfs.yaml", "-L", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.1+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-lPackageDescription", "-sdk", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\SDKs\\Windows.sdk\\", "-libc", "MD", "-I", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows", "-I", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\aarch64", "-L", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\Library\\XCTest-development\\usr\\lib\\swift\\windows\\aarch64", "-I", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows", "-L", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Platforms\\6.0.1\\Windows.platform\\Developer\\Library\\Testing-development\\usr\\lib\\swift\\windows\\aarch64", "-use-ld=lld", "-swift-version", "6", "-I", "C:\\Users\\cdeda\\AppData\\Local\\Programs\\Swift\\Toolchains\\6.0.1+Asserts\\usr\\lib\\swift\\pm\\ManifestAPI", "-package-description-version", "6.0.0", "C:\\Users\\cdeda\\Developer\\hello_world\\Package.swift", "-o", "C:\\Users\\cdeda\\AppData\\Local\\Temp\\TemporaryDirectory.0L7Xlo\\hello_world-manifest.exe"])
<module-includes>:1:10: note: in file included from <module-includes>:1:
 1 | #include "AssertionReporting.h"
   |          `- note: in file included from <module-includes>:1:
 2 | #include "CoreFoundationShims.h"
 3 | #include "EmbeddedShims.h"

You need to install Microsoft Visual C++ (MSVC) for Swift on Windows to work properly.

You should download Visual Studio Community and install Desktop Development with C++ to get it. Probably there are lighter ways to do it but this should work for most people.

I could reproduce your same issue by running the below commands but then got it working after installing the above stuff.

mkdir test
cd test
swift package init
swift build

Be aware that Swift on Windows for ARM was not fully supported when I wrote my project. I hit several issues when trying it and fell back to using an X86_64 Windows machine or a VM in Intel MacBook. Check the README of my project for more details.

In that README I also mention more details about setting up the development environment.

Thank you.
I added a more thorough description of the issue: Error using swift 6.0.1 on Windows 11, ARM, running as a VM on a MacBook Pro m1

I can confirm swift runs all right on a windows 11 vm on intel.
The desire to make it work on ARM is obviously related to that really cool Mac silicon.
From what I gather the windows world does not really care much about ARM.