-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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) |
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() | ||
edymtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 | ||
edymtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#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 | ||
edymtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.