// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let swiftSettings: Array<SwiftSetting> = [
.swiftLanguageMode(.v6),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
]
let package = Package(
name: "StaticNetworking",
platforms: [.macOS(.v15)],
targets: [
.executableTarget(
name: "StaticNetworking",
swiftSettings: swiftSettings,
// Workaround for https://github.com/swiftlang/swift-corelibs-foundation/issues/5089
linkerSettings: [
.linkedLibrary("crypto", .when(platforms: [.linux])),
.linkedLibrary("icudata", .when(platforms: [.linux])),
.linkedLibrary("icuuc", .when(platforms: [.linux])),
.linkedLibrary("ssl", .when(platforms: [.linux])),
.linkedLibrary("z", .when(platforms: [.linux])),
]),
]
)
With the following Sources/main.swift:
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
struct Post: Sendable, Codable {
let id: Int
let userId: Int
let title: String
let body: String
}
let request = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com/posts")!)
print("Fetching data...")
let (data, response) = try await URLSession.shared.data(for: request)
print("Response: \(response)")
let posts = try JSONDecoder().decode(Array<Post>.self, from: data)
print("Decoded \(posts.count) post(s)...")
Which is then built using the Swift Static Linux SDK (swift build -c release --swift-sdk "x86_64-swift-linux-musl"), leads to the following error when run (on e.g. an Ubuntu 24.04 machine):
Using the following
Package.swift
:With the following
Sources/main.swift
:Which is then built using the Swift Static Linux SDK (
swift build -c release --swift-sdk "x86_64-swift-linux-musl"
), leads to the following error when run (on e.g. an Ubuntu 24.04 machine):Note the
NSURLErrorDomain Code=-1
which isNSURLErrorUnknown
. It doesn't matter which url is used, the result is always the same.Tested using Swift 6.0.1 and Swift Static Linux SDK 0.0.1. It's also irrelevant whether the executable is built on macOS or Linux.