summaryrefslogtreecommitdiffstats
path: root/Tests/SwiftOnly
diff options
context:
space:
mode:
authorEvan Wilde <etceterawilde@gmail.com>2023-11-22 19:09:35 (GMT)
committerEvan Wilde <etceterawilde@gmail.com>2023-12-15 13:51:13 (GMT)
commit9bed4f4d817f139f0c2e050d7420e1e247949fe4 (patch)
tree5e89c57c5becc55a005b0bdf214e88949e07fe5f /Tests/SwiftOnly
parent64b336784507f7b8c9117cf5367a6abfc78a8ba3 (diff)
downloadCMake-9bed4f4d817f139f0c2e050d7420e1e247949fe4.zip
CMake-9bed4f4d817f139f0c2e050d7420e1e247949fe4.tar.gz
CMake-9bed4f4d817f139f0c2e050d7420e1e247949fe4.tar.bz2
Swift/Ninja: Split compilation model
Splitting the Swift build into an object build and a separate link step, instead of building and linking in one step. The immediate benefit is LSP support because we are able to emit compile-commands for Swift files now. Additionally, it is possible to specify flags to the compile step, enabling folks to emit C and C++ headers from their Swift builds for C/C++ interop, without needing custom commands. Eventually, this gives us a path toward working object libraries. Object Libraries: - Object libraries don't work today because CMake doesn't emit targets for object libraries into the Ninja build file. - tl;dr: Object libraries work if they aren't WMO. Still need work to make WMO'd object libraries work. Object libraries still don't completely work with this patch because, while we emit the targets, the `TARGET_OBJECTS` generator expression expansion has a separate mechanism for determining what the names of the objects are based on the input source files, so targets that depend on an object library built with a whole-module optimization will depend on objects based on the name of the source file instead of the actual emitted object file. These features require being able to accurately model wholemodule builds though, because we actually need to track object files and WMO affects what objects are emitted. For that, we require CMP0157 use the NEW policy. When it's OLD, we have to fall back on the old behavior and cannot provide object libraries or the compile-commands for LSP. Issue: #25308
Diffstat (limited to 'Tests/SwiftOnly')
-rw-r--r--Tests/SwiftOnly/CMakeLists.txt24
-rw-r--r--Tests/SwiftOnly/O.swift0
2 files changed, 16 insertions, 8 deletions
diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt
index 7de1e04..2aa5710 100644
--- a/Tests/SwiftOnly/CMakeLists.txt
+++ b/Tests/SwiftOnly/CMakeLists.txt
@@ -43,6 +43,13 @@ add_library(N N.swift)
target_link_libraries(N PUBLIC
M)
+if(NOT XCODE_VERSION OR XCODE_VERSION VERSION_GREATER_EQUAL 9.0)
+ # TODO: Add a wholemodule object-library test once that is working
+ add_library(O OBJECT O.swift L.swift)
+ target_link_libraries(N PUBLIC O)
+ set_target_properties(O PROPERTIES Swift_COMPILATION_MODE "incremental")
+endif()
+
# Dummy to make sure generation works with such targets.
add_library(SwiftIface INTERFACE)
target_link_libraries(SwiftOnly PRIVATE SwiftIface)
@@ -59,14 +66,15 @@ if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2)
endif()
function(test_cmp0157_default mode)
-
- cmake_policy(GET CMP0157 cmp0157_wmo)
- if(cmp0157_wmo STREQUAL "NEW")
- set(CMAKE_Swift_COMPILATION_MODE "${mode}")
- add_executable(hi_${mode} main.swift)
- get_target_property(${mode}_swift_comp_mode hi_${mode} "Swift_COMPILATION_MODE")
- if(NOT ${mode}_swift_comp_mode STREQUAL ${mode})
- message(SEND_ERROR "expected ${mode} -- found ${${mode}_swift_comp_mode}")
+ if(POLICY CMP0157)
+ cmake_policy(GET CMP0157 cmp0157_wmo)
+ if(cmp0157_wmo STREQUAL "NEW")
+ set(CMAKE_Swift_COMPILATION_MODE "${mode}")
+ add_executable(hi_${mode} main.swift)
+ get_target_property(${mode}_swift_comp_mode hi_${mode} "Swift_COMPILATION_MODE")
+ if(NOT ${mode}_swift_comp_mode STREQUAL ${mode})
+ message(SEND_ERROR "expected ${mode} -- found ${${mode}_swift_comp_mode}")
+ endif()
endif()
endif()
endfunction()
diff --git a/Tests/SwiftOnly/O.swift b/Tests/SwiftOnly/O.swift
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/SwiftOnly/O.swift