From a6a5c433005be3cceab05f088dbd8fe8ffce3540 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Thu, 21 Dec 2023 10:26:38 -0800 Subject: Swift/Ninja: Add support for response files Adding support for `CMAKE_NINJA_FORCE_RESPONSE_FILE` with Swift. Issue: #25490 Fixes: #25563 --- Modules/CMakeSwiftInformation.cmake | 1 + Source/cmNinjaNormalTargetGenerator.cxx | 6 ++++-- Source/cmNinjaTargetGenerator.cxx | 4 +++- Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt | 4 ++++ Tests/RunCMake/Swift/ForceResponseFile.cmake | 13 +++++++++++++ Tests/RunCMake/Swift/RunCMakeTest.cmake | 7 +++++++ 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt create mode 100644 Tests/RunCMake/Swift/ForceResponseFile.cmake diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 04d500e..7a1c64a 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -56,6 +56,7 @@ set(CMAKE_Swift_LIBRARY_PATH_TERMINATOR "") set(CMAKE_Swift_LINK_LIBRARY_FLAG "-l") set(CMAKE_Swift_LINKER_WRAPPER_FLAG "-Xlinker" " ") set(CMAKE_Swift_RESPONSE_FILE_LINK_FLAG @) +set(CMAKE_Swift_RESPONSE_FILE_FLAG @) set(CMAKE_Swift_LINKER_PREFERENCE 50) set(CMAKE_Swift_LINKER_PREFERENCE_PROPAGATES 1) diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 99ea009..d365ef6 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -453,7 +453,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile, vars.Language = lang.c_str(); vars.AIXExports = "$AIX_EXPORTS"; - if (this->TargetLinkLanguage(config) == "Swift") { + if (!this->GetLocalGenerator()->IsSplitSwiftBuild() && + this->TargetLinkLanguage(config) == "Swift") { vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME"; vars.SwiftModule = "$SWIFT_MODULE"; vars.SwiftModuleName = "$SWIFT_MODULE_NAME"; @@ -508,7 +509,8 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile, vars.LinkLibraries = "$LINK_PATH $LINK_LIBRARIES"; } - if (this->TargetLinkLanguage(config) == "Swift") { + if (!this->GetLocalGenerator()->IsSplitSwiftBuild() && + this->TargetLinkLanguage(config) == "Swift") { vars.SwiftSources = responseFlag.c_str(); } else { vars.Objects = responseFlag.c_str(); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index bc75a95..7b08865 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -2017,6 +2017,7 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement( std::string const targetObjectFilename = this->ConvertToNinjaPath(cmStrCat( objectDir, '/', moduleName, this->GetGlobalGenerator()->GetLanguageOutputExtension(language))); + objBuild.RspFile = cmStrCat(targetObjectFilename, ".swift.rsp"); if (isSingleOutput) { this->LocalGenerator->AppendFlags(vars["FLAGS"], @@ -2076,7 +2077,8 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement( // Write object build this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), - objBuild); + objBuild, + this->ForceResponseFile() ? -1 : 0); } void cmNinjaTargetGenerator::WriteTargetDependInfo(std::string const& lang, diff --git a/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt b/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt new file mode 100644 index 0000000..576f5a1 --- /dev/null +++ b/Tests/RunCMake/Swift/ForceResponseFile-check-stdout.txt @@ -0,0 +1,4 @@ +swiftc [^ +]* -c @CMakeFiles/L.dir/L.o.swift.rsp [^ +]* +.*swiftc -emit-library -static -o libL.a @CMakeFiles/L.rsp.* diff --git a/Tests/RunCMake/Swift/ForceResponseFile.cmake b/Tests/RunCMake/Swift/ForceResponseFile.cmake new file mode 100644 index 0000000..7fd4636 --- /dev/null +++ b/Tests/RunCMake/Swift/ForceResponseFile.cmake @@ -0,0 +1,13 @@ +if(POLICY CMP0157) + cmake_policy(SET CMP0157 NEW) +endif() + +if(NOT CMAKE_GENERATOR STREQUAL "Ninja") + message(SEND_ERROR "this test must use Ninja generator, found ${CMAKE_GENERATOR} ") +endif() + +set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE) + +enable_language(Swift) + +add_library(L STATIC L.swift) diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index f0ad0bd..5de4346 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -69,6 +69,13 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja) run_cmake(CompileCommands) run_cmake_command(CompileCommands-check ${CMAKE_COMMAND} --build ${CompileCommands_TEST_BINARY_DIR}) endblock() + + block() + set(ForceResponseFile_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ForceResponseFile-build) + run_cmake(ForceResponseFile) + # -v: verbose to capture executed commands -n: dry-run to avoid actually compiling + run_cmake_command(ForceResponseFile-check ${CMAKE_COMMAND} --build ${ForceResponseFile_TEST_BINARY_DIR} -- -vn) + endblock() endif() elseif(RunCMake_GENERATOR STREQUAL "Ninja Multi-Config") if(CMake_TEST_Swift) -- cgit v0.12