From c65980862675e90abebf9bd752338db20af012ad Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Wed, 30 Jul 2025 16:25:13 -0700 Subject: [PATCH] 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 --- Source/cmNinjaNormalTargetGenerator.cxx | 3 ++- Tests/RunCMake/Swift/C.c | 0 Tests/RunCMake/Swift/MultiLangChain.cmake | 10 ++++++++++ Tests/RunCMake/Swift/RunCMakeTest.cmake | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Tests/RunCMake/Swift/C.c create mode 100644 Tests/RunCMake/Swift/MultiLangChain.cmake diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 99bc91a8c4..af18d21708 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -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()) { diff --git a/Tests/RunCMake/Swift/C.c b/Tests/RunCMake/Swift/C.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/RunCMake/Swift/MultiLangChain.cmake b/Tests/RunCMake/Swift/MultiLangChain.cmake new file mode 100644 index 0000000000..f8dccc9d8e --- /dev/null +++ b/Tests/RunCMake/Swift/MultiLangChain.cmake @@ -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) diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index 63ad2323b7..bab92309a1 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -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)