Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find 'URLRequest' in scope when building with the Static Linux SDK #5089

Closed
barnard-b opened this issue Sep 26, 2024 · 15 comments · Fixed by #5097
Closed

Cannot find 'URLRequest' in scope when building with the Static Linux SDK #5089

barnard-b opened this issue Sep 26, 2024 · 15 comments · Fixed by #5097
Labels

Comments

@barnard-b
Copy link

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)")
        }
    }
}
@jmschonfeld
Copy link
Contributor

You'll need an import FoundationNetworking since that's the module that contains URLSession/URLRequest, but the linking failure sounds like a bug to me. I'm going to transfer this over to the swift-corelibs-foundation repo where FoundationNetworking lives

@jmschonfeld jmschonfeld transferred this issue from swiftlang/swift-foundation Sep 26, 2024
@jmschonfeld
Copy link
Contributor

@jrflat do you know if the curl lib that we build on Linux is supposed to reference these seemingly OpenSSL symbols? I see in the normal build we have self.cmake_options.define('CMAKE_USE_OPENSSL', 'NO') set, so I'm wondering if maybe the Static SDK build (which I believe uses an entirely separate build script) is missing some options to exclude the use of these symbols? If it is expected that we'd have them, then we're likely missing an auto link flag in the FoundationNetworking build to indicate the library that needs to be linked that contains the symbols.

@jmschonfeld
Copy link
Contributor

@barnard-b
Copy link
Author

You'll need an import FoundationNetworking since that's the module that contains URLSession/URLRequest...

Oh ok, I thought that had changed with the new Foundation.

@jrflat
Copy link
Contributor

jrflat commented Sep 27, 2024

@jrflat do you know if the curl lib that we build on Linux is supposed to reference these seemingly OpenSSL symbols? I see in the normal build we have self.cmake_options.define('CMAKE_USE_OPENSSL', 'NO') set, so I'm wondering if maybe the Static SDK build (which I believe uses an entirely separate build script) is missing some options to exclude the use of these symbols?

I think the curl lib we build doesn't reference those OpenSSL symbols. But this also requires both CMAKE_USE_OPENSSL=NO and CMAKE_USE_LIBSSH2=NO since otherwise libcurl depends on libssh2 which references OpenSSL.

@etcwilde
Copy link
Contributor

SSL should be available in the musl SDK since it includes BoringSSL, which that copy of curl should be getting compiled against.

https://github.com/swiftlang/swift-docker/blob/38e4244ebab3d6a4e702fb30449827d6c28ee1fd/swift-ci/sdks/static-linux/scripts/build.sh#L595-L611

I don't believe SSL or SSH support are enabled for the copy of curl in the Windows Swift SDKs though either, so we may be able to disable that functionality.

@al45tair, ideas on this?

@IlyaGulya
Copy link

IlyaGulya commented Sep 28, 2024

Having same issue while trying to compile application which uses FoundationNetworking
Swift SDK: swift-6.0.1-RELEASE_static-linux-0.0.1
Building on Macbook M3 Pro, macOS 15

command I'm using to build:

xcrun --toolchain swift swift build -c release --swift-sdk aarch64-swift-linux-musl

Here's logs:
https://gist.github.com/IlyaGulya/37369cc4299008fd8b548f43d3efcb1a

Repo where you can reproduce the issue: https://github.com/IlyaGulya/figma-export

@IlyaGulya
Copy link

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

@ffried
Copy link
Contributor

ffried commented Oct 1, 2024

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

@al45tair
Copy link
Contributor

al45tair commented Oct 2, 2024

I would have expected these to be pulled in via autolinking, but maybe they aren't being. I note that the static-executable-args.lnk file for Linux does include references to icudata and icuuc (unlike the one for the Static SDK), but it doesn't include crypto, ssl or z — though maybe that's because FoundationNetworking wouldn't be statically linked there.

@al45tair
Copy link
Contributor

al45tair commented Oct 2, 2024

Looks like some autolink arguments went missing in the Foundation re-core. (I'm just testing a fix and then I'll raise a PR.)

@al45tair
Copy link
Contributor

al45tair commented Oct 4, 2024

Still working on this; found another problem while building Foundation. Should have a PR to fix it all fairly soon.

al45tair added a commit to al45tair/swift-docker that referenced this issue Oct 4, 2024
We don't need ICU for Foundation any more, so remove it and don't
link it into the other libraries either.

(See swiftlang/swift-corelibs-foundation#5089.)
@IlyaGulya
Copy link

@al45tair Hi!
When this will be available for end users of SDK?
How can I test it?

@al45tair
Copy link
Contributor

al45tair commented Oct 7, 2024

I haven't checked, but it's likely in the nightly builds already, assuming things built successfully. There's another issue (#5092) that I need to look at also, which I plan on looking at later today if I get the time.

@al45tair
Copy link
Contributor

al45tair commented Oct 9, 2024

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…)

al45tair added a commit to al45tair/swift-corelibs-foundation that referenced this issue Oct 16, 2024
…nsChdir.

We need a handful more autolink arguments; these were in a previous PR,
but seem to have gone missing at some point during the re-core.

Additionally, Musl has the `posix_spawn_file_actions_addchdir_np()`
function rather than the non-`_np()` version.

Fixes swiftlang#5089.
al45tair added a commit to al45tair/swift-corelibs-foundation that referenced this issue Dec 5, 2024
…nsChdir.

We need a handful more autolink arguments; these were in a previous PR,
but seem to have gone missing at some point during the re-core.

Additionally, Musl has the `posix_spawn_file_actions_addchdir_np()`
function rather than the non-`_np()` version.

Fixes swiftlang#5089.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants