What you're referring to is called "cross-compiling". Like clang, swift does support cross-compiling, but you'll need a bunch of additional materials to make it work: most importantly, the SDK of the target platform.
Xcode supports cross-compiling to iOS/tvOS/watchOS devices, because the SDKs for those targets are bundled together with Xcode. It does not have any particular support to help you cross-compile to other targets (linux, windows, etc).
Generally speaking, obtaining the target SDK is the most challenging part of cross-compiling. For open-source platforms such as linux, it's relatively straightforward, but for proprietary platforms such as Windows or macOS, the terms and conditions generally prohibit you from redistributing the SDK. There may be other restrictions, too - like they may say that you can only use the SDK on Windows, or on an Apple computer, or whatever. In any case, the main difficulty is legal, not technical.
For Windows, Microsoft actually provides virtual machine images, which you (or your users) can download for free. You can install Swift in that VM and use it to build your projects on Windows. Overall, it's probably even easier than cross-compiling, and it can offer a better debugging experience.
EDIT: The terms and conditions for those VMs say:
- INSTALLATION AND USE RIGHTS.
...
c. You may use the software in the virtual hard disk image only to demonstrate and internally evaluate it. You may not use the software for commercial purposes. You may not use the software in a live operating environment.
What exactly does "demonstrate and internally evaluate" mean? What is a "live operating environment"? My guess is that you can use it to check that your project works, but if you actually want to distribute a built product, you might need to buy a Windows license
. Itβs hard to say, and I'm not a lawyer. Again, the main challenges here are all legal, not technical. There are plenty of technical solutions.