Skip to content

Commit 5e09d09

Browse files
committed
WIP Windows
1 parent b459125 commit 5e09d09

File tree

4 files changed

+96
-68
lines changed

4 files changed

+96
-68
lines changed

Sources/CMakeLists.txt

+94-54
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,108 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
# Macros must be built for the build machine, not the host.
10-
include(ExternalProject)
9+
set(SwiftTesting_MACRO "<auto>" CACHE STRING
10+
"Path to SwiftTesting macro plugin, or '<auto>' for automatically building it")
1111

12-
if(NOT SwiftTesting_MACRO_MAKE_PROGRAM)
13-
set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
14-
endif()
15-
if(NOT SwiftTesting_MACRO_Swift_COMPILER)
16-
set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER})
17-
endif()
18-
if(NOT SwiftTesting_MACRO_Swift_FLAGS)
19-
set(SwiftTesting_MACRO_Swift_FLAGS ${CMAKE_Swift_FLAGS})
20-
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELEAE ${CMAKE_Swift_FLAGS_RELEAE})
21-
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELWITHDEBINFO ${CMAKE_Swift_FLAGS_RELWITHDEBINFO})
22-
endif()
23-
if(NOT SwiftTesting_MACRO_AR)
24-
set(SwiftTesting_MACRO_AR ${CMAKE_AR})
25-
endif()
26-
if(NOT SwiftTesting_MACRO_RANLIB)
27-
set(SwiftTesting_MACRO_RANLIB ${CMAKE_RANLIB})
28-
endif()
12+
if(SwiftTesting_MACRO STREQUAL "<auto>")
13+
# Macros must be built for the build machine, not the host.
14+
include(ExternalProject)
15+
if(NOT SwiftTesting_MACRO_MAKE_PROGRAM)
16+
set(SwiftTesting_MACRO_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM})
17+
endif()
18+
if(NOT SwiftTesting_MACRO_Swift_COMPILER)
19+
set(SwiftTesting_MACRO_Swift_COMPILER ${CMAKE_Swift_COMPILER})
20+
endif()
21+
if(NOT SwiftTesting_MACRO_Swift_FLAGS)
22+
set(SwiftTesting_MACRO_Swift_FLAGS ${CMAKE_Swift_FLAGS})
23+
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELEASE ${CMAKE_Swift_FLAGS_RELEASE})
24+
set(SwiftTesting_MACRO_SWIFT_FLAGS_RELWITHDEBINFO ${CMAKE_Swift_FLAGS_RELWITHDEBINFO})
25+
endif()
26+
if(NOT SwiftTesting_MACRO_AR)
27+
set(SwiftTesting_MACRO_AR ${CMAKE_AR})
28+
endif()
29+
if(NOT SwiftTesting_MACRO_RANLIB)
30+
set(SwiftTesting_MACRO_RANLIB ${CMAKE_RANLIB})
31+
endif()
32+
if(NOT SwiftTesting_MACRO_BUILD_TYPE)
33+
set(SwiftTesting_MACRO_BUILD_TYPE ${CMAKE_BUILD_TYPE})
34+
endif()
35+
36+
find_package(SwiftSyntax CONFIG GLOBAL)
37+
if(SwiftSyntax_FOUND)
38+
set(SwiftTesting_BuildMacrosAsExecutables NO)
39+
else()
40+
set(SwiftTesting_BuildMacrosAsExecutables YES)
41+
endif()
2942

30-
find_package(SwiftSyntax CONFIG GLOBAL)
31-
if(SwiftSyntax_FOUND)
32-
set(SwiftTesting_BuildMacrosAsExecutables NO)
43+
set(SwiftTesting_MACRO_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/plugin")
44+
45+
ExternalProject_Add(TestingMacros
46+
PREFIX "tm"
47+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros"
48+
BUILD_ALWAYS ON
49+
CMAKE_ARGS
50+
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
51+
-DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER}
52+
-DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS}
53+
-DCMAKE_Swift_FLAGS_RELEASE=${SwiftTesting_MACRO_Swift_FLAGS_RELEASE}
54+
-DCMAKE_Swift_FLAGS_RELWITHDEBINFO=${SwiftTesting_MACRO_Swift_FLAGS_RELWITHDEBINFO}
55+
-DCMAKE_AR=${SwiftTesting_MACRO_AR}
56+
-DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB}
57+
-DCMAKE_BUILD_TYPE=${CSwiftTesting_MACRO_BUILD_TYPE}
58+
-DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables}
59+
-DSwiftSyntax_DIR=${SwiftSyntax_DIR}
60+
-DCMAKE_INSTALL_PREFIX=${SwiftTesting_MACRO_INSTALL_PREFIX})
61+
62+
# Hardcode the known file names based on system name as a workaround since
63+
# TestingMacros uses `ExternalProject` and we cannot directly query the
64+
# properties of its targets here.
65+
if(NOT SwiftTesting_BuildMacrosAsExecutables)
66+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
67+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/libTestingMacros.dylib")
68+
install(PROGRAMS "${SwiftTesting_MACRO_PATH}"
69+
DESTINATION lib/swift/host/plugins/testing)
70+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
71+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/lib/libTestingMacros.so")
72+
install(PROGRAMS "${SwiftTesting_MACRO_PATH}"
73+
DESTINATION lib/swift/host/plugins)
74+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
75+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.dll")
76+
install(PROGRAMS "${SwiftTesting_MACRO_PATH}"
77+
DESTINATION bin)
78+
else()
79+
message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}")
80+
endif()
81+
else()
82+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
83+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros.exe")
84+
else()
85+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO_INSTALL_PREFIX}/bin/TestingMacros")
86+
endif()
87+
endif()
88+
elseif(SwiftTesting_MACRO)
89+
set(SwiftTesting_MACRO_PATH "${SwiftTesting_MACRO}")
90+
add_custom_target(TestingMacros DEPENDS "${SwiftTesting_MACRO_PATH}")
3391
else()
34-
set(SwiftTesting_BuildMacrosAsExecutables YES)
92+
# If it's excplicitly "false", do not compile the libray with macros.
93+
add_custom_target(TestingMacros)
3594
endif()
3695

37-
ExternalProject_Add(TestingMacros
38-
PREFIX "tm"
39-
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros"
40-
CMAKE_ARGS
41-
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
42-
-DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER}
43-
-DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS}
44-
-DCMAKE_AR=${SwiftTesting_MACRO_AR}
45-
-DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB}
46-
-DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables}
47-
-DSwiftSyntax_DIR=${SwiftSyntax_DIR}
48-
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>)
49-
ExternalProject_Get_Property(TestingMacros BINARY_DIR)
50-
ExternalProject_Get_Property(TestingMacros INSTALL_DIR)
96+
if(NOT SwiftTesting_MACRO_PATH)
97+
message(STATUS "TestingMacros: (none)")
98+
elseif(SwiftTesting_MACRO_PATH)
99+
get_filename_component(macro_ext "${SwiftTesting_MACRO_PATH}" LAST_EXT)
100+
if(macro_ext STREQUAL ${CMAKE_SHARED_LIBRARY_SUFFIX})
101+
message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (shared library)")
102+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-library ${SwiftTesting_MACRO_PATH}>")
103+
else()
104+
message(STATUS "TestingMacros: ${SwiftTesting_MACRO_PATH} (executable)")
105+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-exectuable ${SwiftTesting_MACRO_PATH}#TestingMacros>")
106+
endif()
107+
endif()
51108

52109
include(AvailabilityDefinitions)
53110
include(CompilerSettings)
54111
add_subdirectory(_TestingInternals)
55112
add_subdirectory(Testing)
56113

57-
if(NOT SwiftTesting_BuildMacrosAsExecutables)
58-
# Hardcode the known library names based on system name as a workaround since
59-
# TestingMacros uses `ExternalProject` and we cannot directly query the
60-
# properties of its targets here.
61-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
62-
install(PROGRAMS "${INSTALL_DIR}/lib/libTestingMacros.dylib"
63-
DESTINATION lib/swift/host/plugins/testing)
64-
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
65-
install(PROGRAMS "${INSTALL_DIR}/lib/libTestingMacros.so"
66-
DESTINATION lib/swift/host/plugins)
67-
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
68-
# In Windows toolchain, TestingMacros.dll is installed from seprate CMake
69-
# buikd, just for the macros.
70-
else()
71-
message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}")
72-
endif()
73-
endif()

Sources/Testing/ABI/EntryPoints/SwiftPMEntryPoint.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var EXIT_NO_TESTS_FOUND: CInt {
2727
#if SWT_TARGET_OS_APPLE || os(Linux) || os(WASI)
2828
EX_UNAVAILABLE
2929
#elseif os(Windows)
30-
ERROR_NOT_FOUND
30+
numericCast(ERROR_NOT_FOUND)
3131
#else
3232
#warning("Platform-specific implementation missing: value for EXIT_NO_TESTS_FOUND unavailable")
3333
return 2 // We're assuming that EXIT_SUCCESS = 0 and EXIT_FAILURE = 1.

Sources/Testing/CMakeLists.txt

-12
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,6 @@ target_compile_options(Testing PRIVATE
100100
-enable-library-evolution
101101
-emit-module-interface -emit-module-interface-path $<TARGET_PROPERTY:Testing,Swift_MODULE_DIRECTORY>/Testing.swiftinterface)
102102

103-
if(SwiftTesting_BuildMacrosAsExecutables)
104-
if(CMAKE_HOST_WIN32)
105-
set(_TestingMacros_ExecutableSuffix ".exe")
106-
endif()
107-
108-
target_compile_options(Testing PUBLIC
109-
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-load-plugin-executable ${BINARY_DIR}/TestingMacros${_TestingMacros_ExecutableSuffix}#TestingMacros>")
110-
else()
111-
target_compile_options(Testing PUBLIC
112-
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-plugin-path ${BINARY_DIR}>")
113-
endif()
114-
115103
target_compile_options(Testing PRIVATE "-no-toolchain-stdlib-rpath")
116104
# TODO: Finalize
117105
set_property(TARGET Testing PROPERTY INSTALL_RPATH "$ORIGIN")

Sources/Testing/ExitTests/WaitFor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func wait(for processHandle: HANDLE) async throws -> ExitCondition {
218218
}
219219

220220
// FIXME: handle SEH/VEH uncaught exceptions.
221-
return .exitCode(CInt(bitPattern: status))
221+
return .exitCode(CInt(bitPattern: numericCast(status)))
222222
}
223223
#endif
224224
#endif

0 commit comments

Comments
 (0)