Skip to content

CMake: SwiftCore: Directory Swift Modules #80881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

etcwilde
Copy link
Member

@etcwilde etcwilde commented Apr 17, 2025

The catalyst support in the driver requires that the swiftmodules for the catalyst slice live in the swiftmodule directory. CMake currently doesn't do this natively so this patch works around it by specifying the module path explicitly. The use of an empty custom command is used to hook up the dependency graph on the specific target swiftmodule files correctly.

This is only needed for catalyst builds that this time so limit the affect of this change to instances where we are building zippered catalyst binaries.

The nested structure also greatly simplifies the installation story. We simply need to copy the entire swiftmodule directory into the install location.

I'm not enabling this always since it's not clear to me that the dependency edge on the actual binary swiftmodule file is being created consistently. This is fine for clean builds since the swiftmodule directory and swiftmodule file are created in the same invocation, but might break dependency tracking in incremental builds.

This is a workaround until we can use CMP0195 --https://gitlab.kitware.com/cmake/cmake/-/merge_requests/10664

The catalyst support in the driver requires that the swiftmodules for
the catalyst slice live in the swiftmodule directory. CMake currently
doesn't do this natively so this patch works around it by specifying the
module path explicitly. The use of an empty custom command is used to
hook up the dependency graph on the specific target swiftmodule files
correctly.

This is only needed for catalyst builds that this time so limit the
affect of this change to instances where we are building zippered
catalyst binaries.

The nested structure also greatly simplifies the installation story. We
simply need to copy the entire swiftmodule directory into the install
location.
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

DEPENDS ${target})
target_sources(${target}
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>)
endif()

# Generate textual swift interfaces is library-evolution is enabled
if(SwiftCore_ENABLE_LIBRARY_EVOLUTION)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider removing this? The standard library build does emit the textual interface for all targets and the work that Alexis is doing to always use the textual interface.

Comment on lines +34 to +44
if(SwiftCore_VARIANT_MODULE_TRIPLE)
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftinterface>
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.private.swiftinterface>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-private-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface>")
else()
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface>
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface>)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rework this as:

Suggested change
if(SwiftCore_VARIANT_MODULE_TRIPLE)
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftinterface>
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.private.swiftinterface>
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-private-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface>")
else()
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface>
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface>)
endif()
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-emit-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.swiftinterface>
$<$<COMPILE_LANGUAGE:Swift>:-emit-private-module-interface-path$<SEMICOLON>${CMAKE_CURRENT_BINARY_DIR}/$<TARGET_PROPERTY:${target},Swift_MODULE_NAME>.private.swiftinterface>)
if(SwiftCore_VARIANT_MODULE_TRIPLE)
target_compile_options(${target] PRIVATE
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.swiftinterface>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-emit-variant-private-module-interface-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_VARIANT_MODULE_TRIPLE}.private.swiftinterface>")
endif()

@@ -9,63 +9,74 @@ function(emit_swift_interface target)
# Generate the target-variant binary swift module when performing zippered
# build
if(SwiftCore_VARIANT_MODULE_TRIPLE)
set(variant_module_tmp_dir "${CMAKE_CURRENT_BINARY_DIR}/${target}-${SwiftCore_VARIANT_MODULE_TRIPLE}")
file(MAKE_DIRECTORY "${variant_module_tmp_dir}")
# Clean this up once CMake has nested swiftmodules in the build directory:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does make some complexity. We already have to have the custom handling here, why not consider doing this unconditionally and always generating the thick module layout?

@etcwilde
Copy link
Member Author

etcwilde commented Jul 3, 2025

#82571 merged. Closing this PR.

@etcwilde etcwilde closed this Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants