Skip to content

Commit 7870db6

Browse files
committed
CMake: Runtime Installation Story
Starting to work on a full installation story for the Swift runtimes. This involves generating the SwiftCoreConfig cmake files to allow importing the just-built runtimes into the overlays and supplemental libraries, setting up the flags appropriately for the given SwiftCore build configuration. This also separates out the development and runtime components to allow installing just the runtimes without the headers. Component List: - SwiftCore_runtime The runtime libraries that are required for running code. - SwiftCore_development The interface with the runtime libraries that are required for building code against the runtimes. - SwiftCore_cmake Files for interfacing CMake projects with the built runtimes. This includes the target list and flags needed to use the targets built by the specific configuration used to build the runtime libraries. These files are used for mapping flags, definitions, and locations into the overlay libraries and supplemental libraries. This adds install commands for the object libraries contributing to libswiftCore so that they are represented in SwiftCoreTargets.cmake. Object libraries do not contribute anything to the files actually installed.
1 parent 7484f01 commit 7870db6

File tree

13 files changed

+95
-20
lines changed

13 files changed

+95
-20
lines changed

Runtimes/Core/CMakeLists.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ add_compile_definitions(
143143
$<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_OBJC_INTEROP>
144144
$<$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>:-DSWIFT_LIBRARY_EVOLUTION>
145145
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
146-
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>
147146
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
148147
$<$<BOOL:${SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS}>:-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS>
149148
$<$<BOOL:${SwiftCore_ENABLE_STDIN}>:-DSWIFT_STDLIB_HAS_STDIN> # core + stubs
@@ -225,3 +224,22 @@ endif()
225224
if(SwiftCore_ENABLE_CONCURRENCY)
226225
add_subdirectory(Concurrency)
227226
endif()
227+
228+
# Inter-project install info
229+
export(EXPORT SwiftCoreTargets
230+
FILE "cmake/SwiftCore/SwiftCoreTargets.cmake")
231+
install(EXPORT SwiftCoreTargets
232+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore"
233+
FILE "SwiftCoreTargets.cmake"
234+
COMPONENT SwiftCore_cmake)
235+
include(CMakePackageConfigHelpers)
236+
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/interface/SwiftCoreConfig.cmake.in"
237+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
238+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")
239+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
240+
VERSION "${PROJECT_VERSION}"
241+
COMPATIBILITY ExactVersion)
242+
install(FILES
243+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
244+
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
245+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")

Runtimes/Core/CommandLineSupport/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ if(SwiftCore_ENABLE_COMMANDLINE_SUPPORT)
1010
swiftShims)
1111

1212
if(NOT BUILD_SHARED_LIBS)
13-
install(TARGETS swiftCommandLineSupport)
13+
install(TARGETS swiftCommandLineSupport
14+
EXPORT SwiftCoreTargets
15+
COMPONENT SwiftCore_runtime)
1416
endif()
1517
endif()

Runtimes/Core/Concurrency/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ set_target_properties(swift_Concurrency PROPERTIES
118118
Swift_MODULE_NAME _Concurrency)
119119

120120
install(TARGETS swift_Concurrency
121+
EXPORT SwiftCoreTargets
122+
COMPONENT SwiftCore_runtime
121123
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
122124
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
123125
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Runtimes/Core/Demangling/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@ if(LINUX OR BSD)
4848
endif()
4949

5050
if(NOT BUILD_SHARED_LIBS)
51-
install(TARGETS swiftDemangling)
51+
install(TARGETS swiftDemangling
52+
EXPORT SwiftCoreTargets
53+
COMPONENT SwiftCore_runtime)
5254
endif()

Runtimes/Core/LLVMSupport/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ add_library(swiftLLVMSupport OBJECT
88
target_compile_options(swiftLLVMSupport
99
PRIVATE
1010
$<$<BOOL:${SwiftCore_HAS_ASL}>:-DSWIFT_STDLIB_HAS_ASL>)
11+
12+
if(NOT BUILD_SHARED_LIBS)
13+
install(TARGETS swiftLLVMSupport
14+
EXPORT SwiftCoreTargets
15+
COMPONENT SwiftCore_runtime)
16+
endif()

Runtimes/Core/SwiftOnoneSupport/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ target_link_libraries(swiftSwiftOnoneSupport
3232
swiftCore)
3333

3434
install(TARGETS swiftSwiftOnoneSupport
35+
EXPORT SwiftCoreTargets
36+
COMPONENT SwiftCore_runtime
3537
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
3638
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
3739
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Runtimes/Core/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ install(FILES
2828
_SwiftDistributed.h
2929
_SynchronizationShims.h
3030
module.modulemap
31-
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims")
31+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims"
32+
COMPONENT SwiftCore_development)
3233

3334
add_library(swiftShims INTERFACE)
3435
target_include_directories(swiftShims INTERFACE
35-
$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}/../../>
36-
$<$<COMPILE_LANGUAGE:Swift>:${CMAKE_CURRENT_SOURCE_DIR}>)
36+
$<$<COMPILE_LANGUAGE:C,CXX>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}>>
37+
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/swift/shims>>)
3738
target_compile_definitions(swiftShims INTERFACE
3839
$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:C,CXX>>:SWIFT_STATIC_STDLIB>)
3940
target_compile_options(swiftShims INTERFACE
4041
"$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DSWIFT_STATIC_STDLIB>"
41-
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>")
42+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/swift/shims/module.modulemap>>")
43+
44+
install(TARGETS swiftShims
45+
EXPORT SwiftCoreTargets
46+
COMPONENT SwiftCore_development)

Runtimes/Core/Threading/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ target_link_libraries(swiftThreading PRIVATE swiftShims)
1313
# to avoid pulling in headers from the compiler.
1414
target_include_directories(swiftThreading PRIVATE
1515
"${SwiftCore_SWIFTC_SOURCE_DIR}/include")
16+
17+
if(NOT BUILD_SHARED_LIBS)
18+
install(TARGETS swiftThreading
19+
EXPORT SwiftCoreTargets
20+
COMPONENT SwiftCore_runtime)
21+
endif()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@PACKAGE_INIT@
2+
include("${CMAKE_CURRENT_LIST_DIR}/SwiftCoreTargets.cmake")
3+
4+
set(SwiftCore_ENABLE_LIBRARY_EVOLUTION @SwiftCore_ENABLE_LIBRARY_EVOLUTION@)
5+
6+
set(SwiftCore_ENABLE_VECTOR_TYPES @SwiftCore_ENABLE_VECTOR_TYPES@)

Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,36 @@ function(install_swift_interface target)
3838
# Install binary swift modules
3939
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
4040
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftmodule"
41-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
41+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
42+
COMPONENT SwiftCore_development)
4243
if(SwiftCore_VARIANT_MODULE_TRIPLE)
4344
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftmodule"
4445
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftmodule"
45-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
46+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
47+
COMPONENT SwiftCore_development)
4648
endif()
4749

4850
# Install Swift interfaces if library-evolution is enabled
4951
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
5052
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface"
5153
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftinterface"
52-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
53-
54+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
55+
COMPONENT SwiftCore_development)
5456
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface"
5557
RENAME "${SwiftCore_MODULE_TRIPLE}.private.swiftinterface"
56-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
58+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
59+
COMPONENT SwiftCore_development)
5760

5861
# Install catalyst interface files
5962
if(SwiftCore_VARIANT_MODULE_TRIPLE)
6063
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftinterface"
6164
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface"
62-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
65+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
66+
COMPONENT SwiftCore_development)
6367
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.private.swiftinterface"
6468
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface"
65-
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
69+
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
70+
COMPONENT SwiftCore_development)
6671
endif()
6772
endif()
6873
endfunction()

Runtimes/Core/core/CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,13 @@ if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
291291
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-partial-specialization>")
292292
endif()
293293

294-
target_compile_definitions(swiftCore PRIVATE
295-
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
296-
$<$<BOOL:${SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS}>:-DSWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER>
297-
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftCore>)
294+
target_compile_definitions(swiftCore
295+
PRIVATE
296+
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
297+
$<$<BOOL:${SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS}>:-DSWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER>
298+
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftCore>
299+
INTERFACE
300+
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>)
298301
target_compile_options(swiftCore PRIVATE
299302
"$<$<AND:$<BOOL:${BUILD_SHARED_LIBS}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DswiftCore_EXPORTS>")
300303

@@ -303,10 +306,11 @@ target_link_libraries(swiftCore
303306
swiftRuntime
304307
swiftLLVMSupport
305308
swiftDemangling
306-
swiftShims
307309
swiftStdlibStubs
308310
swiftThreading
309-
$<$<NOT:$<PLATFORM_ID:Darwin>>:swiftrt$<$<PLATFORM_ID:Windows>:T>>)
311+
$<$<NOT:$<PLATFORM_ID:Darwin>>:swiftrt$<$<PLATFORM_ID:Windows>:T>>
312+
PUBLIC
313+
swiftShims)
310314
target_link_options(swiftCore PRIVATE
311315
-nostartfiles)
312316
if(NOT POLICY CMP0157)
@@ -324,6 +328,8 @@ if(NOT ANDROID AND NOT APPLE AND NOT LINUX AND NOT WIN32 AND UNIX)
324328
endif()
325329

326330
install(TARGETS swiftCore
331+
EXPORT SwiftCoreTargets
332+
COMPONENT SwiftCore_runtime
327333
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
328334
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
329335
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")

Runtimes/Core/runtime/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ target_compile_definitions(swiftRuntime
102102
$<$<BOOL:${SwiftCore_ENABLE_FILESYSTEM_SUPPORT}>:-DSWIFT_LIB_SUBDIR="${SwiftCore_PLATFORM_SUBDIR}">
103103
$<$<BOOL:${SwiftCore_ENABLE_FATALERROR_BACKTRACE}>:-DSWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING>
104104
PUBLIC
105+
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>
105106
$<$<BOOL:${SwiftCore_ENABLE_OS_TRACE_LAZY_INIT}>:-DSWIFT_USE_OS_TRACE_LAZY_INIT>)
106107

107108
target_include_directories(swiftRuntime PRIVATE
@@ -142,6 +143,12 @@ if(SwiftCore_ENABLE_OBJC_INTEROP)
142143
ObjCRuntimeGetImageNameFromClass.mm)
143144
endif()
144145

146+
if(NOT BUILD_SHARED_LIBS)
147+
install(TARGETS swiftRuntime
148+
EXPORT SwiftCoreTargets
149+
COMPONENT SwiftCore_runtime)
150+
endif()
151+
145152
string(TOLOWER "${SwiftCore_OBJECT_FORMAT}x" SwiftCore_OBJECT_FORMAT)
146153
if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
147154
add_library(swiftrt OBJECT SwiftRT-ELF-WASM.cpp)
@@ -154,6 +161,7 @@ if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
154161
# The driver requires that swifrt.o is under `usr/lib/swift/<platform>/<arch>`
155162
# Regardless of settings
156163
install(FILES $<TARGET_OBJECTS:swiftrt>
164+
COMPONENT SwiftCore_runtime
157165
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
158166
RENAME swiftrt.o)
159167
elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
@@ -168,6 +176,7 @@ elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
168176
add_library(swiftrt OBJECT SwiftRT-COFF.cpp)
169177
target_link_libraries(swiftrt PRIVATE swiftShims)
170178
install(FILES $<TARGET_OBJECTS:swiftrt>
179+
COMPONENT SwiftCore_runtime
171180
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
172181
RENAME swiftrt.obj)
173182
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")

Runtimes/Core/stubs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,9 @@ if(APPLE)
5858
APPEND_STRING
5959
PROPERTY COMPILE_FLAGS "-fobjc-arc")
6060
endif()
61+
62+
if(NOT BUILD_SHARED_LIBS)
63+
install(TARGETS swiftStdlibStubs
64+
EXPORT SwiftCoreTargets
65+
COMPONENT SwiftCore_runtime)
66+
endif()

0 commit comments

Comments
 (0)