From 69f5db11f4140ec92b4a7812c9a11382a0816f6d Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Sat, 14 Oct 2023 06:17:40 +0000 Subject: [PATCH] [CMake] Add option to specify '-module-abi-name' Add 'SWIFT_MODULE_ABI_NAME_PREFIX' CMake variable. This can be used from compiler's CMake so its swift-syntax libraries can have unique names. That avoids symbol name conflicts when compiler libraries (e.g. sourcekitdInProc) is used from binaries linking with swift-syntax (e.g. via SwiftPM) https://github.com/apple/swift/issues/68812 rdar://116951101 --- CMakeLists.txt | 2 ++ cmake/modules/AddSwiftHostLibrary.cmake | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b2cf7ad094..928f3a2b8a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,8 @@ if(CMAKE_VERSION VERSION_LESS 3.21) endif() endif() +set(SWIFT_MODULE_ABI_NAME_PREFIX CACHE STRING "ABI name prefix to avoid name conflicts") + # The subdirectory into which host libraries will be installed. set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host") diff --git a/cmake/modules/AddSwiftHostLibrary.cmake b/cmake/modules/AddSwiftHostLibrary.cmake index 7a4d22e47d7..e8e6e4c717b 100644 --- a/cmake/modules/AddSwiftHostLibrary.cmake +++ b/cmake/modules/AddSwiftHostLibrary.cmake @@ -77,7 +77,14 @@ function(add_swift_syntax_library name) -emit-module-path;${module_file}; -emit-module-source-info-path;${module_sourceinfo_file}; -emit-module-interface-path;${module_interface_file} + >) + if(SWIFT_MODULE_ABI_NAME_PREFIX) + target_compile_options("${name}" PRIVATE + $<$: + "SHELL:-Xfrontend -module-abi-name" + "SHELL:-Xfrontend ${SWIFT_MODULE_ABI_NAME_PREFIX}${name}" >) + endif() if(CMAKE_VERSION VERSION_LESS 3.26.0 AND SWIFT_SYNTAX_ENABLE_WMO_PRE_3_26) target_compile_options(${name} PRIVATE