Skip to content

Commit b889bcf

Browse files
[WASM] Embed .swiftmodulesummary and .sib in toolchain
1 parent d10f353 commit b889bcf

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

cmake/caches/Runtime-WASI-wasm32.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ set(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY NO CACHE BOOL "")
2222
# TODO(katei): This should get turned off, as this is not an ABI stable platform.
2323
# But current CMake build system doesn't support SWIFT_STDLIB_STABLE_ABI=NO
2424
set(SWIFT_STDLIB_STABLE_ABI YES CACHE BOOL "")
25+
set(SWIFT_STDLIB_ENABLE_THINCMO YES CACHE BOOL "")
2526

2627
# build with the host compiler
2728
set(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER YES CACHE BOOL "")

stdlib/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ option(SWIFT_ENABLE_MODULE_INTERFACES
5959
"Generate .swiftinterface files alongside .swiftmodule files"
6060
"${SWIFT_STDLIB_STABLE_ABI}")
6161

62+
option(SWIFT_STDLIB_ENABLE_THINCMO
63+
"Generate .swiftmodulesummary and .sib files alongside .swiftmodule files for thin cross module optimization"
64+
FALSE)
65+
6266
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
6367
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
6468
TRUE)

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,28 @@ function(_compile_swift_files
806806
${copy_legacy_layouts_dep}
807807
COMMENT "Generating ${module_file}")
808808

809+
set(modulesummary_file "${module_base}.swiftmodulesummary")
810+
set(modulesummary_file_static "${module_base_static}.swiftmodulesummary")
811+
set(thincmo_sib_file "${module_base}.sib")
812+
set(thincmo_sib_file_static "${module_base_static}.sib")
813+
if(SWIFT_STDLIB_ENABLE_THINCMO)
814+
add_custom_command_target(
815+
thincmo_intermediate_target
816+
COMMAND
817+
"$<TARGET_FILE:Python3::Interpreter>" "${line_directive_tool}" "@${file_path}" --
818+
"${swift_compiler_tool}" "-emit-sib" "-o" "${thincmo_sib_file}"
819+
${swift_flags} "-emit-module-summary" "@${file_path}"
820+
OUTPUT "${modulesummary_file}" "${thincmo_sib_file}"
821+
DEPENDS
822+
${swift_compiler_tool_dep}
823+
${source_files} ${SWIFTFILE_DEPENDS}
824+
${swift_ide_test_dependency}
825+
${create_dirs_dependency_target}
826+
${copy_legacy_layouts_dep}
827+
${module_dependency_target}
828+
COMMENT "Generating ${modulesummary_file}")
829+
endif()
830+
809831
if(SWIFTFILE_STATIC)
810832
add_custom_command_target(
811833
module_dependency_target_static
@@ -823,8 +845,22 @@ function(_compile_swift_files
823845
"${module_dependency_target}"
824846
COMMENT "Generating ${module_file}")
825847
set("${dependency_module_target_out_var_name}" "${module_dependency_target_static}" PARENT_SCOPE)
848+
849+
if(SWIFT_STDLIB_ENABLE_THINCMO)
850+
add_custom_command_target(
851+
thincmo_intermediate_target_static
852+
COMMAND
853+
"${CMAKE_COMMAND}" "-E" "copy" ${modulesummary_file} ${modulesummary_file_static}
854+
COMMAND
855+
"${CMAKE_COMMAND}" "-E" "copy" ${thincmo_sib_file} ${thincmo_sib_file_static}
856+
OUTPUT ${modulesummary_file_static}
857+
DEPENDS
858+
"${thincmo_intermediate_target}" "${module_dependency_target_static}"
859+
COMMENT "Generating ${modulesummary_file_static}")
860+
set("${dependency_module_target_out_var_name}" "${module_dependency_target_static}" "${thincmo_intermediate_target_static}" PARENT_SCOPE)
861+
endif()
826862
else()
827-
set("${dependency_module_target_out_var_name}" "${module_dependency_target}" PARENT_SCOPE)
863+
set("${dependency_module_target_out_var_name}" "${module_dependency_target}" "${thincmo_intermediate_target}" PARENT_SCOPE)
828864
endif()
829865

830866
# macCatalyst zippered swiftmodule

0 commit comments

Comments
 (0)