From a34edba5f4c0da2192eed568e95ccb94f71b2ab9 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 11 Jul 2025 11:24:18 -0700 Subject: [PATCH] Runtimes: add an initial build of Observation This migrates Observation to the new runtimes build. It requires some additional help during the build to locate the internal `CMakeConfig.h` header from the runtime build. However, this is a good skeleton for us to start addressing some of those issues. --- Runtimes/Resync.cmake | 4 +- .../Supplemental/Observation/CMakeLists.txt | 112 ++++++++++++++++++ .../Supplemental/Observation/Info.plist.in | 16 +++ 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 Runtimes/Supplemental/Observation/CMakeLists.txt create mode 100644 Runtimes/Supplemental/Observation/Info.plist.in diff --git a/Runtimes/Resync.cmake b/Runtimes/Resync.cmake index d0319c131ff79..fd116eafd98a7 100644 --- a/Runtimes/Resync.cmake +++ b/Runtimes/Resync.cmake @@ -156,8 +156,8 @@ copy_files(public/Platform Overlay/Windows/CRT # libraries, and test support libraries. # Supplemental Libraries -copy_library_sources("Synchronization" "public" "Supplemental") - +copy_library_sources(Synchronization "public" "Supplemental") +copy_library_sources(Observation "public" "Supplemental") # Copy StringProcessing, RegexParser, RegexBuilder if(NOT DEFINED StringProcessing_ROOT_DIR) diff --git a/Runtimes/Supplemental/Observation/CMakeLists.txt b/Runtimes/Supplemental/Observation/CMakeLists.txt new file mode 100644 index 0000000000000..bce09ac4bd4d5 --- /dev/null +++ b/Runtimes/Supplemental/Observation/CMakeLists.txt @@ -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$<$>:_static>$<$:/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}>" CACHE STRING "") +set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$>:_static>$<$:/${${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( + $<$:-explicit-module-build> + $<$:-nostdlibimport> + $<$:-enable-builtin-module> + $<$:-strict-memory-safety> + "$<$:SHELL:-enable-experimental-feature RawLayout>" + "$<$:SHELL:-enable-experimental-feature StaticExclusiveOnly>" + "$<$:SHELL:-enable-experimental-feature Extern>" + "$<$,$>:-enable-library-evolution>" + "$<$,$>: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 + $<$:swiftAndroid> + $<$:swiftDarwin> + $<$:swiftGlibc> + $<$: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) + +include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftObservation.cmake" OPTIONAL) diff --git a/Runtimes/Supplemental/Observation/Info.plist.in b/Runtimes/Supplemental/Observation/Info.plist.in new file mode 100644 index 0000000000000..04673e8d55a62 --- /dev/null +++ b/Runtimes/Supplemental/Observation/Info.plist.in @@ -0,0 +1,16 @@ + + + + + CFBundleIdentifier + @PLIST_INFO_UTI@ + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + @PLIST_INFO_NAME@ + CFBundleShortVersionString + @PLIST_INFO_VERSION@ + CFBundleVersion + @PLIST_INFO_BUILD_VERSION@ + +