Skip to content

Commit d2e98e9

Browse files
committed
[embedded] Start building Synchronization in embeddeded Swift mode
1 parent 2ebae40 commit d2e98e9

File tree

7 files changed

+66
-19
lines changed

7 files changed

+66
-19
lines changed

docs/EmbeddedSwift/EmbeddedSwiftStatus.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ This status table describes which of the following Swift features can be used in
4848

4949
| **Swift Feature** | **Currently Supported In Embedded Swift?** |
5050
|------------------------------------------------------------|-----------------------------------------------------|
51+
| Synchronization module | Yes |
5152
| Swift Concurrency | Partial, experimental (basics of actors and tasks work in single-threaded concurrency mode) |
5253
| C interop | Yes |
5354
| C++ interop | Yes |

docs/EmbeddedSwift/UserManual.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ For (2), external dependencies are also triggered by specific code needing them,
197197
- **atomics instrinsics**
198198
- on CPU architectures that don't have direct load-acquire/store-release support in the ISA, LLVM calls helper functions for atomic operations
199199
- needed by refcounting in the Embedded Swift runtime (so any class usage will trigger this dependency)
200+
- also needed when using atomics from the Synchronization module
200201
- **multiplication/division/modulo instrinsics**
201202
- on CPU architectures that don't have direct support for the math operations in the ISA
202203
- dependency (on Mach-O): `__divti3`

stdlib/public/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
206206
"x86_64 x86_64-unknown-none-elf x86_64-unknown-none-elf"
207207
# Without specifying the `windows` component LLVM refuses to
208208
# generate valid COFF object files.
209-
"i686 i686-unknown-windows-coff i686-unknown-windows-coff"
210-
"x86_64 x86_64-unknown-windows-coff x86_64-unknown-windows-coff"
209+
"i686 i686-unknown-windows-msvc i686-unknown-windows-msvc"
210+
"x86_64 x86_64-unknown-windows-msvc x86_64-unknown-windows-msvc"
211211
)
212212
endif()
213213

stdlib/public/Synchronization/AtomicMemoryOrderings.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ extension AtomicLoadOrdering: Hashable {
9696
}
9797

9898
@available(SwiftStdlib 6.0, *)
99+
@_unavailableInEmbedded
99100
extension AtomicLoadOrdering: CustomStringConvertible {
100101
@available(SwiftStdlib 6.0, *)
101102
public var description: String {
@@ -191,6 +192,7 @@ extension AtomicStoreOrdering: Hashable {
191192
}
192193

193194
@available(SwiftStdlib 6.0, *)
195+
@_unavailableInEmbedded
194196
extension AtomicStoreOrdering: CustomStringConvertible {
195197
@available(SwiftStdlib 6.0, *)
196198
public var description: String {
@@ -315,6 +317,7 @@ extension AtomicUpdateOrdering: Hashable {
315317
}
316318

317319
@available(SwiftStdlib 6.0, *)
320+
@_unavailableInEmbedded
318321
extension AtomicUpdateOrdering: CustomStringConvertible {
319322
@available(SwiftStdlib 6.0, *)
320323
public var description: String {

stdlib/public/Synchronization/CMakeLists.txt

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
#
1111
#===----------------------------------------------------------------------===#
1212

13-
add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
14-
# List of files here:
13+
set(swift_synchronization_sources
1514
Atomic.swift
1615
AtomicBool.swift
1716
AtomicFloats.swift
@@ -21,23 +20,67 @@ add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES
2120
AtomicPointers.swift
2221
AtomicRepresentable.swift
2322
WordPair.swift
23+
)
24+
set(swift_synchronization_gyb_sources
25+
AtomicIntegers.swift.gyb
26+
AtomicStorage.swift.gyb
27+
)
28+
set(swift_synchronization_swift_compile_flags
29+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
30+
"-enable-builtin-module"
31+
"-enable-experimental-feature" "RawLayout"
32+
"-enable-experimental-feature" "StaticExclusiveOnly"
33+
)
2434

25-
GYB_SOURCES
26-
AtomicIntegers.swift.gyb
27-
AtomicStorage.swift.gyb
28-
29-
SWIFT_COMPILE_FLAGS
30-
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
31-
"-enable-builtin-module"
32-
"-enable-experimental-feature" "RawLayout"
33-
"-enable-experimental-feature" "StaticExclusiveOnly"
34-
35+
add_swift_target_library(swiftSynchronization ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
36+
${swift_synchronization_sources}
37+
GYB_SOURCES ${swift_synchronization_gyb_sources}
38+
SWIFT_COMPILE_FLAGS ${swift_synchronization_swift_compile_flags}
3539
LINK_FLAGS
3640
"${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
37-
3841
INSTALL_IN_COMPONENT
3942
stdlib
40-
4143
MACCATALYST_BUILD_FLAVOR
4244
"zippered"
4345
)
46+
47+
# Embedded Synchronization - embedded libraries are built as .swiftmodule only,
48+
# i.e. there is no .o or .a file produced (no binary code is actually produced)
49+
# and only users of a library are going to actually compile any needed code.
50+
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
51+
add_custom_target(embedded-synchronization ALL)
52+
53+
foreach(entry ${EMBEDDED_STDLIB_TARGET_TRIPLES})
54+
string(REGEX REPLACE "[ \t]+" ";" list "${entry}")
55+
list(GET list 0 arch)
56+
list(GET list 1 mod)
57+
list(GET list 2 triple)
58+
59+
set(SWIFT_SDK_embedded_ARCH_${arch}_MODULE "${mod}")
60+
set(SWIFT_SDK_embedded_LIB_SUBDIR "embedded")
61+
set(SWIFT_SDK_embedded_ARCH_${arch}_TRIPLE "${triple}")
62+
set(SWIFT_SDK_embedded_PATH ${SWIFT_SDK_OSX_PATH})
63+
set(SWIFT_SDK_embedded_ARCH_${arch}_PATH ${SWIFT_SDK_OSX_PATH})
64+
set(SWIFT_SDK_embedded_USE_ISYSROOT TRUE)
65+
add_swift_target_library_single(
66+
embedded-synchronization-${mod}
67+
swiftSynchronization
68+
ONLY_SWIFTMODULE
69+
IS_FRAGILE
70+
71+
${swift_synchronization_sources}
72+
GYB_SOURCES ${swift_synchronization_gyb_sources}
73+
74+
SWIFT_COMPILE_FLAGS
75+
${swift_synchronization_swift_compile_flags}
76+
-Xcc -D__MACH__ -Xcc -D__APPLE__ -Xcc -ffreestanding -enable-experimental-feature Embedded
77+
78+
MODULE_DIR "${CMAKE_BINARY_DIR}/lib/swift/embedded"
79+
SDK "embedded"
80+
ARCHITECTURE "${arch}"
81+
DEPENDS embedded-stdlib-${mod}
82+
INSTALL_IN_COMPONENT stdlib
83+
)
84+
add_dependencies(embedded-synchronization embedded-synchronization-${mod})
85+
endforeach()
86+
endif()

stdlib/public/Synchronization/WordPair.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ extension WordPair: Hashable {
184184
}
185185

186186
@available(SwiftStdlib 6.0, *)
187+
@_unavailableInEmbedded
187188
extension WordPair: CustomStringConvertible {
188189
/// A string that represents the contents of the word pair.
189190
@available(SwiftStdlib 6.0, *)
@@ -193,6 +194,7 @@ extension WordPair: CustomStringConvertible {
193194
}
194195

195196
@available(SwiftStdlib 6.0, *)
197+
@_unavailableInEmbedded
196198
extension WordPair: CustomDebugStringConvertible {
197199
/// A string that represents the contents of the word pair, suitable for
198200
/// debugging.

stdlib/public/core/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ add_swift_target_library(swiftCore
411411
# Embedded standard library - embedded libraries are built as .swiftmodule only,
412412
# i.e. there is no .o or .a file produced (no binary code is actually produced)
413413
# and only users of a library are going to actually compile any needed code.
414-
#
415-
# For now, we build a hardcoded list of target triples of the embedded stdlib,
416-
# and only when building Swift on macOS.
417414
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
418415
add_custom_target(embedded-stdlib ALL)
419416

0 commit comments

Comments
 (0)