Skip to content

Commit a34edba

Browse files
committed
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.
1 parent 5d66fda commit a34edba

File tree

3 files changed

+130
-2
lines changed

3 files changed

+130
-2
lines changed

Runtimes/Resync.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ copy_files(public/Platform Overlay/Windows/CRT
156156
# libraries, and test support libraries.
157157

158158
# Supplemental Libraries
159-
copy_library_sources("Synchronization" "public" "Supplemental")
160-
159+
copy_library_sources(Synchronization "public" "Supplemental")
160+
copy_library_sources(Observation "public" "Supplemental")
161161

162162
# Copy StringProcessing, RegexParser, RegexBuilder
163163
if(NOT DEFINED StringProcessing_ROOT_DIR)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
cmake_minimum_required(VERSION 3.29)
2+
# TODO before requiring CMake 4.1 or later
3+
# and/or enforcing CMP0195, please check/update
4+
# the implementation of `emit_swift_interface`
5+
# in `EmitSwiftInterface.cmake`
6+
# to ensure it keeps laying down nested swiftmodule folders
7+
8+
if(POLICY CMP0157 AND CMAKE_Swift_COMPILER_USE_OLD_DRIVER)
9+
cmake_policy(SET CMP0157 OLD)
10+
endif()
11+
12+
if($ENV{BUILD_NUMBER})
13+
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535")
14+
set(BUILD_NUMBER ".${BUILD_NUMBER}")
15+
endif()
16+
project(SwiftObservation
17+
LANGUAGES Swift CXX
18+
VERSION 6.1.0${BUILD_NUMBER})
19+
20+
if(NOT PROJECT_IS_TOP_LEVEL)
21+
message(SEND_ERROR "Swift Observation must build as a standalone project")
22+
endif()
23+
24+
set(CMAKE_CXX_STANDARD 17)
25+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
26+
set(CMAKE_CXX_EXTENSIONS NO)
27+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
28+
29+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules")
30+
31+
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
32+
"${PROJECT_SOURCE_DIR}/../../../"
33+
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
34+
35+
# Hook point for vendor-specific extensions to the build system
36+
# Allowed extension points:
37+
# - DefaultSettings.cmake
38+
# - Settings.cmake
39+
set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor"
40+
CACHE FILEPATH "Location for private build system extension")
41+
42+
find_package(SwiftCore REQUIRED)
43+
44+
include(GNUInstallDirs)
45+
46+
include(AvailabilityMacros)
47+
include(EmitSwiftInterface)
48+
include(InstallSwiftInterface)
49+
include(PlatformInfo)
50+
include(gyb)
51+
include(ResourceEmbedding)
52+
include(CatalystSupport)
53+
54+
option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
55+
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 "")
56+
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 "")
57+
58+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)
59+
60+
option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries"
61+
${SwiftCore_ENABLE_LIBRARY_EVOLUTION})
62+
63+
option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization"
64+
${SwiftCore_ENABLE_PRESPECIALIZATION})
65+
66+
add_compile_options(
67+
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
68+
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>
69+
$<$<COMPILE_LANGUAGE:Swift>:-enable-builtin-module>
70+
$<$<COMPILE_LANGUAGE:Swift>:-strict-memory-safety>
71+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature RawLayout>"
72+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature StaticExclusiveOnly>"
73+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature Extern>"
74+
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
75+
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>")
76+
77+
add_library(swiftObservation
78+
Sources/Observation/Locking.swift
79+
Sources/Observation/Observable.swift
80+
Sources/Observation/ObservationRegistrar.swift
81+
Sources/Observation/ObservationTracking.swift
82+
Sources/Observation/Observations.swift
83+
Sources/Observation/ThreadLocal.swift
84+
Sources/Observation/ThreadLocal.cpp)
85+
set_target_properties(swiftObservation PROPERTIES
86+
Swift_MODULE_NAME Observation)
87+
# FIXME: We should split out the parts that are needed by the runtime to avoid
88+
# pulling in headers from the compiler.
89+
target_include_directories(swiftObservation PRIVATE
90+
"${${PROJECT_NAME}_SWIFTC_SOURCE_DIR}/include")
91+
target_link_libraries(swiftObservation PRIVATE
92+
swiftCore
93+
swift_Concurrency
94+
$<$<PLATFORM_ID:Android>:swiftAndroid>
95+
$<$<PLATFORM_ID:Darwin>:swiftDarwin>
96+
$<$<PLATFORM_ID:Linux>:swiftGlibc>
97+
$<$<PLATFORM_ID:Windows>:swiftWinSDK>)
98+
99+
install(TARGETS swiftObservation
100+
EXPORT SwiftObservationTargets
101+
COMPONENT ${PROJECT_NAME}_runtime
102+
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
103+
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
104+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
105+
emit_swift_interface(swiftObservation)
106+
install_swift_interface(swiftObservation)
107+
108+
# Configure plist creation for Darwin platforms.
109+
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftObservation)
110+
embed_manifest(swiftObservation)
111+
112+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/swiftObservation.cmake" OPTIONAL)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>@PLIST_INFO_UTI@</string>
7+
<key>CFBundleInfoDictionaryVersion</key>
8+
<string>6.0</string>
9+
<key>CFBundleName</key>
10+
<string>@PLIST_INFO_NAME@</string>
11+
<key>CFBundleShortVersionString</key>
12+
<string>@PLIST_INFO_VERSION@</string>
13+
<key>CFBundleVersion</key>
14+
<string>@PLIST_INFO_BUILD_VERSION@</string>
15+
</dict>
16+
</plist>

0 commit comments

Comments
 (0)