Skip to content

Swift SDKs missing curl dependency for statically linking FoundationNetworking #197

Open
@xtremekforever

Description

@xtremekforever

Consider the following example:

import Foundation
import FoundationNetworking

struct TestError: Error {
    let reason: String
}

extension URLSession {
    func data(for request: URLRequest) async throws -> (Data, URLResponse) {
        try await withCheckedThrowingContinuation { continuation in
            let task = self.dataTask(with: request) { data, response, error in
                if let error = error {
                    continuation.resume(throwing: error)
                } else {
                    continuation.resume(returning: (data ?? .init(), response!))
                }
            }
            task.resume()
        }
    }
}

let url = URL(string: "https://httpbin.org/anything")!
let body = Data("test-\(UUID())".utf8)
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.httpBody = body
let (data, urlResponse) = try await URLSession.shared.data(for: request)
guard let httpResponse = urlResponse as? HTTPURLResponse, httpResponse.statusCode == 200 else {
    throw TestError(reason: "Invalid response")
}
guard let json = String(data: data, encoding: .utf8) else {
    throw TestError(reason: "Invalid response")
}
print(json)
print("URLSession test passed")

When I compile the project with a Swift SDK generated (not from a Docker container) and use --static-swift-stdlib, it cannot find -lcurl:

$ swift build --swift-sdk 6.0.3-RELEASE_ubuntu_jammy_aarch64 --static-swift
-stdlib
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
ld.lld: error: unable to find library -lcurl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[5/6] Linking foundation-networking-example

It would be good to add the libcurl4-openssl-dev dependency into the sysroot that is generated for the Swift SDK to be able to compile projects that use FoundationNetworking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions