Skip to content

CMake: SwiftCore Install Story #79548

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Runtimes/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ add_compile_definitions(
$<$<BOOL:${SwiftCore_ENABLE_OBJC_INTEROP}>:-DSWIFT_OBJC_INTEROP>
$<$<BOOL:${SwiftCore_ENABLE_LIBRARY_EVOLUTION}>:-DSWIFT_LIBRARY_EVOLUTION>
$<$<BOOL:${SwiftCore_ENABLE_CRASH_REPORTER_CLIENT}>:-DSWIFT_HAVE_CRASHREPORTERCLIENT>
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To double check my understanding: are we pushing this setting to runtime and core because those are the only artifacts for which it makes sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it to the public interface of runtime so that it affects runtime and anything that links against it. The issue is that runtime is privately linked into core, so the macro won't get carried out to products that link against swiftCore externally.

Then I made it part of the INTERFACE of swiftCore. It doesn't get re-applied to swiftCore, but is forwarded to anything that links against swiftCore using the config file. This means that the overlays and supplemental libraries that are using this config file will also get the flag set without needing to do anything.

$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
$<$<BOOL:${SwiftCore_ENABLE_RUNTIME_FUNCTION_COUNTERS}>:-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS>
$<$<BOOL:${SwiftCore_ENABLE_STDIN}>:-DSWIFT_STDLIB_HAS_STDIN> # core + stubs
Expand Down Expand Up @@ -225,3 +224,22 @@ endif()
if(SwiftCore_ENABLE_CONCURRENCY)
add_subdirectory(Concurrency)
endif()

# Inter-project install info
export(EXPORT SwiftCoreTargets
FILE "cmake/SwiftCore/SwiftCoreTargets.cmake")
install(EXPORT SwiftCoreTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore"
FILE "SwiftCoreTargets.cmake"
COMPONENT SwiftCore_cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/interface/SwiftCoreConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY ExactVersion)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftCoreConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SwiftCore")
4 changes: 3 additions & 1 deletion Runtimes/Core/CommandLineSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ if(SwiftCore_ENABLE_COMMANDLINE_SUPPORT)
swiftShims)

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftCommandLineSupport)
install(TARGETS swiftCommandLineSupport
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()
endif()
2 changes: 2 additions & 0 deletions Runtimes/Core/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ set_target_properties(swift_Concurrency PROPERTIES
Swift_MODULE_NAME _Concurrency)

install(TARGETS swift_Concurrency
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
Expand Down
4 changes: 3 additions & 1 deletion Runtimes/Core/Demangling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ if(LINUX OR BSD)
endif()

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftDemangling)
install(TARGETS swiftDemangling
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()
6 changes: 6 additions & 0 deletions Runtimes/Core/LLVMSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ add_library(swiftLLVMSupport OBJECT
target_compile_options(swiftLLVMSupport
PRIVATE
$<$<BOOL:${SwiftCore_HAS_ASL}>:-DSWIFT_STDLIB_HAS_ASL>)

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftLLVMSupport
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()
2 changes: 2 additions & 0 deletions Runtimes/Core/SwiftOnoneSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ target_link_libraries(swiftSwiftOnoneSupport
swiftCore)

install(TARGETS swiftSwiftOnoneSupport
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
Expand Down
13 changes: 9 additions & 4 deletions Runtimes/Core/SwiftShims/swift/shims/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ install(FILES
_SwiftDistributed.h
_SynchronizationShims.h
module.modulemap
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims")
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/shims"
COMPONENT SwiftCore_development)

add_library(swiftShims INTERFACE)
target_include_directories(swiftShims INTERFACE
$<$<COMPILE_LANGUAGE:C,CXX>:${CMAKE_CURRENT_SOURCE_DIR}/../../>
$<$<COMPILE_LANGUAGE:Swift>:${CMAKE_CURRENT_SOURCE_DIR}>)
$<$<COMPILE_LANGUAGE:C,CXX>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}>>
$<$<COMPILE_LANGUAGE:Swift>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_LIBDIR}/swift/shims>>)
target_compile_definitions(swiftShims INTERFACE
$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:C,CXX>>:SWIFT_STATIC_STDLIB>)
target_compile_options(swiftShims INTERFACE
"$<$<AND:$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DSWIFT_STATIC_STDLIB>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -fmodule-map-file=${CMAKE_CURRENT_SOURCE_DIR}/module.modulemap>")
"$<$<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>>")

install(TARGETS swiftShims
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_development)
6 changes: 6 additions & 0 deletions Runtimes/Core/Threading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ target_link_libraries(swiftThreading PRIVATE swiftShims)
# to avoid pulling in headers from the compiler.
target_include_directories(swiftThreading PRIVATE
"${SwiftCore_SWIFTC_SOURCE_DIR}/include")

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftThreading
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()
6 changes: 6 additions & 0 deletions Runtimes/Core/cmake/interface/SwiftCoreConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/SwiftCoreTargets.cmake")

set(SwiftCore_ENABLE_LIBRARY_EVOLUTION @SwiftCore_ENABLE_LIBRARY_EVOLUTION@)

set(SwiftCore_ENABLE_VECTOR_TYPES @SwiftCore_ENABLE_VECTOR_TYPES@)
19 changes: 12 additions & 7 deletions Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,36 @@ function(install_swift_interface target)
# Install binary swift modules
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftmodule"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)
if(SwiftCore_VARIANT_MODULE_TRIPLE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftmodule"
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftmodule"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)
endif()

# Install Swift interfaces if library-evolution is enabled
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface"
RENAME "${SwiftCore_MODULE_TRIPLE}.swiftinterface"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")

DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface"
RENAME "${SwiftCore_MODULE_TRIPLE}.private.swiftinterface"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)

# Install catalyst interface files
if(SwiftCore_VARIANT_MODULE_TRIPLE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.swiftinterface"
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}/${target}.private.swiftinterface"
RENAME "${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface"
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule")
DESTINATION "${SwiftCore_INSTALL_SWIFTMODULEDIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftmodule"
COMPONENT SwiftCore_development)
endif()
endif()
endfunction()
18 changes: 12 additions & 6 deletions Runtimes/Core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@ if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xllvm -sil-partial-specialization>")
endif()

target_compile_definitions(swiftCore PRIVATE
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
$<$<BOOL:${SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS}>:-DSWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER>
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftCore>)
target_compile_definitions(swiftCore
PRIVATE
$<$<BOOL:${SwiftCore_ENABLE_REFLECTION}>:-DSWIFT_ENABLE_REFLECTION>
$<$<BOOL:${SwiftCore_ENABLE_COMPACT_ABSOLUTE_FUNCTION_POINTERS}>:-DSWIFT_COMPACT_ABSOLUTE_FUNCTION_POINTER>
$<$<COMPILE_LANGUAGE:C,CXX>:-DSWIFT_TARGET_LIBRARY_NAME=swiftCore>
INTERFACE
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>)
target_compile_options(swiftCore PRIVATE
"$<$<AND:$<BOOL:${BUILD_SHARED_LIBS}>,$<COMPILE_LANGUAGE:Swift>>:SHELL:-Xcc -DswiftCore_EXPORTS>")

Expand All @@ -303,10 +306,11 @@ target_link_libraries(swiftCore
swiftRuntime
swiftLLVMSupport
swiftDemangling
swiftShims
swiftStdlibStubs
swiftThreading
$<$<NOT:$<PLATFORM_ID:Darwin>>:swiftrt$<$<PLATFORM_ID:Windows>:T>>)
$<$<NOT:$<PLATFORM_ID:Darwin>>:swiftrt$<$<PLATFORM_ID:Windows>:T>>
PUBLIC
swiftShims)
target_link_options(swiftCore PRIVATE
-nostartfiles)
if(NOT POLICY CMP0157)
Expand All @@ -324,6 +328,8 @@ if(NOT ANDROID AND NOT APPLE AND NOT LINUX AND NOT WIN32 AND UNIX)
endif()

install(TARGETS swiftCore
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime
ARCHIVE DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${SwiftCore_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
Expand Down
9 changes: 9 additions & 0 deletions Runtimes/Core/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ target_compile_definitions(swiftRuntime
$<$<BOOL:${SwiftCore_ENABLE_FILESYSTEM_SUPPORT}>:-DSWIFT_LIB_SUBDIR="${SwiftCore_PLATFORM_SUBDIR}">
$<$<BOOL:${SwiftCore_ENABLE_FATALERROR_BACKTRACE}>:-DSWIFT_STDLIB_SUPPORTS_BACKTRACE_REPORTING>
PUBLIC
$<$<BOOL:${SwiftCore_ENABLE_VECTOR_TYPES}>:-DSWIFT_STDLIB_ENABLE_VECTOR_TYPES>
$<$<BOOL:${SwiftCore_ENABLE_OS_TRACE_LAZY_INIT}>:-DSWIFT_USE_OS_TRACE_LAZY_INIT>)

target_include_directories(swiftRuntime PRIVATE
Expand Down Expand Up @@ -142,6 +143,12 @@ if(SwiftCore_ENABLE_OBJC_INTEROP)
ObjCRuntimeGetImageNameFromClass.mm)
endif()

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftRuntime
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()

string(TOLOWER "${SwiftCore_OBJECT_FORMAT}x" SwiftCore_OBJECT_FORMAT)
if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
add_library(swiftrt OBJECT SwiftRT-ELF-WASM.cpp)
Expand All @@ -154,6 +161,7 @@ if("${SwiftCore_OBJECT_FORMAT}" STREQUAL "elfx")
# The driver requires that swifrt.o is under `usr/lib/swift/<platform>/<arch>`
# Regardless of settings
install(FILES $<TARGET_OBJECTS:swiftrt>
COMPONENT SwiftCore_runtime
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
RENAME swiftrt.o)
elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
Expand All @@ -168,6 +176,7 @@ elseif("${SwiftCore_OBJECT_FORMAT}" STREQUAL "coffx")
add_library(swiftrt OBJECT SwiftRT-COFF.cpp)
target_link_libraries(swiftrt PRIVATE swiftShims)
install(FILES $<TARGET_OBJECTS:swiftrt>
COMPONENT SwiftCore_runtime
DESTINATION "${CMAKE_INSTALL_LIBDIR}/swift/${SwiftCore_PLATFORM_SUBDIR}/${SwiftCore_ARCH_SUBDIR}"
RENAME swiftrt.obj)
elseif(NOT "${SwiftCore_OBJECT_FORMAT}" STREQUAL "x")
Expand Down
6 changes: 6 additions & 0 deletions Runtimes/Core/stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ if(APPLE)
APPEND_STRING
PROPERTY COMPILE_FLAGS "-fobjc-arc")
endif()

if(NOT BUILD_SHARED_LIBS)
install(TARGETS swiftStdlibStubs
EXPORT SwiftCoreTargets
COMPONENT SwiftCore_runtime)
endif()