From b8ab03c3c560acae6fa7fdc228957cad7134d2fe Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Mon, 15 Jun 2026 18:45:05 -0700 Subject: [PATCH] Use `z-applocal` instead of `applocal.ps1` by default. (#52315) --- .../buildsystems/msbuild/vcpkg-general.xml | 4 +- scripts/buildsystems/msbuild/vcpkg.props | 2 +- scripts/buildsystems/vcpkg.cmake | 77 +++++++++++++------ .../cmake/vcpkg_copy_tool_dependencies.cmake | 51 +++++++++--- 4 files changed, 96 insertions(+), 38 deletions(-) diff --git a/scripts/buildsystems/msbuild/vcpkg-general.xml b/scripts/buildsystems/msbuild/vcpkg-general.xml index af45f5ca72..61c7190a57 100644 --- a/scripts/buildsystems/msbuild/vcpkg-general.xml +++ b/scripts/buildsystems/msbuild/vcpkg-general.xml @@ -48,8 +48,8 @@ - + diff --git a/scripts/buildsystems/msbuild/vcpkg.props b/scripts/buildsystems/msbuild/vcpkg.props index 142f5efbda..498c27ee3e 100644 --- a/scripts/buildsystems/msbuild/vcpkg.props +++ b/scripts/buildsystems/msbuild/vcpkg.props @@ -34,7 +34,7 @@ Tried to add /lib as a parameter to the linker call but was unable to find a way to pass it as the first parameter. --> false true - false + true true diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index 5c8dd6f0e9..65ec8f13bf 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -47,6 +47,7 @@ mark_as_advanced(VCPKG_VERBOSE) option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON) option(X_VCPKG_APPLOCAL_DEPS_SERIALIZED "(experimental) Add USES_TERMINAL to VCPKG_APPLOCAL_DEPS to force serialization." OFF) +option(VCPKG_USE_LEGACY_APPLOCAL "Use applocal.ps1 instead of vcpkg z-applocal." OFF) # requires CMake 3.14 option(X_VCPKG_APPLOCAL_DEPS_INSTALL "(experimental) Automatically copy dependencies into the install target directory for executables. Requires CMake 3.14." OFF) @@ -620,19 +621,29 @@ function(add_executable) if(IMPORTED_IDX EQUAL "-1" AND ALIAS_IDX EQUAL "-1") if(VCPKG_APPLOCAL_DEPS) if(Z_VCPKG_TARGET_TRIPLET_PLAT MATCHES "windows|uwp|xbox") - z_vcpkg_set_powershell_path() set(EXTRA_OPTIONS "") if(X_VCPKG_APPLOCAL_DEPS_SERIALIZED) set(EXTRA_OPTIONS USES_TERMINAL) endif() - add_custom_command(TARGET "${target_name}" POST_BUILD - COMMAND "${Z_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1" - -targetBinary "$" - -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" - -OutVariable out - VERBATIM - ${EXTRA_OPTIONS} - ) + if(VCPKG_USE_LEGACY_APPLOCAL) + z_vcpkg_set_powershell_path() + add_custom_command(TARGET "${target_name}" POST_BUILD + COMMAND "${Z_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1" + -targetBinary "$" + -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" + -OutVariable out + VERBATIM + ${EXTRA_OPTIONS} + ) + else() + add_custom_command(TARGET "${target_name}" POST_BUILD + COMMAND "${Z_VCPKG_EXECUTABLE}" z-applocal + "--target-binary=$" + "--installed-bin-dir=${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" + VERBATIM + ${EXTRA_OPTIONS} + ) + endif() elseif(Z_VCPKG_TARGET_TRIPLET_PLAT MATCHES "osx") if(NOT MACOSX_BUNDLE_IDX EQUAL "-1") find_package(Python COMPONENTS Interpreter) @@ -661,14 +672,23 @@ function(add_library) if(IMPORTED_IDX EQUAL "-1" AND INTERFACE_IDX EQUAL "-1" AND ALIAS_IDX EQUAL "-1") get_target_property(IS_LIBRARY_SHARED "${target_name}" TYPE) if(VCPKG_APPLOCAL_DEPS AND Z_VCPKG_TARGET_TRIPLET_PLAT MATCHES "windows|uwp|xbox" AND (IS_LIBRARY_SHARED STREQUAL "SHARED_LIBRARY" OR IS_LIBRARY_SHARED STREQUAL "MODULE_LIBRARY")) - z_vcpkg_set_powershell_path() - add_custom_command(TARGET "${target_name}" POST_BUILD - COMMAND "${Z_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1" - -targetBinary "$" - -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" - -OutVariable out + if(VCPKG_USE_LEGACY_APPLOCAL) + z_vcpkg_set_powershell_path() + add_custom_command(TARGET "${target_name}" POST_BUILD + COMMAND "${Z_VCPKG_POWERSHELL_PATH}" -noprofile -executionpolicy Bypass -file "${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1" + -targetBinary "$" + -installedDir "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" + -OutVariable out + VERBATIM + ) + else() + add_custom_command(TARGET "${target_name}" POST_BUILD + COMMAND "${Z_VCPKG_EXECUTABLE}" z-applocal + "--target-binary=$" + "--installed-bin-dir=${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin" VERBATIM - ) + ) + endif() endif() set_target_properties("${target_name}" PROPERTIES VS_USER_PROPS do_not_import_user.props) set_target_properties("${target_name}" PROPERTIES VS_GLOBAL_VcpkgEnabled false) @@ -705,7 +725,6 @@ function(x_vcpkg_install_local_dependencies) # Install CODE|SCRIPT allow the use of generator expressions cmake_policy(SET CMP0087 NEW) # CMake 3.14 - z_vcpkg_set_powershell_path() if(NOT IS_ABSOLUTE "${arg_DESTINATION}") set(arg_DESTINATION "\${CMAKE_INSTALL_PREFIX}/${arg_DESTINATION}") endif() @@ -719,13 +738,23 @@ function(x_vcpkg_install_local_dependencies) foreach(target IN LISTS arg_TARGETS) get_target_property(target_type "${target}" TYPE) if(target_type IN_LIST allowed_target_types) - install(CODE "message(\"-- Installing app dependencies for ${target}...\") - execute_process(COMMAND \"${Z_VCPKG_POWERSHELL_PATH}\" -noprofile -executionpolicy Bypass -file \"${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1\" - -targetBinary \"${arg_DESTINATION}/$\" - -installedDir \"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin\" - -OutVariable out)" - ${component_param} - ) + if(VCPKG_USE_LEGACY_APPLOCAL) + z_vcpkg_set_powershell_path() + install(CODE "message(\"-- Installing app dependencies for ${target}...\") + execute_process(COMMAND \"${Z_VCPKG_POWERSHELL_PATH}\" -noprofile -executionpolicy Bypass -file \"${Z_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1\" + -targetBinary \"${arg_DESTINATION}/$\" + -installedDir \"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin\" + -OutVariable out)" + ${component_param} + ) + else() + install(CODE "message(\"-- Installing app dependencies for ${target}...\") + execute_process(COMMAND \"${Z_VCPKG_EXECUTABLE}\" z-applocal + \"--target-binary=${arg_DESTINATION}/$\" + \"--installed-bin-dir=${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin\")" + ${component_param} + ) + endif() endif() endforeach() endif() diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 6b4c66a3c3..9b0d22fef9 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -6,15 +6,42 @@ function(z_vcpkg_copy_tool_dependencies_search tool_dir path_to_search) endif() file(GLOB tools "${tool_dir}/*.exe" "${tool_dir}/*.dll" "${tool_dir}/*.pyd") foreach(tool IN LISTS tools) - vcpkg_execute_required_process( - COMMAND "${Z_VCPKG_POWERSHELL_CORE}" -noprofile -executionpolicy Bypass -nologo - -file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1" - -targetBinary "${tool}" - -installedDir "${path_to_search}" - -verbose - WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" - LOGNAME copy-tool-dependencies-${count} - ) + set(log_out "${CURRENT_BUILDTREES_DIR}/copy-tool-dependencies-${count}-out.log") + set(log_err "${CURRENT_BUILDTREES_DIR}/copy-tool-dependencies-${count}-err.log") + set(copied_files_log "${CURRENT_BUILDTREES_DIR}/copy-tool-dependencies-${count}-copied-files.log") + file(REMOVE "${copied_files_log}") + if(VCPKG_USE_LEGACY_APPLOCAL) + vcpkg_execute_in_download_mode( + COMMAND "${Z_VCPKG_POWERSHELL_CORE}" -noprofile -executionpolicy Bypass -file "${VCPKG_ROOT_DIR}/scripts/buildsystems/msbuild/applocal.ps1" + -targetBinary "${tool}" + -installedDir "${path_to_search}" + -OutVariable out + RESULT_VARIABLE error_code + OUTPUT_VARIABLE out_var + ERROR_VARIABLE err_var + WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" + ) + else() + vcpkg_execute_in_download_mode( + COMMAND "$ENV{VCPKG_COMMAND}" z-applocal + "--target-binary=${tool}" + "--installed-bin-dir=${path_to_search}" + "--copied-files-log=${copied_files_log}" + RESULT_VARIABLE error_code + OUTPUT_VARIABLE out_var + ERROR_VARIABLE err_var + WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" + ) + endif() + file(WRITE "${log_out}" "${out_var}") + if(EXISTS "${copied_files_log}") + file(READ "${copied_files_log}" copied_files) + file(APPEND "${log_out}" "${copied_files}") + endif() + file(WRITE "${log_err}" "${err_var}") + if(NOT error_code STREQUAL "0" AND VCPKG_VERBOSE) + message(STATUS "vcpkg failed to copy dependencies for ${tool}; see ${log_out} and ${log_err}.") + endif() math(EXPR count "${count} + 1") endforeach() set(Z_VCPKG_COPY_TOOL_DEPENDENCIES_COUNT ${count} CACHE INTERNAL "") @@ -26,8 +53,10 @@ function(vcpkg_copy_tool_dependencies tool_dir) endif() if(VCPKG_TARGET_IS_WINDOWS) - vcpkg_find_acquire_program(PWSH) - set(Z_VCPKG_POWERSHELL_CORE "${PWSH}") + if(VCPKG_USE_LEGACY_APPLOCAL) + vcpkg_find_acquire_program(PWSH) + set(Z_VCPKG_POWERSHELL_CORE "${PWSH}") + endif() cmake_path(RELATIVE_PATH tool_dir BASE_DIRECTORY "${CURRENT_PACKAGES_DIR}" OUTPUT_VARIABLE relative_tool_dir