File tree Expand file tree Collapse file tree 10 files changed +109
-38
lines changed Expand file tree Collapse file tree 10 files changed +109
-38
lines changed Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ extension Array where Element == PackageDescription.CXXSetting {
170
170
} else {
171
171
git. currentCommit
172
172
}
173
- result. append ( . define( " _SWT_TESTING_LIBRARY_VERSION " , to: #"" \#( testingLibraryVersion) ""# ) )
173
+ result. append ( . define( " SWT_TESTING_LIBRARY_VERSION " , to: #"" \#( testingLibraryVersion) ""# ) )
174
174
}
175
175
176
176
return result
Original file line number Diff line number Diff line change @@ -310,6 +310,9 @@ extension Event.HumanReadableOutputRecorder {
310
310
comments. append ( " Swift Version: \( swiftStandardLibraryVersion) " )
311
311
}
312
312
comments. append ( " Testing Library Version: \( testingLibraryVersion) " )
313
+ if let targetTriple {
314
+ comments. append ( " Target Platform: \( targetTriple) " )
315
+ }
313
316
if verbosity > 0 {
314
317
#if targetEnvironment(simulator)
315
318
comments. append ( " OS Version (Simulator): \( simulatorVersion) " )
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ let operatingSystemVersion: String = {
88
88
}
89
89
}
90
90
#elseif os(WASI)
91
- if let libcVersion = swt_getWASIVersion ( ) . flatMap ( String . init ( validatingCString: ) ) , !libcVersion . isEmpty {
92
- return " WASI with libc \( libcVersion ) "
91
+ if let version = swt_getWASIVersion ( ) . flatMap ( String . init ( validatingCString: ) ) {
92
+ return version
93
93
}
94
94
#else
95
95
#warning("Platform-specific implementation missing: OS version unavailable")
@@ -132,6 +132,13 @@ var testingLibraryVersion: String {
132
132
swt_getTestingLibraryVersion ( ) . flatMap ( String . init ( validatingCString: ) ) ?? " unknown "
133
133
}
134
134
135
+ /// Get the LLVM target triple used to build the testing library, if available.
136
+ ///
137
+ /// This value is not part of the public interface of the testing library.
138
+ var targetTriple: String? {
139
+ swt_getTargetTriple ( ) . flatMap ( String . init ( validatingCString: ) )
140
+ }
141
+
135
142
/// A human-readable string describing the Swift Standard Library's version.
136
143
///
137
144
/// This value's format is platform-specific and is not meant to be
Original file line number Diff line number Diff line change 9
9
set (CMAKE_CXX_SCAN_FOR_MODULES 0 )
10
10
11
11
include (LibraryVersion )
12
+ include (TargetTriple )
12
13
add_library (_TestingInternals STATIC
13
14
Discovery.cpp
14
15
Versions.cpp
Original file line number Diff line number Diff line change 10
10
11
11
#include " Versions.h"
12
12
13
+ #if defined(_SWT_TESTING_LIBRARY_VERSION) && !defined(SWT_TESTING_LIBRARY_VERSION)
14
+ #warning _SWT_TESTING_LIBRARY_VERSION is deprecated
15
+ #warning Define SWT_TESTING_LIBRARY_VERSION and optionally SWT_TARGET_TRIPLE instead
16
+ #define SWT_TESTING_LIBRARY_VERSION _SWT_TESTING_LIBRARY_VERSION
17
+ #endif
18
+
13
19
const char *swt_getTestingLibraryVersion (void ) {
14
- #if defined(_SWT_TESTING_LIBRARY_VERSION)
15
- return _SWT_TESTING_LIBRARY_VERSION;
20
+ #if defined(SWT_TESTING_LIBRARY_VERSION)
21
+ return SWT_TESTING_LIBRARY_VERSION;
22
+ #else
23
+ #warning SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable
24
+ return nullptr ;
25
+ #endif
26
+ }
27
+
28
+ const char *swt_getTargetTriple (void ) {
29
+ #if defined(SWT_TARGET_TRIPLE)
30
+ return SWT_TARGET_TRIPLE;
16
31
#else
17
- #warning _SWT_TESTING_LIBRARY_VERSION not defined: testing library version is unavailable
32
+ // If we're here, we're presumably building as a package. Swift Package
33
+ // Manager does not provide a way to get the target triple from within the
34
+ // package manifest. SEE: swift-package-manager-#7929
35
+ //
36
+ // clang has __is_target_*() intrinsics, but we don't want to play a game of
37
+ // Twenty Questions in order to synthesize the triple (and still potentially
38
+ // get it wrong.) SEE: rdar://134933385
18
39
return nullptr ;
19
40
#endif
20
41
}
Original file line number Diff line number Diff line change 39
39
#include <string.h>
40
40
#include <time.h>
41
41
42
- #if defined(__APPLE__ ) && !SWT_NO_MACH_PORTS
43
- #include <mach/mach_init.h>
44
- #include <mach/task.h>
45
- #endif
46
-
47
- #if defined(__APPLE__ ) && !SWT_NO_LIBDISPATCH
48
- #include <dispatch/dispatch.h>
49
- #endif
50
-
51
42
#if __has_include (< unistd .h > )
52
43
#include <unistd.h>
53
44
#endif
106
97
#include <crt_externs.h>
107
98
#endif
108
99
109
- #if __has_include (< wasi /libc - environ .h > )
110
- #include <wasi/libc-environ.h>
111
- #endif
112
-
113
100
#if __has_include (< libgen .h > )
114
101
#include <libgen.h>
115
102
#endif
122
109
#include <sysexits.h>
123
110
#endif
124
111
112
+ // MARK: - Platform-specific includes
113
+
114
+ #if defined(__APPLE__ )
115
+ #if !SWT_NO_MACH_PORTS
116
+ #include <mach/mach_init.h>
117
+ #include <mach/task.h>
118
+ #endif
119
+
120
+ #if !SWT_NO_LIBDISPATCH
121
+ #include <dispatch/dispatch.h>
122
+ #endif
123
+ #endif
124
+
125
125
#if defined(_WIN32 )
126
126
#define WIN32_LEAN_AND_MEAN
127
127
#define NOMINMAX
128
128
#include <Windows.h>
129
129
#include <Psapi.h>
130
130
#endif
131
131
132
+ #if defined(__wasi__ )
133
+ #if __has_include (< wasi /libc - environ .h > )
134
+ #include <wasi/libc-environ.h>
135
+ #endif
136
+
137
+ #if __has_include (< wasi /version .h > )
138
+ #include <wasi/version.h>
139
+ #endif
140
+ #endif
141
+
132
142
#if defined(__ANDROID__ )
133
143
#pragma clang module import posix_filesystem.linux_stat
134
144
#include <sys/system_properties.h>
Original file line number Diff line number Diff line change @@ -134,24 +134,6 @@ static int swt_siginfo_t_si_status(const siginfo_t *siginfo) {
134
134
#endif
135
135
#endif
136
136
137
- #if defined(__wasi__ )
138
- /// Get the version of the C standard library and runtime used by WASI, if
139
- /// available.
140
- ///
141
- /// This function is provided because `WASI_LIBC_VERSION` may or may not be
142
- /// defined and may or may not be a complex macro.
143
- ///
144
- /// For more information about the `WASI_LIBC_VERSION` macro, see
145
- /// [wasi-libc-#490](https://github.com/WebAssembly/wasi-libc/issues/490).
146
- static const char * _Nullable swt_getWASIVersion (void ) {
147
- #if defined(WASI_LIBC_VERSION )
148
- return WASI_LIBC_VERSION ;
149
- #else
150
- return 0 ;
151
- #endif
152
- }
153
- #endif
154
-
155
137
SWT_ASSUME_NONNULL_END
156
138
157
139
#endif
Original file line number Diff line number Diff line change 12
12
#define SWT_VERSIONS_H
13
13
14
14
#include "Defines.h"
15
+ #include "Includes.h"
15
16
16
17
SWT_ASSUME_NONNULL_BEGIN
17
18
@@ -23,6 +24,30 @@ SWT_ASSUME_NONNULL_BEGIN
23
24
/// other conditions. Do not attempt to parse it.
24
25
SWT_EXTERN const char * _Nullable swt_getTestingLibraryVersion (void );
25
26
27
+ /// Get the LLVM target triple used to build the testing library.
28
+ ///
29
+ /// - Returns: A string containing the LLVM target triple used to build the
30
+ /// testing library, or `nullptr` if that information is not available.
31
+ SWT_EXTERN const char * _Nullable swt_getTargetTriple (void );
32
+
33
+ #if defined(__wasi__ )
34
+ /// Get the version of the C standard library and runtime used by WASI, if
35
+ /// available.
36
+ ///
37
+ /// This function is provided because `WASI_SDK_VERSION` may or may not be
38
+ /// defined and may or may not be a complex macro.
39
+ ///
40
+ /// For more information about the `WASI_SDK_VERSION` macro, see
41
+ /// [wasi-libc-#490](https://github.com/WebAssembly/wasi-libc/issues/490).
42
+ static const char * _Nullable swt_getWASIVersion (void ) {
43
+ #if defined(WASI_SDK_VERSION )
44
+ return WASI_SDK_VERSION ;
45
+ #else
46
+ return 0 ;
47
+ #endif
48
+ }
49
+ #endif
50
+
26
51
SWT_ASSUME_NONNULL_END
27
52
28
53
#endif
Original file line number Diff line number Diff line change @@ -40,4 +40,4 @@ endif()
40
40
# All done!
41
41
message (STATUS "Swift Testing version: ${SWT_TESTING_LIBRARY_VERSION} " )
42
42
add_compile_definitions (
43
- "$<$<COMPILE_LANGUAGE:CXX>:_SWT_TESTING_LIBRARY_VERSION =\" ${SWT_TESTING_LIBRARY_VERSION} \" >" )
43
+ "$<$<COMPILE_LANGUAGE:CXX>:SWT_TESTING_LIBRARY_VERSION =\" ${SWT_TESTING_LIBRARY_VERSION} \" >" )
Original file line number Diff line number Diff line change
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
+ # Ask the Swift compiler what target triple it will be compiling with today.
10
+ set (SWT_TARGET_INFO_COMMAND "${CMAKE_Swift_COMPILER} " -print-target-info )
11
+ if (CMAKE_Swift_COMPILER_TARGET )
12
+ list (APPEND SWT_TARGET_INFO_COMMAND -target ${CMAKE_Swift_COMPILER_TARGET} )
13
+ endif ()
14
+ execute_process (COMMAND ${SWT_TARGET_INFO_COMMAND} OUTPUT_VARIABLE SWT_TARGET_INFO_JSON )
15
+ string (JSON SWT_TARGET_TRIPLE GET "${SWT_TARGET_INFO_JSON} " "target" "unversionedTriple" )
16
+
17
+ # All done!
18
+ message (STATUS "Swift Testing target triple: ${SWT_TARGET_TRIPLE} " )
19
+ if (SWT_TARGET_TRIPLE )
20
+ add_compile_definitions (
21
+ "$<$<COMPILE_LANGUAGE:CXX>:SWT_TARGET_TRIPLE=\" ${SWT_TARGET_TRIPLE} \" >" )
22
+ endif ()
You can’t perform that action at this time.
0 commit comments