Skip to content

Commit 1bc0056

Browse files
authored
Merge pull request #84393 from edymtt/edymtt/add-runtime-to-new-build-system
Runtimes: add support for Runtime module
2 parents 00f047d + fa72527 commit 1bc0056

File tree

5 files changed

+217
-0
lines changed

5 files changed

+217
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Runtimes/**/*.cpp
8989
Runtimes/**/*.c
9090
Runtimes/**/*.m
9191
Runtimes/**/*.mm
92+
Runtimes/**/*.S
93+
Runtimes/**/*.asm
9294
Runtimes/**/*.def
9395
Runtimes/**/*.gyb
9496
Runtimes/**/*.apinotes

Runtimes/Resync.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function(copy_library_sources name from_prefix to_prefix)
5656
"${ARG_ROOT}/${from_prefix}/${name}/*.c"
5757
"${ARG_ROOT}/${from_prefix}/${name}/*.mm"
5858
"${ARG_ROOT}/${from_prefix}/${name}/*.m"
59+
"${ARG_ROOT}/${from_prefix}/${name}/*.S"
60+
"${ARG_ROOT}/${from_prefix}/${name}/*.asm"
5961
"${ARG_ROOT}/${from_prefix}/${name}/*.def"
6062
"${ARG_ROOT}/${from_prefix}/${name}/*.gyb"
6163
"${ARG_ROOT}/${from_prefix}/${name}/*.apinotes"
@@ -116,6 +118,9 @@ copy_files("" "Supplemental/Synchronization" FILES "Info.plist.in")
116118
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Supplemental/Volatile/Info.plist.in")
117119
copy_files("" "Supplemental/Volatile" FILES "Info.plist.in")
118120

121+
message(STATUS "plist[${StdlibSources}/Info.plist.in] -> Supplemental/Runtime/Info.plist.in")
122+
copy_files("" "Supplemental/Runtime" FILES "Info.plist.in")
123+
119124
# Platform Overlays
120125

121126
# Copy magic linker symbols
@@ -185,6 +190,7 @@ copy_library_sources(Distributed "public" "Supplemental")
185190
copy_library_sources(Observation "public" "Supplemental")
186191
copy_library_sources(Synchronization "public" "Supplemental")
187192
copy_library_sources(Volatile "public" "Supplemental")
193+
copy_library_sources("" "public/RuntimeModule" "Supplemental/Runtime")
188194

189195
copy_library_sources(_RegexParser "Sources" "Supplemental/StringProcessing"
190196
ROOT "${StringProcessing_ROOT_DIR}/swift-experimental-string-processing")

Runtimes/Supplemental/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(COMMON_OPTIONS
3939
-DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER}
4040
-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}
4141
-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}
42+
-DCMAKE_ASM_COMPILER_TARGET=${CMAKE_ASM_COMPILER_TARGET}
4243
-DCMAKE_Swift_COMPILER_TARGET=${CMAKE_Swift_COMPILER_TARGET}
4344
-DCMAKE_FIND_PACKAGE_PREFER_CONFIG=${CMAKE_FIND_PACKAGE_PREFER_CONFIG}
4445
${SwiftCore_DIR_FLAG}
@@ -77,6 +78,8 @@ if(SwiftRuntime_ENABLE_distributed)
7778
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Distributed"
7879
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
7980
INSTALL_COMMAND ""
81+
# To ensure incremental builds work as expected
82+
BUILD_ALWAYS 1
8083
CMAKE_ARGS
8184
${COMMON_OPTIONS})
8285
endif()
@@ -89,6 +92,8 @@ if(SwiftRuntime_ENABLE_differentiation)
8992
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Differentiation"
9093
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
9194
INSTALL_COMMAND ""
95+
# To ensure incremental builds work as expected
96+
BUILD_ALWAYS 1
9297
CMAKE_ARGS
9398
${COMMON_OPTIONS})
9499
endif()
@@ -100,6 +105,21 @@ if(SwiftRuntime_ENABLE_observation)
100105
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Observation"
101106
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
102107
INSTALL_COMMAND ""
108+
# To ensure incremental builds work as expected
109+
BUILD_ALWAYS 1
110+
CMAKE_ARGS
111+
${COMMON_OPTIONS})
112+
endif()
113+
114+
# Runtime
115+
if(SwiftRuntime_ENABLE_runtime)
116+
ExternalProject_Add(Runtime
117+
PREFIX "Runtime"
118+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Runtime"
119+
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
120+
INSTALL_COMMAND ""
121+
# To ensure incremental builds work as expected
122+
BUILD_ALWAYS 1
103123
CMAKE_ARGS
104124
${COMMON_OPTIONS})
105125
endif()
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
list(APPEND CMAKE_MODULE_PATH
13+
"${CMAKE_SOURCE_DIR}/../cmake/modules"
14+
"${CMAKE_SOURCE_DIR}/../../cmake/modules")
15+
16+
include(SwiftProjectVersion)
17+
project(SwiftRuntime
18+
LANGUAGES Swift CXX
19+
VERSION ${SWIFT_RUNTIME_VERSION})
20+
21+
if(NOT PROJECT_IS_TOP_LEVEL)
22+
message(SEND_ERROR "Swift Runtime must build as a standalone project")
23+
endif()
24+
25+
include(AsmSupport)
26+
enable_asm_language()
27+
28+
set(CMAKE_CXX_STANDARD 17)
29+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
30+
set(CMAKE_CXX_EXTENSIONS NO)
31+
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
32+
33+
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR
34+
"${PROJECT_SOURCE_DIR}/../../../"
35+
CACHE FILEPATH "Path to the root source directory of the Swift compiler")
36+
37+
# Hook point for vendor-specific extensions to the build system
38+
# Allowed extension points:
39+
# - DefaultSettings.cmake
40+
# - Settings.cmake
41+
set(${PROJECT_NAME}_VENDOR_MODULE_DIR "${CMAKE_SOURCE_DIR}/../cmake/modules/vendor"
42+
CACHE FILEPATH "Location for private build system extension")
43+
44+
find_package(SwiftCore REQUIRED)
45+
find_package(SwiftOverlay REQUIRED)
46+
#find_package(SwiftDarwin)
47+
48+
include(GNUInstallDirs)
49+
50+
include(AvailabilityMacros)
51+
include(EmitSwiftInterface)
52+
include(InstallSwiftInterface)
53+
include(PlatformInfo)
54+
include(gyb)
55+
include(ResourceEmbedding)
56+
include(CatalystSupport)
57+
58+
option(${PROJECT_NAME}_INSTALL_NESTED_SUBDIR "Install libraries under a platform and architecture subdirectory" ON)
59+
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 "")
60+
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 "")
61+
62+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/Settings.cmake" OPTIONAL)
63+
64+
option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Generate ABI resilient runtime libraries"
65+
${SwiftCore_ENABLE_LIBRARY_EVOLUTION})
66+
67+
option(${PROJECT_NAME}_ENABLE_PRESPECIALIZATION "Enable generic metadata prespecialization"
68+
${SwiftCore_ENABLE_PRESPECIALIZATION})
69+
70+
add_compile_options(
71+
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build>
72+
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport>
73+
$<$<COMPILE_LANGUAGE:Swift>:-parse-stdlib>
74+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-swift-version 5>"
75+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enforce-exclusivity=unchecked>"
76+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -target-min-inlining-version -Xfrontend min>"
77+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-string-processing-module-import>"
78+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NoncopyableGenerics2>"
79+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>"
80+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>"
81+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>"
82+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>"
83+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature InoutLifetimeDependence>"
84+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependenceMutableAccessors>"
85+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-disable-upcoming-feature MemberImportVisibility>"
86+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-lexical-lifetimes=false>"
87+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -enable-ossa-modules>"
88+
"$<$<COMPILE_LANGUAGE:Swift>:-warn-implicit-overrides>"
89+
"$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>"
90+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -experimental-spi-only-imports>"
91+
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>"
92+
"$<$<AND:$<BOOL:${${PROJECT_NAME}_ENABLE_PRESPECIALIZATION}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xfrontend -prespecialize-generic-metadata>")
93+
94+
# LNK4049: symbol 'symbol' defined in 'filename.obj' is imported
95+
# LNK4286: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj'
96+
# LNK4217: symbol 'symbol' defined in 'filename_1.obj' is imported by 'filename_2.obj' in function 'function'
97+
#
98+
# We cannot selectively filter the linker warnings as we do not use the MSVC
99+
# frontned and `clang-cl` (and `clang`) currently do not support `/WX:nnnn`. As
100+
# a compromise, treat all linker warnings as errors.
101+
add_link_options($<$<PLATFORM_ID:Windows>:LINKER:/WX>)
102+
# Ensure all symbols are fully resolved on Linux
103+
add_link_options($<$<PLATFORM_ID:Linux>:LINKER:-z,defs>)
104+
105+
add_library(swiftRuntime
106+
Address.swift
107+
Backtrace.swift
108+
Backtrace+Codable.swift
109+
BacktraceFormatter.swift
110+
Base64.swift
111+
ByteSwapping.swift
112+
CachingMemoryReader.swift
113+
CompactBacktrace.swift
114+
CompactImageMap.swift
115+
Compression.swift
116+
Context.swift
117+
CoreSymbolication.swift
118+
Dwarf.swift
119+
EightByteBuffer.swift
120+
Elf.swift
121+
ElfImageCache.swift
122+
FramePointerUnwinder.swift
123+
Image.swift
124+
ImageMap.swift
125+
ImageMap+Darwin.swift
126+
ImageMap+Linux.swift
127+
ImageSource.swift
128+
Libc.swift
129+
LimitSequence.swift
130+
MemoryReader.swift
131+
OSReleaseScanner.swift
132+
ProcMapsScanner.swift
133+
Registers.swift
134+
Runtime.swift
135+
RichFrame.swift
136+
SymbolicatedBacktrace.swift
137+
Utils.swift
138+
Win32Extras.cpp
139+
get-cpu-context.${SWIFT_ASM_EXT})
140+
141+
set_target_properties(swiftRuntime PROPERTIES
142+
Swift_MODULE_NAME Runtime)
143+
target_compile_definitions(swiftRuntime PRIVATE
144+
SWIFT_ASM_AVAILABLE)
145+
target_compile_options(swiftRuntime PRIVATE
146+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/modules/module.modulemap>")
147+
# FIXME: We should split out the parts that are needed by the runtime to avoid
148+
# pulling in headers from the compiler.
149+
target_include_directories(swiftRuntime PRIVATE
150+
"${${PROJECT_NAME}_SWIFTC_SOURCE_DIR}/include")
151+
target_link_libraries(swiftRuntime PRIVATE
152+
swiftShims
153+
swiftCore
154+
swift_Concurrency
155+
swiftCxxStdlib
156+
$<$<PLATFORM_ID:Android>:swiftAndroid>
157+
#$<$<PLATFORM_ID:Darwin>:swiftDarwin>
158+
$<$<PLATFORM_ID:Linux>:swiftGlibc>
159+
$<$<PLATFORM_ID:Windows>:swiftWinSDK>)
160+
161+
install(TARGETS swiftRuntime
162+
EXPORT SwiftRuntimeTargets
163+
COMPONENT ${PROJECT_NAME}_runtime
164+
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
165+
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}"
166+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
167+
emit_swift_interface(swiftRuntime)
168+
install_swift_interface(swiftRuntime)
169+
170+
# Configure plist creation for Darwin platforms.
171+
generate_plist(swiftRuntime "${CMAKE_PROJECT_VERSION}" swiftRuntime)
172+
embed_manifest(swiftRuntime)
173+
174+
include("${${PROJECT_NAME}_VENDOR_MODULE_DIR}/SwiftRuntime.cmake" OPTIONAL)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
macro(enable_asm_language)
2+
# On Windows, use MASM or MARMASM
3+
set(SWIFT_ASM_DIALECT ASM)
4+
set(SWIFT_ASM_EXT S)
5+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
6+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64")
7+
set(SWIFT_ASM_DIALECT ASM_MARMASM)
8+
else()
9+
set(SWIFT_ASM_DIALECT ASM_MASM)
10+
endif()
11+
set(SWIFT_ASM_EXT asm)
12+
endif()
13+
14+
enable_language(${SWIFT_ASM_DIALECT})
15+
endmacro()

0 commit comments

Comments
 (0)