diff --git a/Sources/Testing/Support/Locked+Platform.swift b/Sources/Testing/Support/Locked+Platform.swift index 951e62da8..2b3f5b648 100644 --- a/Sources/Testing/Support/Locked+Platform.swift +++ b/Sources/Testing/Support/Locked+Platform.swift @@ -94,3 +94,14 @@ typealias DefaultLock = Never #warning("Platform-specific implementation missing: locking unavailable") typealias DefaultLock = Never #endif + +#if SWT_NO_DYNAMIC_LINKING +/// A function which, when called by another file, ensures that the file in +/// which ``DefaultLock`` is declared is linked. +/// +/// When static linking is used, the linker may opt to strip some or all of the +/// symbols (including protocol conformance metadata) declared in this file. +/// ``LockedWith`` calls this function in ``LockedWith/init(rawValue:)`` to work +/// around that issue. +func linkLockImplementations() {} +#endif diff --git a/Sources/Testing/Support/Locked.swift b/Sources/Testing/Support/Locked.swift index e8b17be7b..c69cfd351 100644 --- a/Sources/Testing/Support/Locked.swift +++ b/Sources/Testing/Support/Locked.swift @@ -66,6 +66,10 @@ struct LockedWith: RawRepresentable where L: Lockable { private nonisolated(unsafe) var _storage: ManagedBuffer init(rawValue: T) { +#if SWT_NO_DYNAMIC_LINKING + linkLockImplementations() +#endif + _storage = _Storage.create(minimumCapacity: 1, makingHeaderWith: { _ in rawValue }) _storage.withUnsafeMutablePointerToElements { lock in L.initializeLock(at: lock)