From f292e28b84a8df50a8c4523c04f5e9eacc2ee772 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 22 Feb 2024 16:53:50 -0800 Subject: [PATCH] Swift: Ninja: Pass module name to all swift builds Executables that don't export a public API should not emit a swiftmodule, but the swift modulename is observable from within the program, so we should still set the module name on executable builds. Fixes: #25710 --- Source/cmNinjaTargetGenerator.cxx | 6 ++---- .../Swift/SwiftLibraryModuleCommand-check-stdout.txt | 4 +++- Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index a465b084a01..a88d8472362 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -2024,11 +2024,9 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement( this->LocalGenerator->AppendFlags( vars["FLAGS"], { emitModuleFlag, modulePathFlag, moduleFilepath }); objBuild.Outputs.push_back(moduleFilepath); - - std::string const moduleNameFlag = "-module-name"; - this->LocalGenerator->AppendFlags( - vars["FLAGS"], cmStrCat(moduleNameFlag, ' ', moduleName)); } + this->LocalGenerator->AppendFlags(vars["FLAGS"], + cmStrCat("-module-name ", moduleName)); if (target.GetType() != cmStateEnums::EXECUTABLE) { std::string const libraryLinkNameFlag = "-module-link-name"; diff --git a/Tests/RunCMake/Swift/SwiftLibraryModuleCommand-check-stdout.txt b/Tests/RunCMake/Swift/SwiftLibraryModuleCommand-check-stdout.txt index 85767eba547..7e7fc7dee92 100644 --- a/Tests/RunCMake/Swift/SwiftLibraryModuleCommand-check-stdout.txt +++ b/Tests/RunCMake/Swift/SwiftLibraryModuleCommand-check-stdout.txt @@ -1,3 +1,5 @@ .*swiftc(.exe)? .* -parse-as-library -static -emit-module .* -module-name StaticLibrary [^ ]* -.*swiftc(.exe)? .* -parse-as-library -emit-module .* -module-name DynamicLibrary +.*swiftc(.exe)? .* -parse-as-library -emit-module .* -module-name DynamicLibrary [^ +]* +.*swiftc(.exe)? .* -j [0-9]* -num-threads [0-9]* -c -module-name Executable diff --git a/Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake b/Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake index 7127751bd7e..af4aede0b99 100644 --- a/Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake +++ b/Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake @@ -6,3 +6,7 @@ enable_language(Swift) add_library(StaticLibrary STATIC L.swift) add_library(DynamicLibrary SHARED L.swift) +add_executable(Executable E.swift) + +add_dependencies(DynamicLibrary StaticLibrary) +add_dependencies(Executable DynamicLibrary) -- GitLab