Swift: Fix swiftmodule dependency

Fix a bug in the split build model where we generate a dependency on the
swiftmodule of a target that does not emit a swiftmodule.

This fix drops the erroneous swiftmodule dependency edge, avoiding the
broken dependency graph. Incremental builds still work with the new
model because of the swiftmodule dependency edges between Swift
compilation steps.

Fixes: #26922
This commit is contained in:
Evan Wilde authored and Brad King committed 2025-08-04 10:51:23 -04:00
1 parent 1c3300998f
commit c659808626
4 files changed
+23 -1

No files matched your search

+2 -1
View File
@@ -1578,7 +1578,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
}
// Add dependencies on swiftmodule files when using the swift linker
if (this->TargetLinkLanguage(config) == "Swift") {
if (!this->GetLocalGenerator()->IsSplitSwiftBuild() &&
this->TargetLinkLanguage(config) == "Swift") {
if (cmComputeLinkInformation* cli =
this->GeneratorTarget->GetLinkInformation(config)) {
for (auto const& dependency : cli->GetItems()) {
View File
Whitespace-only changes.
+10
View File
@@ -0,0 +1,10 @@
cmake_policy(SET CMP0157 NEW)
cmake_policy(SET CMP0195 NEW)
enable_language(Swift C)
add_library(L L.swift)
add_library(C C.c)
target_link_libraries(C PRIVATE L)
add_library(E E.swift)
target_link_libraries(E PRIVATE C)
+11
View File
@@ -30,6 +30,17 @@ block()
endif()
endblock()
# Older Xcode versions didn't support Swift static libraries.
if(NOT (RunCMake_GENERATOR STREQUAL "Xcode" AND XCODE_VERSION VERSION_LESS 9.0))
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/MultiLangChain-build)
run_cmake(MultiLangChain)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_command(MultiLangChain-build ${CMAKE_COMMAND} --build .)
endblock()
endif()
if(RunCMake_GENERATOR MATCHES "Ninja.*")
block()
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CMP0195-NEW-build)