Copy the Python runtime only when it changes, and use thin archives with clang-cl (#17511)

This commit is contained in:
Ian Bassi authored and GitHub committed 2026-11-15 11:07:56 -03:00
1 parent 8a1cef365e
commit ebfce227c6
5 files changed
+47 -6

No files matched your search

+5
View File
@@ -373,6 +373,11 @@ if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
# clang-cl can interpret SYSTEM header paths if -imsvc is used
set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc")
# Thin archives reference the objects instead of copying them; only lld-link reads them.
if (NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND CMAKE_AR MATCHES "llvm-lib" AND CMAKE_LINKER MATCHES "lld-link")
string(APPEND CMAKE_STATIC_LINKER_FLAGS " /llvmlibthin")
endif ()
else ()
set(IS_CLANG_CL FALSE)
endif ()
+32
View File
@@ -0,0 +1,32 @@
# cmake -DSOURCE=<dir> -DDESTINATION=<dir> -DSTAMP=<file> -P StagePythonRuntime.cmake
# Copies only when SOURCE's files or their times changed since the copy STAMP records.
foreach (_var SOURCE DESTINATION STAMP)
if (NOT DEFINED ${_var})
message(FATAL_ERROR "StagePythonRuntime.cmake: ${_var} is not set")
endif ()
endforeach ()
file(GLOB_RECURSE _files LIST_DIRECTORIES false RELATIVE "${SOURCE}" "${SOURCE}/*")
list(SORT _files)
set(_signature "${SOURCE}\n")
foreach (_file IN LISTS _files)
file(TIMESTAMP "${SOURCE}/${_file}" _time "%Y%m%d%H%M%S" UTC)
string(APPEND _signature "${_file} ${_time}\n")
endforeach ()
string(SHA256 _signature "${_signature}")
if (IS_DIRECTORY "${DESTINATION}" AND EXISTS "${STAMP}")
file(READ "${STAMP}" _copied)
if (_copied STREQUAL _signature)
return()
endif ()
endif ()
file(REMOVE "${STAMP}")
file(REMOVE_RECURSE "${DESTINATION}")
execute_process(COMMAND "${CMAKE_COMMAND}" -E copy_directory "${SOURCE}" "${DESTINATION}"
RESULT_VARIABLE _result)
if (NOT _result EQUAL 0)
message(FATAL_ERROR "Copying ${SOURCE} to ${DESTINATION} failed")
endif ()
file(WRITE "${STAMP}" "${_signature}")
+1 -1
View File
@@ -24,7 +24,7 @@ BUILD_CONFIG="${2:-}"
# Install it with the uv staged beside that runtime -- the tool the app installs plugin
# dependencies with -- straight into the interpreter's own site-packages: no pip needed
# in the runtime, no PYTHONPATH. Re-checked every run because a rebuild of the test
# target re-copies the runtime; needs network whenever it installs. Pinned so a numpy
# target can re-copy the runtime; needs network whenever it installs. Pinned so a numpy
# release cannot change results on its own.
NUMPY_VERSION="2.5.3"
+5 -3
View File
@@ -282,9 +282,11 @@ if (WIN32)
endif ()
# copy libpython to the bin folder for Windows
add_custom_command(TARGET OrcaSlicer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rm -rf "$<TARGET_FILE_DIR:OrcaSlicer>/python"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_PREFIX_PATH}/libpython" "$<TARGET_FILE_DIR:OrcaSlicer>/python"
COMMENT "Copying Python runtime into the build tree"
COMMAND ${CMAKE_COMMAND} "-DSOURCE=${CMAKE_PREFIX_PATH}/libpython"
"-DDESTINATION=$<TARGET_FILE_DIR:OrcaSlicer>/python"
"-DSTAMP=${CMAKE_CURRENT_BINARY_DIR}/python_runtime_$<CONFIG>.stamp"
-P "${CMAKE_SOURCE_DIR}/cmake/modules/StagePythonRuntime.cmake"
COMMENT "Updating the Python runtime in the build tree"
VERBATIM)
if (CMAKE_CONFIGURATION_TYPES)
+4 -2
View File
@@ -90,8 +90,10 @@ orcaslicer_copy_test_dlls(${_TEST_NAME}_tests)
if (WIN32)
add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_PREFIX_PATH}/libpython" "$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
COMMAND ${CMAKE_COMMAND} "-DSOURCE=${CMAKE_PREFIX_PATH}/libpython"
"-DDESTINATION=$<TARGET_FILE_DIR:${_TEST_NAME}_tests>/python"
"-DSTAMP=${CMAKE_CURRENT_BINARY_DIR}/python_runtime_$<CONFIG>.stamp"
-P "${CMAKE_SOURCE_DIR}/cmake/modules/StagePythonRuntime.cmake"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_PREFIX_PATH}/libpython/python${_bundled_python_abi}.dll"
"${CMAKE_PREFIX_PATH}/libpython/vcruntime140.dll"