-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Runtimes: add an initial build of Observation #83006
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
cmake_minimum_required(VERSION 3.29) | ||
# TODO before requiring CMake 4.1 or later | ||
# and/or enforcing CMP0195, please check/update | ||
# the implementation of `emit_swift_interface` | ||
# in `EmitSwiftInterface.cmake` | ||
# to ensure it keeps laying down nested swiftmodule folders | ||
|
||
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(SwiftObservation | ||
LANGUAGES Swift CXX | ||
VERSION 6.1.0${BUILD_NUMBER}) | ||
|
||
if(NOT PROJECT_IS_TOP_LEVEL) | ||
message(SEND_ERROR "Swift Observation must build as a standalone project") | ||
endif() | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | ||
set(CMAKE_CXX_EXTENSIONS NO) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE 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") | ||
|
||
# Hook point for vendor-specific extensions to the build system | ||
# Allowed extension points: | ||
# - DefaultSettings.cmake | ||
# - Settings.cmake | ||
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(GNUInstallDirs) | ||
|
||
include(AvailabilityMacros) | ||
include(EmitSwiftInterface) | ||
include(InstallSwiftInterface) | ||
include(PlatformInfo) | ||
include(gyb) | ||
include(ResourceEmbedding) | ||
include(CatalystSupport) | ||
|
||
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}/${${PROJECT_NAME}_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}) | ||
|
||
add_compile_options( | ||
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build> | ||
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport> | ||
$<$<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>" | ||
"$<$<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>") | ||
|
||
add_library(swiftObservation | ||
Sources/Observation/Locking.swift | ||
Sources/Observation/Observable.swift | ||
Sources/Observation/ObservationRegistrar.swift | ||
Sources/Observation/ObservationTracking.swift | ||
Sources/Observation/Observations.swift | ||
Sources/Observation/ThreadLocal.swift | ||
Sources/Observation/ThreadLocal.cpp) | ||
set_target_properties(swiftObservation PROPERTIES | ||
Swift_MODULE_NAME Observation) | ||
# FIXME: We should split out the parts that are needed by the runtime to avoid | ||
# pulling in headers from the compiler. | ||
target_include_directories(swiftObservation PRIVATE | ||
"${${PROJECT_NAME}_SWIFTC_SOURCE_DIR}/include") | ||
target_link_libraries(swiftObservation PRIVATE | ||
swiftCore | ||
swift_Concurrency | ||
$<$<PLATFORM_ID:Android>:swiftAndroid> | ||
$<$<PLATFORM_ID:Darwin>:swiftDarwin> | ||
$<$<PLATFORM_ID:Linux>:swiftGlibc> | ||
$<$<PLATFORM_ID:Windows>:swiftWinSDK>) | ||
|
||
install(TARGETS swiftObservation | ||
EXPORT SwiftObservationTargets | ||
COMPONENT ${PROJECT_NAME}_runtime | ||
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" | ||
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" | ||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") | ||
emit_swift_interface(swiftObservation) | ||
install_swift_interface(swiftObservation) | ||
|
||
# Configure plist creation for Darwin platforms. | ||
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftObservation) | ||
embed_manifest(swiftObservation) | ||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftObservation.cmake" OPTIONAL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleIdentifier</key> | ||
<string>@PLIST_INFO_UTI@</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>@PLIST_INFO_NAME@</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>@PLIST_INFO_VERSION@</string> | ||
<key>CFBundleVersion</key> | ||
<string>@PLIST_INFO_BUILD_VERSION@</string> | ||
</dict> | ||
</plist> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Optional at this stage: we should specify the linker language since we have a C++ source file
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.
We don't want to link with the C++ driver, we want to link with the Swift driver. We could be explicit and use the
LINKER_LANGUAGE Swift
, but I don't think that adds anything of value.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.
I assumed we needed to link with the C++ driver to ensure we link the correct C++ standard library, as per discussion in #79972 and #80139 -- I'm fine with not forcing it for now and see if we hit issues later.
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.
Selection of the c++ standard library should be driven by a flag in the swift-driver - we need this functionality for the C++ interop anyway. I believe that the current best option is
-Xcc -stdlib=... -Xlinker -Xcc -Xlinker -stdlib=...
(CC: @artemcm)