Skip to content

[cmake] add Synchronization library to Supplemental build #81310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Runtimes/Resync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ endforeach()
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Core/Info.plist.in")
copy_files("" "Core" FILES "Info.plist.in")

message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Supplemental/Synchronization/Info.plist.in")
copy_files("" "Supplemental/Synchronization" FILES "Info.plist.in")

# Platform Overlays

# Copy magic linker symbols
Expand Down Expand Up @@ -153,6 +156,8 @@ copy_files(public/Platform Overlay/Windows/CRT
# libraries, and test support libraries.

# Supplemental Libraries
copy_library_sources("Synchronization" "public" "Supplemental")


# Copy StringProcessing, RegexParser, RegexBuilder
if(NOT DEFINED StringProcessing_ROOT_DIR)
Expand Down
12 changes: 12 additions & 0 deletions Runtimes/Supplemental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ endif()

set(COMMON_OPTIONS
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
-DSwift_SDKROOT=${Swift_SDKROOT}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DCMAKE_INSTALL_NAME_DIR=${CMAKE_INSTALL_NAME_DIR}
Expand All @@ -47,3 +48,14 @@ if(SwiftRuntime_ENABLE_stringprocessing)
CMAKE_ARGS
${COMMON_OPTIONS})
endif()

# Synchronization
if(SwiftRuntime_ENABLE_synchronization)
ExternalProject_Add(Synchronization
PREFIX "Synchronization"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Synchronization"
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
INSTALL_COMMAND ""
CMAKE_ARGS
${COMMON_OPTIONS})
endif()
107 changes: 107 additions & 0 deletions Runtimes/Supplemental/Synchronization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
cmake_minimum_required(VERSION 3.29)

if($ENV{BUILD_NUMBER})
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
set(BUILD_NUMBER ".${BUILD_NUMBER}")
endif()

project(SwiftSynchronization
LANGUAGES Swift
VERSION 6.1.0${BUILD_NUMBER})

if(NOT PROJECT_IS_TOP_LEVEL)
message(SEND_ERROR "Swift Synchronization must build as a standalone project")
endif()
Comment on lines +12 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should likely hoist this to right after the project call


set(CMAKE_POSITION_INDEPENDENT_CODE YES)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")

set(CMAKE_Swift_LANGUAGE_VERSION 5)

include(GNUInstallDirs)

set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
"${PROJECT_SOURCE_DIR}/../../../"
CACHE FILEPATH "Path to the root source directory of the Swift compiler")

set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor"
CACHE FILEPATH "Location for private build system extension")

find_package(SwiftCore QUIET REQUIRED)

include(gyb)
include(ResourceEmbedding)
include(AvailabilityMacros)
include(PlatformInfo)

include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)

option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries"
${SwiftCore_ENABLE_LIBRARY_EVOLUTION})

option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization"
${SwiftCore_ENABLE_PRESPECIALIZATION})

include(CatalystSupport)
include(EmitSwiftInterface)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We likely need to import InstallSwiftInterface to be able to call install_swift_interface

include(InstallSwiftInterface)

include(InstallSwiftInterface)

add_compile_options(
"$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>"
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>"
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
$<$<COMPILE_LANGUAGE:Swift>:-enable-builtin-module>
$<$<COMPILE_LANGUAGE:Swift>:-strict-memory-safety>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature RawLayout>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StaticExclusiveOnly>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Extern>")

gyb_expand(Atomics/AtomicIntegers.swift.gyb Atomics/AtomicIntegers.swift)
gyb_expand(Atomics/AtomicStorage.swift.gyb Atomics/AtomicStorage.swift)

add_library(swiftSynchronization
Atomics/Atomic.swift
Atomics/AtomicBool.swift
Atomics/AtomicFloats.swift
Atomics/AtomicLazyReference.swift
Atomics/AtomicMemoryOrderings.swift
Atomics/AtomicOptional.swift
Atomics/AtomicPointers.swift
Atomics/AtomicRepresentable.swift
Atomics/WordPair.swift
Atomics/AtomicStorage.swift
Atomics/AtomicIntegers.swift
Cell.swift
Mutex/Mutex.swift
$<$<PLATFORM_ID:Darwin>:Mutex/DarwinImpl.swift>
$<$<PLATFORM_ID:Linux>:Mutex/LinuxImpl.swift>
$<$<PLATFORM_ID:WASI>:Mutex/SpinLoopHint.swift>
$<$<PLATFORM_ID:WINDOWS>:Mutex/WindowsImpl.swift>)

set_target_properties(swiftSynchronization PROPERTIES
Swift_MODULE_NAME Synchronization)

target_link_libraries(swiftSynchronization
PRIVATE
swiftCore
$<$<PLATFORM_ID:Darwin>:swiftDarwin>)

set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}/${Supplemental_ARCH_SUBDIR}>" CACHE STRING "")
set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}>" CACHE STRING "")

install(TARGETS swiftSynchronization
EXPORT SwiftSynchronizationTargets
COMPONENT ${PROJECT_NAME}_runtime
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
emit_swift_interface(swiftSynchronization)
install_swift_interface(swiftSynchronization)

# Configure plist creation for Darwin platforms.
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftSynchronization)
embed_manifest(swiftSynchronization)

include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftSynchronization.cmake" OPTIONAL)