I've been exploring ways to port a macOS CLI, joyfully built with Swift, into Windows. While I've encountered some challenges, I'm excited about the future possibilities and wanted to share my experience, ideas, and take the opportunity to ask about upcoming improvements for cross-platform Swift. I'm sharing this with the hope of sparking constructive conversations around Swift's promising cross-platform future.
Foundation
I was thrilled when I saw the announcement of Foundation becoming open source! While exploring cross-platform development, I noticed opportunities to further enhance some fundamental operations that would benefit CLI tools: consistent file-system operations across platforms, streamlined child process handling, and robust data structures for paths. I've found the AbsolutePath
and RelativePath
utilities from swift-tools-support-core quite valuable, though I had to fork it when it was marked as deprecated. Other languages like Rust, Zig, and Go have similar well-established path utilities. The Subprocess work is fantastic, and Swift NIO offers great utilities too. I'm looking forward to when we can simply import Foundation
with confidence across all platforms.
Compilation
Many of us develop primarily in a macOS
environment and can easily virtualize Linux using Podman or Docker. Windows presents unique opportunities for expanding Swift's reach, though the debugging experience when using GitHub Actions environments can be challenging. This has led to ecosystem components like swift-actions/setup-swift facing difficulties with Windows support.
I appreciate that Windows has its own ecosystem, but I'm inspired by languages like Zig, which elegantly handle cross-compilation by linking against Windows' libc. As Apple's Foundation continues to evolve toward ensuring consistent API behavior across operating systems, developers will gain increasing confidence that their code will work smoothly across platforms.
Node.js faced similar challenges, which led to numerous cross-xxx
packages in the NPM ecosystem. Swift has the potential to offer an even more integrated experience from the start.
Resolving and linking non-Apple static binaries
For Apple platforms, XCFramework bundles provide an excellent solution for consuming pre-compiled binaries through SwiftPM. I'm excited about the potential to extend similar conveniences to Windows and Linux.
For context, I'm currently complementing Foundation with binaries built using Zig, which excels at multi-platform builds. I'd love to distribute these elegantly along with headers and modulemaps, referencing them via URLs or version-based references like SwiftPM does with repository versions. Perhaps .artifactbundle
already supports some of this functionality?
Currently, I include binaries in the repository with relative paths in cSettings
and linkerSettings
, which works well but could be more elegant. A streamlined way to bridge these gaps would be fantastic - something like "we know you love using Swift everywhere, and here's an API to help you integrate with other language ecosystems when needed."
I'm passionate about Swift's potential beyond Apple's ecosystems! While there are currently some hurdles in cross-platform development, I believe the community and Apple can collaborate to address these opportunities: enhancing tools, expanding package support for Windows, refining standard libraries for consistency, and creating tooling that embraces interoperability.
Is cross-platform enhancement on the roadmap? I'd love to contribute to discussions about making Swift shine everywhere!