Skip to content

Commit 271bff1

Browse files
authored
Configure CMake to build and install the Foundation cross-import overlay (#825)
This augments the project's CMake rules to begin building and installing the Foundation cross-import overlay (`_Testing_Foundation`), including the associated `.swiftcrossimport` directory which causes the overlay to be applied to clients. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. Resolves rdar://139877808
1 parent 1df9545 commit 271bff1

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ endif()
104104
include(AvailabilityDefinitions)
105105
include(CompilerSettings)
106106
add_subdirectory(_TestingInternals)
107+
add_subdirectory(Overlays)
107108
add_subdirectory(Testing)

Sources/Overlays/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_subdirectory(_Testing_Foundation)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(_Testing_Foundation
10+
Attachments/EncodingFormat.swift
11+
Attachments/Attachment+URL.swift
12+
Attachments/Attachable+NSSecureCoding.swift
13+
Attachments/Data+Attachable.swift
14+
Attachments/Attachable+Encodable+NSSecureCoding.swift
15+
Attachments/Attachable+Encodable.swift
16+
Events/Clock+Date.swift
17+
ReexportTesting.swift)
18+
19+
target_link_libraries(_Testing_Foundation PUBLIC
20+
Testing)
21+
22+
# Although this library links Foundation on all platforms, it only does so using
23+
# `target_link_libraries()` when building for non-Apple platforms. This is
24+
# because that command uses the `-lFoundation` linker flag, but on Apple
25+
# platforms Foundation is a .framework and requires a different flag. However,
26+
# we don't need to explicitly pass any linker flag since it's handled
27+
# automatically on Apple platforms via auto-linking.
28+
if(NOT APPLE)
29+
target_link_libraries(_Testing_Foundation PUBLIC
30+
Foundation)
31+
endif()
32+
33+
# Note: This does not enable Library Evolution, despite emitting a module
34+
# interface, because Foundation does not have Library Evolution enabled for all
35+
# platforms.
36+
target_compile_options(_Testing_Foundation PRIVATE
37+
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:_Testing_Foundation,Swift_MODULE_DIRECTORY>/_Testing_Foundation.swiftinterface)
38+
39+
_swift_testing_install_target(_Testing_Foundation)

Sources/Testing/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ target_compile_options(Testing PRIVATE
125125
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:Testing,Swift_MODULE_DIRECTORY>/Testing.swiftinterface)
126126

127127
_swift_testing_install_target(Testing)
128+
129+
# Install the Swift cross-import overlay directory.
130+
_swift_testing_install_swiftcrossimport(Testing
131+
Testing.swiftcrossimport)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: 1
2+
modules:
3+
- name: _Testing_Foundation

cmake/modules/SwiftModuleInstallation.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,23 @@ function(_swift_testing_install_target module)
9696
RENAME ${SwiftTesting_MODULE_TRIPLE}.swiftinterface)
9797
endif()
9898
endfunction()
99+
100+
# Install the specified .swiftcrossimport directory for the specified declaring
101+
# module.
102+
#
103+
# Usage:
104+
# _swift_testing_install_swiftcrossimport(module swiftcrossimport_dir)
105+
#
106+
# Arguments:
107+
# module: The name of the declaring module. This is used to determine where
108+
# the .swiftcrossimport directory should be installed, since it must be
109+
# adjacent to the declaring module's .swiftmodule directory.
110+
# swiftcrossimport_dir: The path to the source .swiftcrossimport directory
111+
# which will be installed.
112+
function(_swift_testing_install_swiftcrossimport module swiftcrossimport_dir)
113+
get_target_property(type ${module} TYPE)
114+
get_swift_testing_install_lib_dir(${type} lib_destination_dir)
115+
116+
install(DIRECTORY "${swiftcrossimport_dir}"
117+
DESTINATION "${lib_destination_dir}")
118+
endfunction()

0 commit comments

Comments
 (0)