Skip to content

Commit 5c1b20d

Browse files
committed
stdlib: Build libswiftCompatibilitySpan.dylib compatibility shim
This dynamic library contains a copy of the standard library's exported entry points for the Span and RawSpan types. This will allow backward deployment of code that uses those new types.
1 parent 0aeba05 commit 5c1b20d

File tree

5 files changed

+122
-0
lines changed

5 files changed

+122
-0
lines changed

stdlib/public/core/Span/RawSpan.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
/// `RawSpan` represents a contiguous region of memory
1418
/// which contains initialized bytes.
1519
///

stdlib/public/core/Span/Span.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#if SPAN_COMPATIBILITY_STUB
14+
import Swift
15+
#endif
16+
1317
/// `Span<Element>` represents a contiguous region of memory
1418
/// which contains initialized instances of `Element`.
1519
///

stdlib/toolchain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ if(SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
5050
add_subdirectory(Compatibility50)
5151
add_subdirectory(Compatibility51)
5252
add_subdirectory(Compatibility56)
53+
add_subdirectory(CompatibilitySpan)
5354
add_subdirectory(CompatibilityDynamicReplacements)
5455
add_subdirectory(CompatibilityConcurrency)
5556
add_subdirectory(CompatibilityThreading)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
2+
3+
set(library_name "swiftCompatibilitySpan")
4+
5+
add_swift_target_library("${library_name}" ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
6+
FakeStdlib.swift
7+
../../public/core/Span/RawSpan.swift
8+
../../public/core/Span/Span.swift
9+
10+
TARGET_SDKS ${SWIFT_APPLE_PLATFORMS}
11+
12+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
13+
14+
SWIFT_COMPILE_FLAGS
15+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
16+
-parse-stdlib
17+
-module-abi-name Swift
18+
-DSPAN_COMPATIBILITY_STUB
19+
20+
DEPLOYMENT_VERSION_OSX ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX}
21+
DEPLOYMENT_VERSION_IOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS}
22+
DEPLOYMENT_VERSION_TVOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS}
23+
DEPLOYMENT_VERSION_WATCHOS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS}
24+
DEPLOYMENT_VERSION_XROS ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_XROS}
25+
DEPLOYMENT_VERSION_MACCATALYST ${COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_MACCATALYST}
26+
27+
MACCATALYST_BUILD_FLAVOR "zippered"
28+
29+
INSTALL_IN_COMPONENT compiler
30+
31+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" -Xlinker -not_for_dyld_shared_cache
32+
33+
BACK_DEPLOYMENT_LIBRARY 6.2)
34+
endif()
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===--- FakeStdlib.swift -------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// A handful of standard library stubs to allow Span.swift and RawSpan.swift
14+
// to be compiled as part of the compatibility shim.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
import Swift
19+
20+
@_alwaysEmitIntoClient @_transparent
21+
internal func _precondition(
22+
_ condition: @autoclosure () -> Bool, _ message: StaticString = StaticString(),
23+
file: StaticString = #file, line: UInt = #line
24+
) {
25+
fatalError()
26+
}
27+
28+
@_alwaysEmitIntoClient @_transparent
29+
internal func _internalInvariantFailure(
30+
_ message: StaticString = StaticString(),
31+
file: StaticString = #file, line: UInt = #line
32+
) -> Never {
33+
fatalError()
34+
}
35+
36+
@unsafe
37+
@_unsafeNonescapableResult
38+
@_alwaysEmitIntoClient
39+
@_transparent
40+
@lifetime(borrow source)
41+
internal func _overrideLifetime<
42+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
43+
>(
44+
_ dependent: consuming T, borrowing source: borrowing U
45+
) -> T {
46+
dependent
47+
}
48+
49+
@unsafe
50+
@_unsafeNonescapableResult
51+
@_alwaysEmitIntoClient
52+
@_transparent
53+
@lifetime(copy source)
54+
internal func _overrideLifetime<
55+
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
56+
>(
57+
_ dependent: consuming T, copying source: borrowing U
58+
) -> T {
59+
dependent
60+
}
61+
62+
extension Range {
63+
@_alwaysEmitIntoClient
64+
internal init(_uncheckedBounds bounds: (lower: Bound, upper: Bound)) {
65+
self.init(uncheckedBounds: bounds)
66+
}
67+
}
68+
69+
extension Optional {
70+
@_alwaysEmitIntoClient
71+
internal var _unsafelyUnwrappedUnchecked: Wrapped {
72+
get {
73+
if let x = self {
74+
return x
75+
}
76+
_internalInvariantFailure("_unsafelyUnwrappedUnchecked of nil optional")
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)