I am trying to use Swift Testing in my CMake-based Windows project setup, but the Testing module cannot be found:
[138/153] Building Swift Module 'WinTests' with 2 sources
FAILED: Tests/CMakeFiles/WinTests.dir/Common/Mouse/MouseEventAdapterTests.swift.obj Tests/CMakeFiles/WinTests.dir/main.swift.obj
E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Onone -g -swift-version 5 -incremental -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:1:8: error: no such module 'Testing'
import Testing
^
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:1:8: error: no such module 'Testing'
import Testing
^
I am on a current 6.2 toolchain and want to use the bundled Testing framework (not a separate download ).
I have read this post and used it as a starting point. Here's the CMakeLists.txt
for my Tests
folder:
cmake_minimum_required(VERSION 3.29)
project(WinTests Swift)
file(GLOB_RECURSE TEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.swift"
)
add_executable(WinTests ${TEST_SOURCES})
set_target_properties(WinTests PROPERTIES
SUFFIX .swift-testing
)
target_compile_options(WinTests PRIVATE
-parse-as-library
)
target_link_libraries(WinTests PRIVATE
Testing
)
# Enable CTest
enable_testing()
add_test(NAME WinTests COMMAND WinTests)
Swift toolchain (20250629.2 TBC toolchain ):
compnerd.org Swift version 6.2-dev (LLVM f1607d165cb61ef, Swift a9f696b81261204)
Target: aarch64-unknown-windows-msvc
Build config: +assertions
Has anybody got this working on Windows?
thanks in advance
grynspan
(Jonathan Grynspan)
June 29, 2025, 7:10pm
2
As I mentioned in that thread, we don't support the use of CMake with Swift Testing. If you use Swift Package Manager, is it able to find the Testing module?
@plemarquand FYI.
compnerd
(Saleem Abdulrasool)
June 29, 2025, 9:17pm
3
This should work fine. Did you adjust the library search path for the developer libraries?
I had tried adding this function here
function(enable_swift_testing target)
# Locate Swift compiler
find_program(SWIFT_EXECUTABLE swiftc)
if(NOT SWIFT_EXECUTABLE)
message(FATAL_ERROR "Swift compiler (swiftc) not found in PATH.")
endif()
# Get Swift target info in JSON format
execute_process(
COMMAND ${SWIFT_EXECUTABLE} -print-target-info
OUTPUT_VARIABLE SWIFT_TARGET_INFO_JSON
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Extract runtime library path
string(JSON SWIFT_LIB_PATH GET ${SWIFT_TARGET_INFO_JSON} "paths" "runtimeLibraryPaths" 0)
# set(SWIFT_LIB_PATH "E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows")
if(NOT EXISTS "${SWIFT_LIB_PATH}/Testing.swiftmodule")
message(WARNING "Testing.swiftmodule not found at: ${SWIFT_LIB_PATH}")
else()
message(STATUS "Swift Testing.swiftmodule found at: ${SWIFT_LIB_PATH}")
endif()
# Apply to the given target
target_compile_options(${target} PRIVATE -I"${SWIFT_LIB_PATH}")
target_link_directories(${target} PRIVATE "${SWIFT_LIB_PATH}")
target_link_libraries(${target} PRIVATE Testing)
endfunction()
to my CMakeLists.txt
cmake_minimum_required(VERSION 3.29)
project(WinTests Swift)
include(FindSwiftTesting)
file(GLOB_RECURSE TEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*.swift"
)
add_executable(WinTests ${TEST_SOURCES})
set_target_properties(WinTests PROPERTIES
SUFFIX .swift-testing
)
enable_swift_testing(WinTests)
target_compile_options(WinTests PRIVATE
-parse-as-library
-enable-experimental-feature Extern
)
target_link_libraries(WinTests PRIVATE
Testing
# CompositorCore
# CWinRT
# UWP
# Win2D
# WinAppSDK
# WindowsFoundation
# WinUI
)
# Enable CTest
enable_testing()
add_test(NAME WinTests COMMAND WinTests)
but that didn't improve things.
I also tried hardwiring
set(SWIFT_LIB_PATH "E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows")
in the function, but that made no difference.
compnerd
(Saleem Abdulrasool)
June 30, 2025, 6:09am
5
Are you building the toolchain yourself? That path does not seem correct for recent releases.
Try $ENV{SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows/x86_64
.
I am using yesterday's TBC toolchain build.
The relative path you gave and the hardcoded path I tried expand to the same path:
set(SDKROOT $ENV{SDKROOT})
set(RELATIVE_PATH "${SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows")
file(REAL_PATH "${RELATIVE_PATH}" SWIFT_LIB_PATH)
message(STATUS "SWIFT_LIB_PATH: ${SWIFT_LIB_PATH}")
outputs
[cmake] -- SWIFT_LIB_PATH: E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows
My modified enable_swift_testing
function with $ENV{SDKROOT}
now looks like this:
function(enable_swift_testing target)
set(RELATIVE_PATH "$ENV{SDKROOT}/../../Library/Testing-0.0.0/usr/lib/swift/windows")
file(REAL_PATH "${RELATIVE_PATH}" SWIFT_TESTING_LIB_PATH)
if(NOT EXISTS "${SWIFT_TESTING_LIB_PATH}/Testing.swiftmodule")
message(WARNING "Testing.swiftmodule not found at: ${SWIFT_TESTING_LIB_PATH}")
else()
message(STATUS "Testing.swiftmodule found at: ${SWIFT_TESTING_LIB_PATH}")
endif()
target_compile_options(${target} PRIVATE -I"${SWIFT_TESTING_LIB_PATH}")
target_link_directories(${target} PRIVATE "${SWIFT_TESTING_LIB_PATH}/aarch64")
target_link_libraries(${target} PRIVATE Testing)
endfunction()
I added the architecture folder only on the target_link_directories
call, because I am guessing that the Testing.swiftmodule
needs to be on the include path (-I"${SWIFT_LIB_PATH}"
) and the .lib for the target platform needs to be in the target_link_directories
list:
|-- Platforms
| `-- 0.0.0
| `-- Windows.platform
| |-- Developer
| | |-- Library
| | | |-- Testing-0.0.0
| | | | `-- usr
| | | | |-- bin32
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | |-- bin64
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | |-- bin64a
| | | | | |-- Testing.dll
| | | | | `-- _Testing_Foundation.dll
| | | | `-- lib
| | | | `-- swift
| | | | `-- windows
| | | | |-- Testing.swiftcrossimport
| | | | | `-- Foundation.swiftoverlay
| | | | |-- Testing.swiftmodule
| | | | | |-- aarch64-unknown-windows-msvc.swiftdoc
| | | | | |-- aarch64-unknown-windows-msvc.swiftinterface
| | | | | |-- i686-unknown-windows-msvc.swiftdoc
| | | | | |-- i686-unknown-windows-msvc.swiftinterface
| | | | | |-- x86_64-unknown-windows-msvc.swiftdoc
| | | | | `-- x86_64-unknown-windows-msvc.swiftinterface
| | | | |-- _Testing_Foundation.swiftmodule
| | | | | |-- aarch64-unknown-windows-msvc.swiftdoc
| | | | | |-- aarch64-unknown-windows-msvc.swiftinterface
| | | | | |-- i686-unknown-windows-msvc.swiftdoc
| | | | | |-- i686-unknown-windows-msvc.swiftinterface
| | | | | |-- x86_64-unknown-windows-msvc.swiftdoc
| | | | | `-- x86_64-unknown-windows-msvc.swiftinterface
| | | | |-- aarch64
| | | | | |-- Testing.lib
| | | | | `-- _Testing_Foundation.lib
| | | | |-- i686
| | | | | |-- Testing.lib
| | | | | `-- _Testing_Foundation.lib
| | | | `-- x86_64
| | | | |-- Testing.lib
| | | | `-- _Testing_Foundation.lib
Also: Thanks for the quick response (as always)!
compnerd
(Saleem Abdulrasool)
June 30, 2025, 4:44pm
7
Yes, that is correct, the .swiftmodule
needs to be in the module search path (-I
) and the .lib
files need to be in the linker search path (-L
). Once the import is resolved, the linker search path will become relevant.
Is the module not found after that adjustment? Can you re-run the build with -D CMAKE_Swift_FLAGS="-Rmodule-loading"
? That should help identify what is going on with the module search.
I think this here should be the relevant part of the build output after adding -Rmodule-loading
to my CMAKE_Swift_FLAGS
:
...
[136/153] E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Rmodule-loading -Onone -g -swift-version 5 -incremental -I\"E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows\" -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
FAILED: Tests/CMakeFiles/WinTests.dir/Common/Mouse/MouseEventAdapterTests.swift.obj Tests/CMakeFiles/WinTests.dir/main.swift.obj
E:\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe -j 4 -num-threads 4 -c -module-name WinTests -g -Onone -use-ld=lld -Xlinker /DEBUG:FULL -Xlinker -debug:dwarf -diagnostic-style=llvm -Rmodule-loading -Onone -g -swift-version 5 -incremental -I\"E:/Swift/Platforms/0.0.0/Windows.platform/Developer/Library/Testing-0.0.0/usr/lib/swift/windows\" -parse-as-library -enable-experimental-feature Extern -output-file-map Tests\CMakeFiles\WinTests.dir\Debug\output-file-map.json E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/Common/Mouse/MouseEventAdapterTests.swift E:/sandbox/ktraunmueller/compositor/Sources/Win/Tests/main.swift
Module import search paths:
[0] (non-system) "E:\Swift\Platforms\0.0.0\Windows.platform\Developer\Library\Testing-0.0.0\usr\lib\swift\windows"
Framework search paths:
Implicit framework search paths:
Runtime library import search paths:
[0] E:\Swift\Toolchains\0.0.0+Asserts\usr\lib\swift\windows
[1] E:\Swift\Toolchains\0.0.0+Asserts\usr\lib\swift\windows\aarch64
[2] E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows
[3] E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\aarch64
(End of search path lists.)
<unknown>:0: remark: 'Swift' has a required transitive dependency on 'SwiftShims'
<unknown>:0: remark: loaded module 'SwiftShims'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\module.modulemap', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\1XXETTPEZDFIH\SwiftShims-3QCGUQPGZBKD0.pcm'
<unknown>:0: remark: loaded module 'Swift'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\Swift.swiftmodule\aarch64-unknown-windows-msvc.swiftmodule'
<unknown>:0: remark: '_StringProcessing' has a required transitive dependency on 'Swift'
<unknown>:0: remark: loaded module '_StringProcessing'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\_StringProcessing.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\_StringProcessing-1XXI22SV15PNA.swiftmodule'
<unknown>:0: remark: loaded module '_SwiftConcurrencyShims'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\shims\module.modulemap', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\1XXETTPEZDFIH\_SwiftConcurrencyShims-3QCGUQPGZBKD0.pcm'
<unknown>:0: remark: '_Concurrency' has a required transitive dependency on 'Swift'
<unknown>:0: remark: '_Concurrency' has a required transitive dependency on 'SwiftShims'
<unknown>:0: remark: loaded module '_Concurrency'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\_Concurrency.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\_Concurrency-2OL061KBKSHQC.swiftmodule'
<unknown>:0: remark: 'SwiftOnoneSupport' has a required transitive dependency on 'Swift'
<unknown>:0: remark: loaded module 'SwiftOnoneSupport'; source: 'E:\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk\usr\lib\swift\windows\SwiftOnoneSupport.swiftmodule\aarch64-unknown-windows-msvc.swiftinterface', loaded: 'C:\Users\karl\AppData\Local\clang\ModuleCache\SwiftOnoneSupport-29BN42HHB1KCZ.swiftmodule'
E:\sandbox\ktraunmueller\compositor\Sources\Win\Tests\Common\Mouse\MouseEventAdapterTests.swift:2:8: error: no such module 'Testing'
import Testing
compnerd
(Saleem Abdulrasool)
June 30, 2025, 5:00pm
9
I think that the issue is that you have extra quotes in your path. Use "-I..."
rather than -I\"...\"
.
Yes, that now successully produces the test binary:
E:\sandbox\ktraunmueller\compositor\Sources\Win\build\Tests>dir
...
06/30/2025 07:03 PM 1,426 WinTests.lib
06/30/2025 07:03 PM 483,328 WinTests.pdb
06/30/2025 07:03 PM 94,208 WinTests.swift-testing
Thank you so much