Skip to content

Commit 35786c8

Browse files
committed
WIP Windows
1 parent b459125 commit 35786c8

File tree

4 files changed

+87
-68
lines changed

4 files changed

+87
-68
lines changed

Sources/CMakeLists.txt

Lines changed: 85 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,99 @@
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_PATH "<auto>" CACHE STRING "Path to SwiftTesting macro plugin, or '<auto>' for building it")
1110

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

30-
find_package(SwiftSyntax CONFIG GLOBAL)
31-
if(SwiftSyntax_FOUND)
32-
set(SwiftTesting_BuildMacrosAsExecutables NO)
39+
ExternalProject_Add(TestingMacros
40+
PREFIX "tm"
41+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/TestingMacros"
42+
CMAKE_ARGS
43+
-DCMAKE_MAKE_PROGRAM=${SwiftTesting_MACRO_MAKE_PROGRAM}
44+
-DCMAKE_Swift_COMPILER=${SwiftTesting_MACRO_Swift_COMPILER}
45+
-DCMAKE_Swift_FLAGS=${SwiftTesting_MACRO_Swift_FLAGS}
46+
-DCMAKE_Swift_FLAGS_RELEASE=${SwiftTesting_MACRO_Swift_FLAGS_RELEASE}
47+
-DCMAKE_Swift_FLAGS_RELWITHDEBINFO=${SwiftTesting_MACRO_Swift_FLAGS_RELWITHDEBINFO}
48+
-DCMAKE_AR=${SwiftTesting_MACRO_AR}
49+
-DCMAKE_RANLIB=${SwiftTesting_MACRO_RANLIB}
50+
-DSwiftTesting_BuildMacrosAsExecutables=${SwiftTesting_BuildMacrosAsExecutables}
51+
-DSwiftSyntax_DIR=${SwiftSyntax_DIR}
52+
INSTALL_COMMAND "")
53+
ExternalProject_Get_Property(TestingMacros BINARY_DIR)
54+
55+
# Hardcode the known file names based on system name as a workaround since
56+
# TestingMacros uses `ExternalProject` and we cannot directly query the
57+
# properties of its targets here.
58+
if(NOT SwiftTesting_BuildMacrosAsExecutables)
59+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
60+
set(SwiftTesting_MACRO "${BINARY_DIR}/libTestingMacros.dylib")
61+
install(PROGRAMS "${SwiftTesting_MACRO}"
62+
DESTINATION lib/swift/host/plugins/testing)
63+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
64+
set(SwiftTesting_MACRO "${BINARY_DIR}/libTestingMacros.so")
65+
install(PROGRAMS "${SwiftTesting_MACRO}"
66+
DESTINATION lib/swift/host/plugins)
67+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
68+
set(SwiftTesting_MACRO_LIBRARY "${BINARY_DIR}/TestingMacros.dll")
69+
# In Windows toolchain, TestingMacros.dll is injected from separate CMake build.
70+
else()
71+
message(FATAL_ERROR "Unable to determine the library name for TestingMacros based on system name: ${CMAKE_SYSTEM_NAME}")
72+
endif()
73+
else()
74+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
75+
set(SwiftTesting_MACRO "${BINARY_DIR}/TestingMacros.exe")
76+
else()
77+
set(SwiftTesting_MACRO "${BINARY_DIR}/TestingMacros")
78+
endif()
79+
endif()
80+
elseif(SwiftTesting_MACRO_PATH)
81+
add_custom_target(TestingMacros DEPENDS "${SwiftTesting_MACRO_PATH}")
82+
set(SwiftTesting_MACRO "${SwiftTesting_MACRO_PATH}")
3383
else()
34-
set(SwiftTesting_BuildMacrosAsExecutables YES)
84+
add_custom_target(TestingMacros)
3585
endif()
3686

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)
87+
if(NOT SwiftTesting_MACRO)
88+
message(STATUS "TestingMacros: (none)")
89+
elseif(SwiftTesting_MACRO)
90+
get_filename_component(macro_ext "${SwiftTesting_MACRO}" LAST_EXT)
91+
if(macro_ext STREQUAL ${CMAKE_SHARED_LIBRARY_SUFFIX})
92+
message(STATUS "TestingMacros: ${SwiftTesting_MACRO} (shared library)")
93+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-library ${SwiftTesting_MACRO}>")
94+
else()
95+
message(STATUS "TestingMacros: ${SwiftTesting_MACRO} (executable)")
96+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-load-plugin-exectuable ${SwiftTesting_MACRO}#TestingMacros>")
97+
endif()
98+
endif()
5199

52100
include(AvailabilityDefinitions)
53101
include(CompilerSettings)
54102
add_subdirectory(_TestingInternals)
55103
add_subdirectory(Testing)
56104

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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)