Skip to content

Commit 3e7fa6b

Browse files
authored
Merge pull request #75355 from rintaro/6.0-swiftsyntax-package-cmo
[6.0][SwiftSyntax] Enable Package CMO if possible
2 parents 3a9161c + 821be0c commit 3e7fa6b

File tree

7 files changed

+80
-25
lines changed

7 files changed

+80
-25
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,18 @@ include(CheckSymbolExists)
9393
include(CMakeDependentOption)
9494
include(CheckLanguage)
9595
include(GNUInstallDirs)
96-
include(SwiftImplicitImport)
96+
include(SwiftCompilerCapability)
9797
include(FetchContent)
9898

9999
# Enable Swift for the host compiler build if we have the language. It is
100100
# optional until we have a bootstrap story.
101101
check_language(Swift)
102102
if(CMAKE_Swift_COMPILER)
103+
# we are not interested in logging any Swift module used
104+
# when configuring the build system -- those are not useful
105+
# since they will not contribute to the build of the compiler itself
106+
unset(ENV{SWIFT_LOADED_MODULE_TRACE_FILE})
107+
103108
enable_language(Swift)
104109
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION "${CMAKE_Swift_COMPILER_VERSION}")
105110
else()
@@ -845,6 +850,10 @@ if (CMAKE_Swift_COMPILER)
845850
swift_supports_implicit_module("backtracing"
846851
SWIFT_SUPPORTS_DISABLE_IMPLICIT_BACKTRACING_MODULE_IMPORT)
847852
message(STATUS " Implicit 'backtracing' import: ${SWIFT_SUPPORTS_DISABLE_IMPLICIT_BACKTRACING_MODULE_IMPORT}")
853+
854+
swift_get_package_cmo_support(
855+
Swift_COMPILER_PACKAGE_CMO_SUPPORT)
856+
message(STATUS " Package CMO: ${Swift_COMPILER_PACKAGE_CMO_SUPPORT}")
848857
else()
849858
message(STATUS "Swift Compiler (None).")
850859
endif()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Test if the Swift compiler returns success for supplied compiler arguments....
2+
function(swift_supports_compiler_arguments out_var)
3+
file(WRITE "${CMAKE_BINARY_DIR}/tmp/dummy.swift" "")
4+
execute_process(
5+
COMMAND "${CMAKE_Swift_COMPILER}" -parse ${ARGN} -
6+
INPUT_FILE "${CMAKE_BINARY_DIR}/tmp/dummy.swift"
7+
OUTPUT_QUIET ERROR_QUIET
8+
RESULT_VARIABLE result
9+
)
10+
if(NOT result)
11+
set("${out_var}" "TRUE" PARENT_SCOPE)
12+
else()
13+
set("${out_var}" "FALSE" PARENT_SCOPE)
14+
endif()
15+
endfunction()
16+
17+
# Test if the Swift compiler supports -disable-implicit-<module>-module-import.
18+
macro(swift_supports_implicit_module module_name out_var)
19+
swift_supports_compiler_arguments(${out_var}
20+
-Xfrontend -disable-implicit-${module_name}-module-import
21+
)
22+
endmacro()
23+
24+
# Get "package cross-module-optimization" compiler arguments suitable for the compiler.
25+
function(swift_get_package_cmo_support out_var)
26+
# > 6.0 : Fixed feature.
27+
swift_supports_compiler_arguments(result
28+
-package-name my-package
29+
-Xfrontend -package-cmo
30+
-Xfrontend -allow-non-resilient-access
31+
)
32+
if(result)
33+
set(${out_var} IMPLEMENTED PARENT_SCOPE)
34+
return()
35+
endif()
36+
37+
# == 6.0 : Experimental.
38+
swift_supports_compiler_arguments(result
39+
-package-name my-package
40+
-Xfrontend -experimental-package-cmo
41+
-Xfrontend -experimental-allow-non-resilient-access
42+
-Xfrontend -experimental-package-bypass-resilience
43+
)
44+
if(result)
45+
set(${out_var} EXPERIMENTAL PARENT_SCOPE)
46+
return()
47+
endif()
48+
49+
# < 6.0 : Not supported.
50+
set(${out_var} NO PARENT_SCOPE)
51+
endfunction()

cmake/modules/SwiftImplicitImport.cmake

Lines changed: 0 additions & 23 deletions
This file was deleted.

lib/ASTGen/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ else()
107107
list(APPEND compile_options "-cxx-interoperability-mode=default")
108108
endif()
109109

110+
# FXIME: Importing package-cmo enabled '.swiftmodule' causes compiler crash :(
111+
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT)
112+
list(APPEND compile_options
113+
"SHELL:-Xfrontend -module-load-mode -Xfrontend prefer-interface")
114+
endif()
115+
110116
if(SWIFT_BUILD_SWIFT_SYNTAX)
111117
foreach(target swiftASTGen swiftIDEUtilsBridging)
112118
target_compile_options(${target} PRIVATE ${compile_options})

lib/Macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ function(add_swift_macro_library name)
3737
return()
3838
endif()
3939

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+
4046
# Add rpath to 'lib/{platform}'
4147
file(RELATIVE_PATH relpath_to_lib
4248
"${SWIFT_HOST_PLUGINS_DEST_DIR}"

stdlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ swift_create_stdlib_targets("swift-test-libexec" "" FALSE)
230230

231231
# Check whether the Swift compiler we're using supports
232232
# -disable-implicit-backtracing-module-import
233-
include(SwiftImplicitImport)
233+
include(SwiftCompilerCapability)
234234

235235
swift_supports_implicit_module("backtracing" SWIFT_COMPILER_SUPPORTS_BACKTRACING)
236236

tools/swift-plugin-server/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
77
SwiftCompilerPluginMessageHandling
88
SwiftLibraryPluginProvider
99
)
10+
11+
# FXIME: Importing package-cmo enabled '.swiftmodule' causes compiler crash :(
12+
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT)
13+
target_compile_options(swift-plugin-server PRIVATE
14+
"SHELL:-Xfrontend -module-load-mode -Xfrontend prefer-interface")
15+
endif()
1016
endif()

0 commit comments

Comments
 (0)