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
2025-07-30 16:25:13 -07:00
committed by Brad King
parent 1c3300998f
commit c659808626
4 changed files with 23 additions and 1 deletions

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()) {

0
Tests/RunCMake/Swift/C.c Normal file
View File

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)

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)