Swift: Ninja: Remove module dependency for executables
We shouldn't include the swiftmodule in the ninja dependency graph unless that target emits a swiftmodule. Fixes: #25869
This commit is contained in:
parent
5fc6d6165c
commit
579472d877
@ -2016,11 +2016,21 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
|
|||||||
this->LocalGenerator->AppendFlags(vars["FLAGS"], "-static");
|
this->LocalGenerator->AppendFlags(vars["FLAGS"], "-static");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Does this swift target emit a module file for importing into other
|
||||||
|
// targets?
|
||||||
|
auto isImportableTarget = [](cmGeneratorTarget const& tgt) -> bool {
|
||||||
|
// Everything except for executables that don't export anything should emit
|
||||||
|
// some way to import them.
|
||||||
|
if (tgt.GetType() == cmStateEnums::EXECUTABLE) {
|
||||||
|
return tgt.IsExecutableWithExports();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
// Swift modules only make sense to emit from things that can be imported.
|
// Swift modules only make sense to emit from things that can be imported.
|
||||||
// Executables that don't export symbols can't be imported, so don't try to
|
// Executables that don't export symbols can't be imported, so don't try to
|
||||||
// emit a swiftmodule for them. It will break.
|
// emit a swiftmodule for them. It will break.
|
||||||
if (target.GetType() != cmStateEnums::EXECUTABLE ||
|
if (isImportableTarget(target)) {
|
||||||
target.IsExecutableWithExports()) {
|
|
||||||
std::string const emitModuleFlag = "-emit-module";
|
std::string const emitModuleFlag = "-emit-module";
|
||||||
std::string const modulePathFlag = "-emit-module-path";
|
std::string const modulePathFlag = "-emit-module-path";
|
||||||
this->LocalGenerator->AppendFlags(
|
this->LocalGenerator->AppendFlags(
|
||||||
@ -2089,18 +2099,21 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
|
|||||||
if (!dep->IsLanguageUsed("Swift", config)) {
|
if (!dep->IsLanguageUsed("Swift", config)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Add dependencies on the emitted swiftmodule file from swift targets we
|
|
||||||
// depend on
|
// If the dependency emits a swiftmodule, add a dependency edge on that
|
||||||
std::string const depModuleName =
|
// swiftmodule to the ninja build graph.
|
||||||
getTargetPropertyOrDefault(*dep, "Swift_MODULE_NAME", dep->GetName());
|
if (isImportableTarget(*dep)) {
|
||||||
std::string const depModuleDir = getTargetPropertyOrDefault(
|
std::string const depModuleName =
|
||||||
*dep, "Swift_MODULE_DIRECTORY",
|
getTargetPropertyOrDefault(*dep, "Swift_MODULE_NAME", dep->GetName());
|
||||||
dep->LocalGenerator->GetCurrentBinaryDirectory());
|
std::string const depModuleDir = getTargetPropertyOrDefault(
|
||||||
std::string const depModuleFilename = getTargetPropertyOrDefault(
|
*dep, "Swift_MODULE_DIRECTORY",
|
||||||
*dep, "Swift_MODULE", cmStrCat(depModuleName, ".swiftmodule"));
|
dep->LocalGenerator->GetCurrentBinaryDirectory());
|
||||||
std::string const depModuleFilepath =
|
std::string const depModuleFilename = getTargetPropertyOrDefault(
|
||||||
this->ConvertToNinjaPath(cmStrCat(depModuleDir, '/', depModuleFilename));
|
*dep, "Swift_MODULE", cmStrCat(depModuleName, ".swiftmodule"));
|
||||||
objBuild.ImplicitDeps.push_back(depModuleFilepath);
|
std::string const depModuleFilepath = this->ConvertToNinjaPath(
|
||||||
|
cmStrCat(depModuleDir, '/', depModuleFilename));
|
||||||
|
objBuild.ImplicitDeps.push_back(depModuleFilepath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
|
objBuild.OrderOnlyDeps.push_back(this->OrderDependsTargetForTarget(config));
|
||||||
|
@ -50,6 +50,9 @@ if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_GREATER_EQUAL 9.0)
|
|||||||
set_target_properties(O PROPERTIES Swift_COMPILATION_MODE "incremental")
|
set_target_properties(O PROPERTIES Swift_COMPILATION_MODE "incremental")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_library(P L.swift)
|
||||||
|
add_dependencies(P SwiftOnly)
|
||||||
|
|
||||||
# Dummy to make sure generation works with such targets.
|
# Dummy to make sure generation works with such targets.
|
||||||
add_library(SwiftIface INTERFACE)
|
add_library(SwiftIface INTERFACE)
|
||||||
target_link_libraries(SwiftOnly PRIVATE SwiftIface)
|
target_link_libraries(SwiftOnly PRIVATE SwiftIface)
|
||||||
|
Loading…
Reference in New Issue
Block a user