Ninja: Avoid re-linking a Swift executable on every build

Swift doesn't emit swiftmodules for executables, so we shouldn't put it
in dependency graph.  Ninja sees the "missing" dependency and always
tries to rebuild/re-link the target.
This commit is contained in:
Evan Wilde
2022-11-11 09:59:59 -08:00
committed by Brad King
parent 0c71f3c943
commit 38c8807c5a
5 changed files with 16 additions and 1 deletions

View File

@@ -1112,7 +1112,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
this->GetObjectFilePath(source, config));
}
}
linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
if (targetType != cmStateEnums::EXECUTABLE) {
linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
}
} else {
linkBuild.ExplicitDeps = this->GetObjects(config);
}

View File

@@ -0,0 +1 @@
^ninja: no work to do

View File

@@ -0,0 +1,2 @@
enable_language(Swift)
add_executable(hello hello.swift)

View File

@@ -14,6 +14,16 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja)
run_cmake(SwiftMultiArch)
unset(RunCMake_TEST_OPTIONS)
endif()
# Test that a second build with no changes does nothing.
block()
run_cmake(NoWorkToDo)
set(RunCMake_TEST_NO_CLEAN 1)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/NoWorkToDo-build)
set(RunCMake_TEST_OUTPUT_MERGE 1)
run_cmake_command(NoWorkToDo-build ${CMAKE_COMMAND} --build .)
run_cmake_command(NoWorkToDo-nowork ${CMAKE_COMMAND} --build . -- -d explain)
endblock()
endif()
elseif(RunCMake_GENERATOR STREQUAL "Ninja Multi-Config")
if(CMAKE_Swift_COMPILER)

View File