Build on Linux too: SOCK_STREAM is a different type under Glibc
`hints.ai_socktype = SOCK_STREAM` compiles on macOS and fails on Linux.
Glibc declares `SOCK_STREAM` as `__socket_type`; Darwin declares it as
`Int32`. The relay is built in a Linux container, so the only machine
that could have caught this locally is the one that cannot.
Verified against real Linux rather than by reasoning about it: the file
imports nothing but Foundation, Dispatch and Glibc, so it typechecks
standalone in a `swift:6.1-noble` container. The pre-fix version
reproduces CI's exact error there and the fixed one is clean — which is
also what makes the check worth keeping rather than a step that would
have passed either way.
docker run --rm -v "$PWD/Sources/FlamenetRelay/OutboundAddressGuard.swift:/tmp/g.swift:ro" \
swift:6.1-noble swiftc -typecheck -swift-version 6 /tmp/g.swift
Also imports Dispatch explicitly. Foundation re-exports it on Darwin and
does not reliably do so on Linux, and `DispatchQueue` is what keeps the
resolver off the cooperative thread pool.
664 tests, 0 failures.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
4bd1b13726
commit
a5e30ed18a
@@ -1,3 +1,4 @@
|
||||
import Dispatch
|
||||
import Foundation
|
||||
|
||||
#if canImport(Glibc)
|
||||
@@ -218,7 +219,16 @@ struct OutboundAddressGuard: Sendable {
|
||||
private static func blockingResolve(_ host: String) -> [IPAddress] {
|
||||
var hints = addrinfo()
|
||||
hints.ai_family = AF_UNSPEC
|
||||
// ⚠️ **`SOCK_STREAM` is not the same TYPE on both platforms.** Glibc
|
||||
// declares it as `__socket_type`; Darwin as `Int32`. Assigning it
|
||||
// directly compiles on macOS and fails on Linux, which is where this
|
||||
// actually runs — the relay is built in a Linux container and the only
|
||||
// machine that would have caught it locally is the one that cannot.
|
||||
#if canImport(Glibc)
|
||||
hints.ai_socktype = Int32(SOCK_STREAM.rawValue)
|
||||
#else
|
||||
hints.ai_socktype = SOCK_STREAM
|
||||
#endif
|
||||
var result: UnsafeMutablePointer<addrinfo>?
|
||||
guard host.withCString({ getaddrinfo($0, nil, &hints, &result) }) == 0,
|
||||
let head = result
|
||||
|
||||
Reference in New Issue
Block a user