[vcpkg scripts] Enable cross-compilation tool dependency copying#49887
[vcpkg scripts] Enable cross-compilation tool dependency copying#49887zynfly wants to merge 1 commit intomicrosoft:masterfrom
Conversation
When cross-compiling from macOS/Linux to Windows targets (e.g., x64-mingw-dynamic), tools built with dynamic linkage were missing their vcpkg DLL dependencies, causing runtime errors on Windows. This change enhances vcpkg_copy_tool_dependencies.cmake to handle cross-compilation scenarios: - Windows host: continues using PowerShell + applocal.ps1 (no change) - Non-Windows host: uses objdump to analyze PE dependencies and recursively copy vcpkg DLLs to the tool directory - Gracefully degrades if objdump is not available (warning only) - Only runs for dynamic linkage (static builds unaffected) The implementation: 1. Detects available objdump variants (MinGW, LLVM, native) 2. Parses PE import tables to find DLL dependencies 3. Recursively resolves transitive dependencies (DLL → DLL) 4. Copies only vcpkg-managed DLLs (skips system DLLs) Tested with brotli:x64-mingw-dynamic on macOS, confirming that brotli.exe now includes all required DLLs (libbrotlidec.dll, libbrotlienc.dll, libbrotlicommon.dll). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
This topic has been touched before:
|
|
This is primarily to address the issue of cross-compilation, rather than the issue of dll handling under Windows. |
This is what I read in the initial post. All my points stand. |
|
And there is a bug in vcpkg. When executed on macOS/Linux, if the target triplet is still set to Windows, it will invoke Powershell, which can also lead to failures. I initially started working on this to fix the bug. |
Yes, it is possible to install pwsh on Linux and macOS, but I don't think it's a good approach. Or maybe vcpkg shouldn't rely on pwsh on these platforms. |
|
[ if(VCPKG_TARGET_IS_WINDOWS) ]( )The main issue lies here: as long as the target is Windows, pwsh must be used. |
It is a feature, not an issue: If you install powershell on macOS and build for mingw, it should already work. |
I agree. I just don't agree to inventing a fourth line of code (custom cmake) in addition to powershell (exists), original cmake (needs cmake glue), and vcpkg (needs C++ code and cmake glue). |
|
Or should I try using pwsh as a tool for vcpkg? However, there are still some cross-platform libraries, such as Qt, that require special handling. |
|
@dg0yt https://github.com/zynfly/vcpkg/tree/feature/add-pwsh-tool-clean If pwsh is not available, let vcpkg download it automatically. |
Description
This PR enables automatic copying of tool dependencies when cross-compiling from macOS/Linux to Windows targets with dynamic linkage (e.g.,
x64-mingw-dynamic).Problem
When cross-compiling to Windows from non-Windows hosts, tools built with dynamic linkage were missing their vcpkg DLL dependencies in the tools directory. This caused runtime errors when attempting to use these tools on Windows, as they couldn't find required DLLs like
libbrotlidec.dll.Example failure scenario:
Solution
Enhanced
vcpkg_copy_tool_dependencies.cmaketo handle cross-compilation scenarios:applocal.ps1solution (no change)objdumpto analyze PE dependencies and recursively copy vcpkg DLLsobjdumpis not available, warns but doesn't fail the buildImplementation Details
Added two new internal functions:
z_vcpkg_resolve_pe_dependencies(): Analyzes PE binaries using objdump to extract DLL dependencies, searches for them in vcpkg directories, and copies found DLLs to the tool directory.z_vcpkg_copy_tool_dependencies_cross_compile(): Coordinates the cross-compilation dependency copying by finding an appropriate objdump tool and recursively processing tool binaries and their dependencies.The implementation:
Testing
Test package:
brotli:x64-mingw-dynamicTest environment: macOS → Windows x64 (MinGW cross-compilation)
objdump tool:
x86_64-w64-mingw32-objdumpBefore this change:
After this change:
Dependency verification:
Compatibility
Performance Impact