@@ -120,6 +120,27 @@ function(_set_pure_swift_profile_flags target_name)
120120 endif ()
121121endfunction ()
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}
0 commit comments