# Swift as a cross-platform language and Windows support

**URL:** <https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547>\
**Category:** Discussion\
**Tags:** windows, swift-evolution\
**Created:** [May 10, 2018, 8:49pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547 "2018-05-10T20:49:33Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Torust](https://avatars.discourse-cdn.com/v4/letter/t/f17d59/32.png) [@Torust](https://forums.swift.org/u/Torust)\
**Post date:** [November 30, 2018, 10:47am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/61 "2018-11-30T10:47:22Z")

</div>

I've uploaded the source to [Swift Tromino Algorithm - Windows Test · GitHub](https://gist.github.com/troughton/9fdecf4dc09b0406c444c28f40f80d43). It works correctly in debug mode but crashes in release mode; it's hitting an `internalInvariant` on line 31 of ArrayBody.swift. (As a side note, this is a Swift 2-era program that's been lightly modified, so the code style is very out of date).

From the looks of things, it does seem like the generic parameter to `Builtin.allocWithTailElems_1 ` is invalid somehow, so that allocation is getting corrupted. I haven't investigated too thoroughly, though.

I'll note that I ran into an issue in the build process - `SwiftPrivatePthreadExtras` can't be built because the definition of `_beginthreadex` isn't found (perhaps because it's only building against the single-threaded CRT?). I disabled that target to get past the error.

---

<div class="post-metadata">

**Author:** ![jackyko1991](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jackyko1991](https://forums.swift.org/u/jackyko1991)\
**Post date:** [December 13, 2018, 5:21am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/62 "2018-12-13T05:21:17Z")

</div>

[official msvc build guide](https://github.com/apple/swift/blob/master/docs/WindowsBuild.md#MSVC)

however i still like to stick with cmake + native msbuild stye. I am start working at compile Swift without clang. Everything should be ok if the dependencies are available in windows

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [December 13, 2018, 6:04am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/63 "2018-12-13T06:04:50Z")

</div>

There are a number of deficiencies with MSVC. At least as of the 14.16.2703 toolset, the compiler has bugs with various template instantiations. It also doesn't support C11 (which we are using in a few places). Finally, MSVC doesn't support the swift calling convention. As I have put in the document, you can get the compiler to build with MSVC (although, that does require a few changes), but you cannot build the standard library without clang.

---

<div class="post-metadata">

**Author:** ![pvieito](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pvieito/32/33613_2.png) [@pvieito](https://forums.swift.org/u/pvieito)\
**Post date:** [December 19, 2018, 9:13pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/64 "2018-12-19T21:13:14Z")

</div>

I have been following the latest developments in the Swift and Swift Foundation repos, and it seems Windows support [is becoming a reality](https://github.com/apple/swift-corelibs-foundation/pull/1812/files) (thanks @compnerd, awesome job!).

Is there any plan at Apple / the Swift for TensorFlow team / other organization to hook up a Windows machine to the Swift CI infrastructure? I would love to be able to try the toolchain and follow its evolution on Windows but I don't have time/resources to build it myself (probably the same applies to many others).

---

<div class="post-metadata">

**Author:** ![pfusik](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pfusik/32/10588_2.png) [@pfusik](https://forums.swift.org/u/pfusik)\
**Post date:** [February 16, 2020, 9:56am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/65 "2020-02-16T09:56:54Z")

</div>

A year has passed. What's the current status of Swift on Windows?

---

<div class="post-metadata">

**Author:** ![Judgeman777](https://avatars.discourse-cdn.com/v4/letter/j/77aa72/32.png) [@Judgeman777](https://forums.swift.org/u/Judgeman777)\
**Post date:** [February 16, 2020, 6:18pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/66 "2020-02-16T18:18:35Z")

</div>

I think it would also be good to know the status of Android and Linux as well. So much work has been done so far, where are we? And what is the next focus? @compnerd @Finagolfin

---

<div class="post-metadata">

**Author:** ![SwiftUI](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/swiftui/32/24361_2.png) [@SwiftUI](https://forums.swift.org/u/SwiftUI)\
**Post date:** [February 16, 2020, 8:44pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/67 "2020-02-16T20:44:59Z")

</div>

Linux distros such as redhat Debian should be first to officially supported along with Ubuntu latest lts release 20.4.  
Windows and Android maybe the second wave to add support.

---

<div class="post-metadata">

**Author:** ![SDGGiesbrecht](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/sdggiesbrecht/32/4768_2.png) [@SDGGiesbrecht](https://forums.swift.org/u/SDGGiesbrecht)\
**Post date:** [February 16, 2020, 9:01pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/68 "2020-02-16T21:01:22Z")

</div>

> [@pfusik](#):
>
> What's the current status of Swift on Windows?

You can compile Swift code on Windows. All the core libraries can be linked against (`Foundation`, `FoundationNetworking`, `FoundationXML`, `Dispatch`, `XCTest`), and also the `WinSDK`. But the result is still fragile at runtime. Of the tests I have started running on Windows, just under half of them crash with segmentation faults. It seems to be mostly centred around the compiler botching complicated protocol hierarchies or something, although I haven’t been able to narrow it down yet. The places I would have expected the most difficultly, because of the greatest platform differences—like `FileManager` and `Process`—are actually working flawlessly. SwiftPM is not yet functional, so you have to use CMake.

> [@Judgeman777](#):
>
> I think it would also be good to know the status of Android and Linux as well.

Linux has been officially supported and on par with macOS for some time now. You will just find fewer third‐party development utilities for Linux. (Not sure about variants besides Ubuntu though, if that is what you were referring to.)

Android works and some companies are using it in production. Of the core libraries, only `FoundationNetworking` has been giving me problems. Both SwiftPM and CMake can cross‐compile from Linux. Apparently SwiftPM can also be used to compile source natively on Android. The compiler occasionally trips for Android where it wouldn’t for macOS or Linux, resulting in the need for either `#if !os(Android)` or code to be refactored. (I think this too is mostly concentrated around complex protocol hierarchies.)

The main hurdles are that:

- These platforms are still experimental and not officially supported.
- The necessary toolchains aren’t available at the official Swift site, so to install you have to do more work collecting the pieces (and figuring out where to find them in the first place). Or else you have to build the whole toolchain from source.
- You will need to supply a lot more build flags manually, because the compiler, CMake and SwiftPM haven’t yet been taught where to find everything either.

You can see an example of a package being tested on all platforms [here](https://github.com/SDGGiesbrecht/SDGCornerstone/runs/447338299). And you can search it’s source for `os(Windows)` or `os(Android)` to get a sense of some of the platform differences and what does and doesn’t work yet. The approximate number of lines in [the various set‐up scripts](https://github.com/SDGGiesbrecht/SDGCornerstone/blob/dd2c15c4cefa2ad9a95d7d84c86d6a3e46a6b893/.github/workflows/Workspace%20Validation.yaml) can serve as a rough comparison of how easy it is to run tests on each platform:

| Platform | Build | Test | Notes |
| --- | --- | --- | --- |
| macOS | 1 | 1 | “swift test” |
| Linux | 3 | 3 | download Swift, unpack, “swift test” |
| Windows | 40 | 40 | configure Visual Studio; install platform module maps, Swift, and ICU; minor repairs; additions to `PATH`; run CMake; test  
(This figure does not include writing the `CMakeLists.txt` files.) |
| Android | 60 | 70 | install official Swift, cross‐compilation toolchain, Android SDK and ICU; minor repairs; write out a destination file, “swift build”; copy libraries; install on emulator/device; execute test executable  
(This figure assumes you already have the Android NDK installed.) |

It won’t help you do a proper install on your own device, but if you just want to experiment, the same GitHub workflow linked above can be set up for any package with [this tool](https://sdggiesbrecht.github.io/Workspace/%F0%9F%87%A8%F0%9F%87%A6EN/Tools/workspace/Subcommands/refresh/Subcommands/continuous%E2%80%90integration.html). It includes the automatic generation of all the CMake pieces. (You can copy and paste instead, but you’ll then have to manually adjust pieces of it according to your particular package manifest.)

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [February 17, 2020, 8:52am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/69 "2020-02-17T08:52:05Z")

</div>

I can't speak much for linux, or even Android cross-compilation, as my work has been to get a Swift toolchain natively running on an Android device. The goal is to get it to the point where you can just type `pkg install swift` and start writing Swift packages on your Android tablet, but for now [you will have to build the Swift toolchain from source, with a few simple steps](https://forums.swift.org/t/swift-for-android-call-for-the-community/32766/11). The advantage of getting everything running natively is that I can run all the tests easily and [I reported last month that I was down to only 16 test failures across all the tests from the Swift compiler validation suite up through the SwiftPM and sourcekit-lsp tests](https://forums.swift.org/t/swift-for-android-call-for-the-community/32766/5).

Since then, the last test fix for Foundation has been merged, so the only failures are 11 in Swift validation, 1 in XCTest, and 3 in SwiftPM, largely inconsequential issues like some validation tests not having [RUNPATH set like Android requires](https://forums.swift.org/t/ci-for-packages-on-windows-android/32295/69) or some LLVM sanitizers not working on Android. Of course, I'm guessing the tests don't cover everything and there is some functionality that hasn't been implemented for Android, [such as Bundle support](https://github.com/apple/swift-corelibs-foundation/blob/fcda3c794db3b0b5d66f81aa9d40342d59a8b249/CoreFoundation/PlugIn.subproj/CFBundle.c#L167) (ironically, @pvieito, who started this thread a couple years ago, [tried to fix it and then abandoned it](https://github.com/apple/swift-corelibs-foundation/pull/2093)), but I haven't looked into how much of that there is.

I tried building and testing some Swift packages on an Android device, such as [SwiftyJSON, the most-starred Swift package on github that advertises linux support](https://github.com/SwiftyJSON/SwiftyJSON). While other packages worked great, with `swift build; swift test` just working and passing all their tests, [SwiftyJSON has been broken on linux itself with Swift 5.1](https://github.com/SwiftyJSON/SwiftyJSON/issues/1038). It's a simple fix though, and with a couple other tweaks for the lack of Bundle support, I was able to get the same test results on both linux x86\_64 and Android aarch64, around 5 test failures, will probably submit a pull with those tweaks. Another package that had problems was swift-nio, which supposedly worked at some point for cross-compiling to Android, but will require some patching to build natively.

I have not tried building an Android app like the flowkey guys or writing much of anything myself with this new Swift toolchain on Android, so I can only report test results. Jeremy has another perspective just above.

I think it might be possible to set up a native Android CI now using the new Anbox Cloud service I mentioned in my post last month. I'll reach out to them and see how it works.

---

<div class="post-metadata">

**Author:** ![Gabor\_Sebestyen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gabor_sebestyen/32/326_2.png) [@Gabor\_Sebestyen](https://forums.swift.org/u/Gabor_Sebestyen)\
**Post date:** [February 17, 2020, 10:30am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/70 "2020-02-17T10:30:25Z")

</div>

Arch Linux is a popular choice in Linux world, however getting Swift built and run is somewhat painful. I also want to use Swift on FreeBSD (or even on NetBSD) but \*BSDs are quite unsupported platforms.

---

<div class="post-metadata">

**Author:** ![Finagolfin](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finagolfin/32/34388_2.png) [@Finagolfin](https://forums.swift.org/u/Finagolfin)\
**Post date:** [February 18, 2020, 2:37am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/71 "2020-02-18T02:37:21Z")

</div>

> Arch Linux is a popular choice in Linux world, however getting Swift built and run is somewhat painful.

Have you built it lately? I've been building Swift master on Arch Linux x86\_64 occasionally since last year, and while there used to be some tweaks needed back then, I haven't had to patch it at all lately. If you try master or the 5.2 branch, it should just work.

> I also want to use Swift on FreeBSD (or even on NetBSD) but \*BSDs are quite unsupported platforms.

[There is some support](https://github.com/apple/swift/blob/67297904acf5f2a2b525611f4f6017e3c1a3e017/stdlib/public/Platform/glibc.modulemap.gyb#L22) and since Darwin/macOS and Android's Bionic libc use a lot of BSD code, I doubt it would take much to get the BSDs working.

---

<div class="post-metadata">

**Author:** ![Gabor\_Sebestyen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gabor_sebestyen/32/326_2.png) [@Gabor\_Sebestyen](https://forums.swift.org/u/Gabor_Sebestyen)\
**Post date:** [February 18, 2020, 11:59am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/72 "2020-02-18T11:59:40Z")

</div>

I wanted to confirm it but ran into a weird issue compiling compiler-rt with the latest 5.2 DEVELOPMENT branch (sanitizer\_platform\_limits\_posix.cc:1131:1: error: 'assertion\_failed\_\_1131' declared as an array with a negative size). I will file a bug.  
According to this post [Swift on FreeBSD](https://forums.swift.org/t/swift-on-freebsd/20298) FreeBSD needs a helping hand, specifically porting Foundation stuff.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [February 18, 2020, 4:06pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/73 "2020-02-18T16:06:24Z")

</div>

The "array declared with a negative size" is an assertion failure. Something is incorrect about the configuration.

---

<div class="post-metadata">

**Author:** ![Gabor\_Sebestyen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/gabor_sebestyen/32/326_2.png) [@Gabor\_Sebestyen](https://forums.swift.org/u/Gabor_Sebestyen)\
**Post date:** [February 19, 2020, 10:54am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/74 "2020-02-19T10:54:35Z")

</div>

Can't tell you what went wrong. I've been using the same build enviroment for building Swift snapshots. Ticket for this issue is opened [[SR-12224] Assertion error in sanitizer: declared as an array with a negative size · Issue #54650 · apple/swift · GitHub](https://bugs.swift.org/browse/SR-12224)

---

<div class="post-metadata">

**Author:** ![Genaro-Chris](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/genaro-chris/32/24997_2.png) [@Genaro-Chris](https://forums.swift.org/u/Genaro-Chris)\
**Post date:** [August 4, 2022, 1:56am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/75 "2022-08-04T01:56:33Z")

</div>

I think Swift should really achieve its full capabilities if & only if it start cross-platform compilation just like Go and others, in Swift 6.  
Any ideas on cross-platform compilation options 🤔🤔🤔

---

<div class="post-metadata">

**Author:** ![sspringer](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sspringer](https://forums.swift.org/u/sspringer)\
**Post date:** [August 4, 2022, 2:04am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/76 "2022-08-04T02:04:07Z")

</div>

> [@Genaro-Chris](#):
>
> I think Swift should really achieve its full capabilities if & only if it start cross-platform compilation just like Go and others, in Swift 6.  
> Any ideas on cross-platform compilation options

As I understand it, it is common in this forum not to give new answers to "old" topics as everyone involved in the old topic then gets a notification, but might not be interested any more. I would recommend to then create a new topic 😉

---

<div class="post-metadata">

**Author:** ![Haddock](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Haddock](https://forums.swift.org/u/Haddock)\
**Post date:** [August 4, 2022, 8:29am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/77 "2022-08-04T08:29:53Z")

</div>

Good support for Windows would be great of course. Not wanting to appear negative, but there is an issue that with C# you can develop applications for MS AppStore and \>also\< Apple AppStore. That is unhappily not true for Swift, because MS is more restrictive here than Apple and does not allow Swift applications to be uploaded to MS AppStore.

Besides that Ximian paved the way for C# on Linux and Apple. Some company would be needed that does for Swift what Ximian did for C#.

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [August 4, 2022, 8:46am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/78 "2022-08-04T08:46:39Z")

</div>

> [@Haddock](#):
>
> MS is more restrictive here than Apple and does not allow Swift applications to be uploaded to MS AppStore

Can you provide a link that supports this please? I haven't seen this mentioned anywhere before. What exactly is the nature of the restriction?

---

<div class="post-metadata">

**Author:** ![Haddock](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Haddock](https://forums.swift.org/u/Haddock)\
**Post date:** [August 4, 2022, 8:54am UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/79 "2022-08-04T08:54:59Z")

</div>

> Can you provide a link that supports this please? I haven't seen this mentioned anywhere before. What exactly is the nature of the restriction?

Here is some [link](https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/september/modern-apps-understanding-your-language-choices-for-developing-modern-apps) I found on the MS homepage. So some app for MS AppStore must be written in C or C++ or some .NET language. That's how I understand it and various places on the Internet I found other people saying the same. Wished I could provide better news ...

---

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [August 4, 2022, 1:57pm UTC](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547/80 "2022-08-04T13:57:44Z")

</div>

I don't think that the link you've provided is a "policy" requirement for apps published on Windows Store. It looks more like a guidance, as in "these are the languages that we recommend to use". There are [apps written in Rust](https://github.com/bdbai/firstuwp-rs) already published and available on the store. What would make Rust different from Swift in this perspective?

[Previous page](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547.md?page=3)

[Next page](https://forums.swift.org/t/swift-as-a-cross-platform-language-and-windows-support/12547.md?page=5)
