Skip to content

[Runtimes][CMake] Add Distributed to Supplemental build #81529

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions Runtimes/Resync.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ 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")

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

# Platform Overlays

# Copy magic linker symbols
Expand Down Expand Up @@ -175,3 +178,7 @@ copy_library_sources(_CUnicode "Sources" "Supplemental/StringProcessing/_StringP
ROOT "${StringProcessing_ROOT_DIR}/swift-experimental-string-processing")
copy_library_sources(RegexBuilder "Sources" "Supplemental/StringProcessing"
ROOT "${StringProcessing_ROOT_DIR}/swift-experimental-string-processing")

copy_library_sources("Distributed" "public" "Supplemental")
copy_files(swift/runtime Supplemental/Distributed FILES CMakeConfig.h.in ROOT ${CMAKE_CURRENT_LIST_DIR}/../include)
copy_library_sources(include "" "Supplemental/Distributed")
11 changes: 11 additions & 0 deletions Runtimes/Supplemental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,14 @@ if(SwiftRuntime_ENABLE_synchronization)
CMAKE_ARGS
${COMMON_OPTIONS})
endif()

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

if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
cmake_policy(SET CMP0157 OLD)
endif()

if($ENV{BUILD_NUMBER})
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
set(BUILD_NUMBER ".${BUILD_NUMBER}")
endif()
project(SwiftDistributed
LANGUAGES C CXX Swift
VERSION 6.3.0${BUILD_NUMBER})

if(NOT PROJECT_IS_TOP_LEVEL)
message(SEND_ERROR "Swift Distributed must build as a standalone project")
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE YES)
set(CMAKE_C_VISIBILITY_PRESET "hidden")
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

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

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 REQUIRED)

include(AvailabilityMacros)
include(EmitSwiftInterface)
include(InstallSwiftInterface)
include(PlatformInfo)
include(ResourceEmbedding)
include(CatalystSupport)
include(CxxStandard)
include(SwiftCallingConventions)

option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${${PROJECT_NAME}_INSTALL_NESTED_SUBDIR}>:/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${Supplemental_ARCH_SUBDIR}>" CACHE STRING "")
set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${${PROJECT_NAME}_INSTALL_NESTED_SUBDIR}>:/${${PROJECT_NAME}_PLATFORM_SUBDIR}>" CACHE STRING "")

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})

configure_file("CMakeConfig.h.in"
"${PROJECT_BINARY_DIR}/include/swift/Runtime/CMakeConfig.h"
ESCAPE_QUOTES @ONLY)
Copy link
Member

Choose a reason for hiding this comment

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

This seems sketchy. We shouldn't be re-generating the configuration for the runtime build, but should distribute it or pull it from the build tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see what I can do -- possibly a find module may help here, need to think about the distribution scenario.

Copy link
Member

Choose a reason for hiding this comment

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

If we install/export this from Core, find_package(SwiftCore) should be able to wire this up.

Copy link
Member

Choose a reason for hiding this comment

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

Once the Core and supplemental libraries are built, the CMakeConfig.h file aren't used by anything so it shouldn't be necessary so installing it isn't great.

You're right that it's sketchy if the projects get out of sync. I do think that the SwiftCoreConfig.cmake should export the appropriate settings and that the supplemental libraries should import them to ensure that the values are kept in sync.


add_library(swiftDistributed
DistributedActor.cpp
DistributedActor.swift
DistributedActorSystem.swift
DistributedAssertions.swift
DistributedDefaultExecutor.swift
DistributedMacros.swift
DistributedMetadata.swift
LocalTestingDistributedActorSystem.swift)

target_compile_options(swiftDistributed PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>
$<$<COMPILE_LANGUAGE:Swift>:-parse-stdlib>
$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature AllowUnsafeAttribute>
$<$<COMPILE_LANGUAGE:Swift>:-strict-memory-safety>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-library-level api>"
$<$<COMPILE_LANGUAGE:Swift>:-enforce-exclusivity=unchecked>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NoncopyableGenerics2>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature MemberImportVisibility>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature InoutLifetimeDependence>"
"$<$<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>")

set_target_properties(swiftDistributed PROPERTIES
Swift_MODULE_NAME Distributed
LINKER_LANGUAGE CXX)

if(APPLE AND BUILD_SHARED_LIBS)
target_link_options(swiftDistributed PRIVATE "SHELL:-Xlinker -headerpad_max_install_names")
endif()

target_compile_definitions(swiftDistributed PRIVATE
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftDistributed>)

target_include_directories(swiftDistributed PRIVATE
# FIXME: Use of `swift/Runtime/...`, `swift/ABI/...`, and `swift/Demangling/...`
"${${PROJECT_NAME}_SWIFTC_SOURCE_DIR}/include"
# FIXME: grant access to `runtime/CMakeConfig.h` which should be available
# through the swiftRuntime target.
"${PROJECT_BINARY_DIR}/include"
# For llvm/support headers
"${PROJECT_SOURCE_DIR}/include")

target_link_libraries(swiftDistributed PRIVATE
swiftShims
swiftCore
swift_Concurrency)
# swiftDarwin/Libc/Platform
# builtin_float
Copy link
Member

Choose a reason for hiding this comment

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

_Builtin_float is part of the overlays, we should introduce a find_project(SwiftOverlay) for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggesting this should be more generic -- I was thinking of focusing specifically on _Builtin_float, but that may be too granular.


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

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

include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftDistributed.cmake" OPTIONAL)
17 changes: 17 additions & 0 deletions Runtimes/Supplemental/cmake/modules/CxxStandard.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use C++17
set(${PROJECT_NAME}_MIN_CXX_STANDARD 17)
# Unset CMAKE_CXX_STANDARD if it's too low and in the CMakeCache.txt
if($CACHE{CMAKE_CXX_STANDARD} AND $CACHE{CMAKE_CXX_STANDARD} LESS ${${PROJECT_NAME}_MIN_CXX_STANDARD})
message(WARNING "Resetting cache value for CMAKE_CXX_STANDARD to ${${PROJECT_NAME}_MIN_CXX_STANDARD}")
unset(CMAKE_CXX_STANDARD CACHE)
endif()

# Allow manually specified CMAKE_CXX_STANDARD if it's greater than the minimum
# required C++ version
if(DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS ${${PROJECT_NAME}_MIN_CXX_STANDARD})
message(FATAL_ERROR "Requested CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} which is less than the minimum C++ standard ${${PROJECT_NAME}_MIN_CXX_STANDARD}")
endif()

set(CMAKE_CXX_STANDARD ${${PROJECT_NAME}_MIN_CXX_STANDARD} CACHE STRING "C++ standard to conform to")
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
include(CheckSourceCompiles)
include(CheckCompilerFlag)

check_source_compiles(CXX
"#if !(__has_attribute(swiftcall) && \
__has_attribute(swift_context) && \
__has_attribute(swift_error_result) && \
__has_attribute(swift_indirect_result))
#error CXX compiler must support Swift calling conventions
#endif
int main(void) { return 0; }"
HAVE_SWIFTCALL)

if(NOT HAVE_SWIFTCALL)
message(SEND_ERROR "CXX Compiler must support Swift calling conventions")
endif()

check_source_compiles(CXX
"#if !(__has_attribute(swiftasynccall) && \
__has_attribute(swift_async_context))
#error CXX compiler must support Swift async calling conventions
#endif
int main(void) { return 0; }"
HAVE_SWIFT_ASYNC_CALL)

if(NOT HAVE_SWIFT_ASYNC_CALL)
message(SEND_ERROR "CXX Compiler must support Swift async calling conventions")
endif()