-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preliminary Windows support #20
Conversation
For GTest, I think I'm currently blocked by this: https://gitlab.kitware.com/cmake/cmake/-/issues/21453 Trying to run the test discovery during the post build event fails because the test executables can't find the required DLLs (usd_*.dll, unf.dll, gtest*.dll). |
Ah true, I've run into that issue before and solved it by monkey patching if (WIN32)
# Expand functions to copy dependent DLLs in the same folder after
# building target to ensure that tests can run properly on Windows.
macro(gtest_discover_tests NAME)
add_custom_command(
TARGET ${NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
$<TARGET_RUNTIME_DLLS:${NAME}>
$<TARGET_FILE_DIR:${NAME}>
COMMAND_EXPAND_LISTS
)
_gtest_discover_tests(${NAME} ${ARGV})
endmacro()
endif() The issue is that TARGET_RUNTIME_DLLS will require us to use CMake 3.21 as a minimum version, but it might not be too unreasonable at this point |
0193b68
to
706c87d
Compare
094247d
to
c1aced4
Compare
Thanks for the monkey patch. I gave it a try, but it only copied: python310.dll, unf.dll, unfTest.dll. It didn't copy USD, TBB, GTest. I'm thinking maybe it's because of the NOTE here: https://cmake.org/cmake/help/latest/manual/cmake-generator-expressions.7.html#genex:TARGET_RUNTIME_DLLS I was also thinking that maybe it'd be better to use |
Does Windows support an environment variable that can be used to get it to find DLLs? Basically the semantic equivalent of Linux's Is that variable just called If so, I'd be curious if things run ok if you modify If https://cmake.org/cmake/help/latest/prop_test/ENVIRONMENT_MODIFICATION.html Each of the # test/unit/CMakeLists.txt
if (WIN32)
macro(unf_configure_test target)
set_tests_properties(
${${target}_TESTS} PROPERTIES
ENVIRONMENT_MODIFICATION PATH=path_list_prepend:${CMAKE_BINARY_DIR}/src
)
endmacro()
unf_configure_tests(testUnitBroker)
unf_configure_tests(testUnitDispatcher)
unf_configure_tests(testUnitDispatcherPlugin)
unf_configure_tests(testUnitTransaction)
endif() That might only handle the unf libraries. Some additional tweaks might be needed to add gtest's and usd's directories if that's a viable solution. |
If it's test discovery that's failing then my sug to use Would an option be to avoid gtest_discover_tests altogether and just wire them up as regular If we do that then we should have more control over the environment. |
Hmm true,
I ran some tests by tweaking the monkey-patch to extend the PATH environment variable for all discovered tests and the linking error disappeared (but not all tests are passing yet): if (WIN32)
# Monkeypatch Gtest discovery function to extend environment so that
# relevant DLLs can be found on Windows. We use 'set_tests_properties'
# to prevent issue with escaped semi-colons when passing environment
# to 'gtest_discover_tests'.
macro(gtest_discover_tests NAME)
set(DEPS
$<TARGET_FILE_DIR:unf>
$<TARGET_FILE_DIR:unfTest>
$<TARGET_FILE_DIR:usd::usd>
$<TARGET_FILE_DIR:usd::sdf>
$<TARGET_FILE_DIR:usd::tf>
$<TARGET_FILE_DIR:usd::plug>
$<TARGET_FILE_DIR:usd::arch>
$<TARGET_FILE_DIR:usd::vt>
$<TARGET_FILE_DIR:TBB::tbb>
$<TARGET_FILE_DIR:GTest::gtest>
)
list(REMOVE_DUPLICATES DEPS)
string(REPLACE ";" "\;" DEPS "${DEPS}")
string(REPLACE ";" "\;" ENV_PATH "$ENV{PATH}")
gtest_add_tests(TARGET ${NAME} TEST_LIST allTests)
set_tests_properties(
${allTests} PROPERTIES ENVIRONMENT
"PATH=${DEPS}\;${ENV_PATH}")
endmacro()
endif() We could use the TARGET_RUNTIME_DLL_DIRS expression generator for convenience, but it would only work with CMake 3.27 so it might be a bit restrictive. I feel there might be a better way than listing all dependent targets though. Also, somehow |
If it's tucked inside of a The opt-out variable would be for folks that manage their environment through other means (e.g. the chocolatey package manager for Windows) and don't need that setup. The default behavior can be to leverage that feature so that it's easier for Windows users. |
@buddly27 Can you share what you have with the monkey patch? I tried the latest snippet that you shared, but couldn't get it working. |
@mati-nvidia I pushed my tests on a dummy PR to my fork of the project if you want to check the results: I've got 21 tests failing out of 53 in Release mode, but all tests are failing in Debug mode, so there is still something I'm missing. We could try to catch up this week to discuss it if you have time! Also, I added |
- Experiment with monkey-patching the 'gtest_discover_tests' function on Windows to update the environment to find DLLs; - Update TBB CMake module finder to match the one used by OpenUSD; - Have all CMake module finders create unknown targets as shared targets don't seem to work in Windows when only the import library is found (as it is the case for the TBB lib installed with OpenUSD); - Add CI job to run the tests on Windows.
- Add UNF_EXPORTS definition for all test libraries to ensure that used symbols are marked as exported when required; - Move implementation for test notices within source file as MSVC seems to perform inline expansion more aggressively than GCC; - Update CMake script to ensure that Python module is structured properly within the build folder; - Use pytest-cmake instead of embedding Pytest module finder script; - Ensure compatibility between clang-format v7 (used in studio) and v16 (used within Github Windows runner); - Update CI job and add tests on Windows; - Update documentation and add release notes.
Thanks @buddly27 ! 👍🏼 |
Yes! Thank you @buddly27 ! |
Just sharing the progress so far for #19. I just realized I was working off of the "main" branch, but I'll rebase onto "dev" once I have everything working.
I have the unf and pyUnf projects building on Windows and I was able to run the Python tests successfully on Windows. I'm still fiddling with the GTest projects so that they build on Windows and so that I can run them to verify that's all working too.