Skip to content

Commit 0ad185a

Browse files
authored
Merge pull request #76130 from rintaro/cmake-package-name-toolchain
[CMake] Build macro plugin and plugin servers as a package
2 parents cfd3936 + 3bf75e7 commit 0ad185a

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ function(_set_pure_swift_profile_flags target_name)
120120
endif()
121121
endfunction()
122122

123+
function(_set_pure_swift_package_options target_name package_name)
124+
if(NOT package_name OR NOT Swift_COMPILER_PACKAGE_CMO_SUPPORT)
125+
return()
126+
endif()
127+
128+
# Enable package CMO if possible
129+
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "IMPLEMENTED")
130+
target_compile_options("${target_name}" PRIVATE
131+
"SHELL:-package-name ${package_name}"
132+
"SHELL:-Xfrontend -package-cmo"
133+
"SHELL:-Xfrontend -allow-non-resilient-access"
134+
)
135+
elseif(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "EXPERIMENTAL")
136+
target_compile_options("${target_name}" PRIVATE
137+
"SHELL:-package-name ${package_name}"
138+
"SHELL:-Xfrontend -experimental-package-cmo"
139+
"SHELL:-Xfrontend -experimental-allow-non-resilient-access"
140+
"SHELL:-Xfrontend -experimental-package-bypass-resilience"
141+
)
142+
endif()
143+
endfunction()
123144

124145
# Add a new "pure" Swift host library.
125146
#
@@ -149,6 +170,9 @@ endfunction()
149170
# EMIT_MODULE
150171
# Emit '.swiftmodule' to
151172
#
173+
# PACKAGE_NAME
174+
# Name of the Swift package this library belongs to.
175+
#
152176
# DEPENDENCIES
153177
# Target names to pass target_link_library
154178
#
@@ -169,7 +193,8 @@ function(add_pure_swift_host_library name)
169193
SHARED
170194
STATIC
171195
EMIT_MODULE)
172-
set(single_parameter_options)
196+
set(single_parameter_options
197+
PACKAGE_NAME)
173198
set(multiple_parameter_options
174199
DEPENDENCIES
175200
SWIFT_DEPENDENCIES)
@@ -193,6 +218,7 @@ function(add_pure_swift_host_library name)
193218
# Create the library.
194219
add_library(${name} ${libkind} ${APSHL_SOURCES})
195220
_add_host_swift_compile_options(${name})
221+
_set_pure_swift_package_options(${name} "${APSHL_PACKAGE_NAME}")
196222

197223
set_property(TARGET ${name}
198224
PROPERTY BUILD_WITH_INSTALL_RPATH YES)
@@ -315,6 +341,9 @@ endfunction()
315341
# name
316342
# Name of the tool (e.g., swift-frontend).
317343
#
344+
# PACKAGE_NAME
345+
# Name of the Swift package this executable belongs to.
346+
#
318347
# DEPENDENCIES
319348
# Target names to pass target_link_library
320349
#
@@ -333,7 +362,8 @@ function(add_pure_swift_host_tool name)
333362
# Option handling
334363
set(options)
335364
set(single_parameter_options
336-
SWIFT_COMPONENT)
365+
SWIFT_COMPONENT
366+
PACKAGE_NAME)
337367
set(multiple_parameter_options
338368
DEPENDENCIES
339369
SWIFT_DEPENDENCIES)
@@ -349,6 +379,7 @@ function(add_pure_swift_host_tool name)
349379
add_executable(${name} ${APSHT_SOURCES})
350380
_add_host_swift_compile_options(${name})
351381
_set_pure_swift_link_flags(${name} "../lib/")
382+
_set_pure_swift_package_options(${name} "${APSHT_PACKAGE_NAME}")
352383

353384
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
354385
set_property(TARGET ${name}

lib/Macros/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@ function(add_swift_macro_library name)
2929
set(ASML_SOURCES ${ARGN})
3030

3131
# Add the library.
32-
add_pure_swift_host_library(${name} SHARED ${ASML_SOURCES})
32+
add_pure_swift_host_library(${name} SHARED
33+
PACKAGE_NAME Toolchain
34+
${ASML_SOURCES})
3335

3436
# If we don't have the Swift swift parser, bail out, because the above
3537
# add_pure_swift_host_library did nothing.
3638
if (NOT SWIFT_BUILD_SWIFT_SYNTAX)
3739
return()
3840
endif()
3941

40-
# FXIME: Importing package-cmo enabled '.swiftmodule' causes compiler crash :(
41-
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT)
42-
target_compile_options(${name} PRIVATE
43-
"SHELL:-Xfrontend -module-load-mode -Xfrontend prefer-interface")
44-
endif()
45-
4642
# Add rpath to 'lib/{platform}'
4743
file(RELATIVE_PATH relpath_to_lib
4844
"${SWIFT_HOST_PLUGINS_DEST_DIR}"

lib/SwiftSyntax/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ endif()
1818
# Add unique ABI prefix to swift-syntax libraries so that compiler libraries (e.g. sourcekitdInProc)
1919
# can be used from tools that has its own swift-syntax libraries as SwiftPM dependencies.
2020
set(SWIFT_MODULE_ABI_NAME_PREFIX "Compiler")
21+
set(SWIFTSYNTAX_PACKAGE_NAME "Toolchain")
2122

2223
file(TO_CMAKE_PATH "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}" swift_syntax_path)
2324
FetchContent_Declare(SwiftSyntax SOURCE_DIR "${swift_syntax_path}")

tools/swift-plugin-server/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
66
SWIFT_DEPENDENCIES
77
SwiftCompilerPluginMessageHandling
88
SwiftLibraryPluginProvider
9+
PACKAGE_NAME Toolchain
910
)
1011

1112
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
@@ -15,6 +16,7 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
1516
SWIFT_DEPENDENCIES
1617
SwiftCompilerPluginMessageHandling
1718
SwiftLibraryPluginProvider
19+
PACKAGE_NAME Toolchain
1820
)
1921

2022
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
@@ -28,14 +30,6 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
2830
_set_pure_swift_link_flags(SwiftInProcPluginServer "../../")
2931
endif()
3032

31-
# FXIME: Importing package-cmo enabled '.swiftmodule' causes compiler crash :(
32-
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT)
33-
target_compile_options(swift-plugin-server PRIVATE
34-
"SHELL:-Xfrontend -module-load-mode -Xfrontend prefer-interface")
35-
target_compile_options(SwiftInProcPluginServer PRIVATE
36-
"SHELL:-Xfrontend -module-load-mode -Xfrontend prefer-interface")
37-
endif()
38-
3933
set_property(TARGET ${name}
4034
PROPERTY BUILD_WITH_INSTALL_RPATH YES)
4135

0 commit comments

Comments
 (0)