Skip to content

Commit 1b33db2

Browse files
authored
Work around a type checking error when using the Static Linux SDK (#2898)
# Motivation Building `swift-nio` with the Static Linux SDK (https://www.swift.org/documentation/articles/static-linux-getting-started.html), fails in `PosixSingletons+ConcurrencyTakeOver.swift`: ``` Building for debugging... error: emit-module command failed with exit code 1 (use -v to see invocation) /private/tmp/vaportest/.build/checkouts/swift-nio/Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift:76:12: error: conflicting arguments to generic parameter 'T' ('Optional<UnsafeRawPointer>.AtomicRepresentation' vs. 'Optional<UnsafeRawPointer>.AtomicRepresentation') 74 | dlopen(nil, RTLD_NOW), 75 | "swift_task_enqueueGlobal_hook" 76 | )?.assumingMemoryBound(to: UnsafeRawPointer?.AtomicRepresentation.self) | `- error: conflicting arguments to generic parameter 'T' ('Optional<UnsafeRawPointer>.AtomicRepresentation' vs. 'Optional<UnsafeRawPointer>.AtomicRepresentation') 77 | guard let concurrencyEnqueueGlobalHookPtr = concurrencyEnqueueGlobalHookPtr else { 78 | return false ``` This happens because `Foundation` and `swift-atomics` both define `AtomicRepresentation`. A compiler problem (rdar://132885963) makes these extensions globally visible, causing the two `AtomicRepresentation` types to collide. This only affects non-Darwin platforms. # Modification This PR works around the problem by using a local type alias which does not collide with the other `AtomicRepresentation` types. # Result It is now possible to build `swift-nio` with the Static Linux SDK. Fixes: #2893 Suggested-by: Alastair Houghton <[email protected]>
1 parent aa25fda commit 1b33db2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/NIOPosix/PosixSingletons+ConcurrencyTakeOver.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension NIOSingletons {
7373
let concurrencyEnqueueGlobalHookPtr = dlsym(
7474
dlopen(nil, RTLD_NOW),
7575
"swift_task_enqueueGlobal_hook"
76-
)?.assumingMemoryBound(to: UnsafeRawPointer?.AtomicRepresentation.self)
76+
)?.assumingMemoryBound(to: UnsafeRawPointer?.AtomicRep.self)
7777
guard let concurrencyEnqueueGlobalHookPtr = concurrencyEnqueueGlobalHookPtr else {
7878
return false
7979
}
@@ -126,3 +126,12 @@ extension NIOSingletons {
126126
#endif
127127
}
128128
}
129+
130+
// Workaround for https://github.com/apple/swift-nio/issues/2893
131+
extension Optional
132+
where
133+
Wrapped: AtomicOptionalWrappable,
134+
Wrapped.AtomicRepresentation.Value == Wrapped
135+
{
136+
typealias AtomicRep = Wrapped.AtomicOptionalRepresentation
137+
}

0 commit comments

Comments
 (0)