swift-corelibs-foundation: Cannot find 'URLRequest' in scope when building with the Static Linux SDK

When building a Swift package executable using the Swift 6.0.1 toolchain and matching Static Linux SDK, URLRequest and URLSession cannot be found. import FoundationNetworking prevents those errors, but linking fails with errors such as ld.lld: error: undefined symbol: SSL_get_peer_cert_chain

System info

OS: macOS 14.7 Xcode: 16.0 public release, 15.4 Swift: Apple Swift version 6.0.1 (swift-6.0.1-RELEASE) Target: arm64-apple-macosx14.0 Static Linux SDK: swift-6.0.1-RELEASE_static-linux-0.0.1

Output

Without FoundationNetworking

% xcrun --toolchain swift swift build --swift-sdk x86_64-swift-linux-musl
Building for debugging...
error: cannot find 'URLRequest' in scope
 8 |     static func main() async throws {
 9 |         let swiftDotOrg = URL(string: "https://swift.org")!
10 |         let swift = URLRequest(url: swiftDotOrg)
   |                     `- error: cannot find 'URLRequest' in scope
11 |         let (_, response) = try await URLSession.shared.data(for: swift)
12 |         if let statusCode = (response as? HTTPURLResponse)?.statusCode {

error: type 'URLSession' (aka 'AnyObject') has no member 'shared'
 9 |         let swiftDotOrg = URL(string: "https://swift.org")!
10 |         let swift = URLRequest(url: swiftDotOrg)
11 |         let (_, response) = try await URLSession.shared.data(for: swift)
   |                                                  `- error: type 'URLSession' (aka 'AnyObject') has no member 'shared'
12 |         if let statusCode = (response as? HTTPURLResponse)?.statusCode {
13 |             print("Status: \(statusCode)")


error: value of type 'HTTPURLResponse' (aka 'AnyObject') has no member 'statusCode'
10 |         let swift = URLRequest(url: swiftDotOrg)
11 |         let (_, response) = try await URLSession.shared.data(for: swift)
12 |         if let statusCode = (response as? HTTPURLResponse)?.statusCode {
   |                                                             `- error: value of type 'HTTPURLResponse' (aka 'AnyObject') has no member 'statusCode'
13 |             print("Status: \(statusCode)")
14 |         }

With FoundationNetworking

clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
ld.lld: error: undefined symbol: SSL_get_peer_cert_chain
>>> referenced by openssl.c:427 (/home/build-user/source/curl/lib/vtls/openssl.c:427)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: sk_num
>>> referenced by x509.h:142 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509.h:142)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by x509.h:130 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509.h:130)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by x509.h:130 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509.h:130)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 5 more times

ld.lld: error: undefined symbol: BIO_s_mem
>>> referenced by openssl.c:439 (/home/build-user/source/curl/lib/vtls/openssl.c:439)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:392 (/home/build-user/source/curl/lib/vtls/openssl.c:392)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:4221 (/home/build-user/source/curl/lib/vtls/openssl.c:4221)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 2 more times

ld.lld: error: undefined symbol: BIO_new
>>> referenced by openssl.c:439 (/home/build-user/source/curl/lib/vtls/openssl.c:439)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:392 (/home/build-user/source/curl/lib/vtls/openssl.c:392)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:1421 (/home/build-user/source/curl/lib/vtls/openssl.c:1421)
>>>               openssl.c.o:(cert_stuff) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 5 more times

ld.lld: error: undefined symbol: BIO_get_mem_data
>>> referenced by openssl.c:647 (/home/build-user/source/curl/lib/vtls/openssl.c:647)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:651 (/home/build-user/source/curl/lib/vtls/openssl.c:651)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:453 (/home/build-user/source/curl/lib/vtls/openssl.c:453)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 18 more times

ld.lld: error: undefined symbol: BIO_reset
>>> referenced by openssl.c:647 (/home/build-user/source/curl/lib/vtls/openssl.c:647)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:651 (/home/build-user/source/curl/lib/vtls/openssl.c:651)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:453 (/home/build-user/source/curl/lib/vtls/openssl.c:453)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 18 more times

ld.lld: error: undefined symbol: PEM_write_bio_X509
>>> referenced by openssl.c:650 (/home/build-user/source/curl/lib/vtls/openssl.c:650)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: sk_value
>>> referenced by x509.h:142 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509.h:142)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by x509.h:130 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509.h:130)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by x509v3.h:206 (/home/build-user/build/sdk_root/x86_64/usr/include/openssl/x509v3.h:206)
>>>               openssl.c.o:(Curl_ossl_verifyhost) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 1 more times

ld.lld: error: undefined symbol: X509_get_subject_name
>>> referenced by openssl.c:452 (/home/build-user/source/curl/lib/vtls/openssl.c:452)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:2298 (/home/build-user/source/curl/lib/vtls/openssl.c:2298)
>>>               openssl.c.o:(Curl_ossl_verifyhost) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:4253 (/home/build-user/source/curl/lib/vtls/openssl.c:4253)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_NAME_print_ex
>>> referenced by openssl.c:452 (/home/build-user/source/curl/lib/vtls/openssl.c:452)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:455 (/home/build-user/source/curl/lib/vtls/openssl.c:455)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:1685 (/home/build-user/source/curl/lib/vtls/openssl.c:1685)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 1 more times

ld.lld: error: undefined symbol: X509_get_issuer_name
>>> referenced by openssl.c:455 (/home/build-user/source/curl/lib/vtls/openssl.c:455)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:4284 (/home/build-user/source/curl/lib/vtls/openssl.c:4284)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_get_version
>>> referenced by openssl.c:458 (/home/build-user/source/curl/lib/vtls/openssl.c:458)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: BIO_printf
>>> referenced by openssl.c:458 (/home/build-user/source/curl/lib/vtls/openssl.c:458)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:465 (/home/build-user/source/curl/lib/vtls/openssl.c:465)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:548 (/home/build-user/source/curl/lib/vtls/openssl.c:548)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced 1 more times

ld.lld: error: undefined symbol: X509_get_serialNumber
>>> referenced by openssl.c:461 (/home/build-user/source/curl/lib/vtls/openssl.c:461)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: BIO_puts
>>> referenced by openssl.c:463 (/home/build-user/source/curl/lib/vtls/openssl.c:463)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_get0_signature
>>> referenced by openssl.c:474 (/home/build-user/source/curl/lib/vtls/openssl.c:474)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_ALGOR_get0
>>> referenced by openssl.c:477 (/home/build-user/source/curl/lib/vtls/openssl.c:477)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: i2a_ASN1_OBJECT
>>> referenced by openssl.c:478 (/home/build-user/source/curl/lib/vtls/openssl.c:478)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:486 (/home/build-user/source/curl/lib/vtls/openssl.c:486)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_get_X509_PUBKEY
>>> referenced by openssl.c:482 (/home/build-user/source/curl/lib/vtls/openssl.c:482)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:4097 (/home/build-user/source/curl/lib/vtls/openssl.c:4097)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a
>>> referenced by openssl.c:4106 (/home/build-user/source/curl/lib/vtls/openssl.c:4106)
>>>               openssl.c.o:(ossl_connect_common) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: undefined symbol: X509_PUBKEY_get0_param
>>> referenced by openssl.c:484 (/home/build-user/source/curl/lib/vtls/openssl.c:484)
>>>               openssl.c.o:(Curl_ossl_certchain) in archive /Users/<username>/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libcurl.a

ld.lld: error: too many errors emitted, stopping now (use --error-limit=0 to see all errors)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Package

Package.swift

// swift-tools-version: 6.0

import PackageDescription

let package = Package(
    name: "FoundationTest",
    platforms: [
        .macOS(.v12)
    ],
    targets: [
        .executableTarget(name: "FoundationTest")
    ]
)

Sources/FoundationTest/FoundationTest.swift

import Foundation
#if canImport(Musl)
// Finds `URLSession` and `URLRequest`, linking fails
//import FoundationNetworking
#endif

@main
struct App {
    static func main() async throws {
        let swiftDotOrg = URL(string: "https://swift.org")!
        let swift = URLRequest(url: swiftDotOrg)
        let (_, response) = try await URLSession.shared.data(for: swift)
        if let statusCode = (response as? HTTPURLResponse)?.statusCode {
            print("Status: \(statusCode)")
        }
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (11 by maintainers)

Commits related to this issue

Most upvoted comments

FYI, I managed to compile by adding some linker flags:

xcrun --toolchain swift swift build -c release --swift-sdk aarch64-swift-linux-musl -Xlinker -lz -Xlinker -licuuc -Xlinker -licudata -Xlinker -lssl -Xlinker -lcrypto

Update: we haven’t had a nightly build since the 25th of September. It should be in the next nightly (on main).

If you want to try doing a build of it in the meantime, you can grab the swift-docker repo, then look in swift-docker/swift-ci/sdks/static-linux where you’ll find a build script. You’ll need to update that script slightly, by adding --swift-scheme main to the fetch-source.sh invocation, and in my case I also need to tell my container runtime to give the container more memory so I add -m 10G to the $DOCKER run invocation at the bottom. Running that will build you a new SDK.

Addendum: You also need to add --build-arg SWIFT_WEBROOT=https://download.swift.org/development to the Docker image build, or you’ll build an SDK that won’t work because the compiler won’t match.

(I’m actually doing this myself at the moment so I can look at #5092…)

Passing linker flag provided by @IlyaGulya in the CLI works only if the package does not use build tool plugins. Otherwise building the build tool plugin fails. However, you can also specify those on the targets that use FoundationNetworking:

linkerSettings: [
    .linkedLibrary("crypto"),
    .linkedLibrary("icudata"),
    .linkedLibrary("icuuc"),
    .linkedLibrary("ssl"),
    .linkedLibrary("z"),
]

With that, you can even limit this to Linux:

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])),
]