Skip to content

scripts: Add PowerShell Core tool for cross-platform dependency deployment#49890

Closed
zynfly wants to merge 1 commit intomicrosoft:masterfrom
zynfly:feature/add-pwsh-tool-clean
Closed

scripts: Add PowerShell Core tool for cross-platform dependency deployment#49890
zynfly wants to merge 1 commit intomicrosoft:masterfrom
zynfly:feature/add-pwsh-tool-clean

Conversation

@zynfly
Copy link
Contributor

@zynfly zynfly commented Feb 9, 2026

Summary

This PR enables cross-compilation from macOS/Linux hosts to Windows targets by providing PowerShell Core as a vcpkg-managed tool and fixing cross-platform PE dependency analysis.

Problem Description

When cross-compiling to Windows from non-Windows hosts (e.g., ./vcpkg install brotli:x64-mingw-dynamic on macOS), tools are missing required DLL dependencies:

Before this PR:

packages/brotli_x64-mingw-dynamic/tools/brotli/
└── brotli.exe  ← Missing libbrotlidec.dll, libbrotlienc.dll

Root causes:

  1. vcpkg_copy_tool_dependencies.cmake required system-installed PowerShell Core, which may not be available
  2. applocal.ps1 regex pattern only matched GNU objdump output format (tab-based), not BSD/macOS objdump (space-based)

Solution

1. Add PowerShell Core as vcpkg-managed tool

  • New file: scripts/cmake/vcpkg_find_acquire_program(PWSH).cmake
  • Downloads PowerShell Core 7.5.4 for 7 platforms:
    • Windows: x86, x64, arm64
    • macOS: x64, arm64
    • Linux: x64, arm64
  • Automatically sets execute permissions on Unix platforms

2. Use vcpkg-managed PowerShell

  • Modified: scripts/cmake/vcpkg_copy_tool_dependencies.cmake
  • Changed from find_program(pwsh) to vcpkg_find_acquire_program(PWSH)
  • Eliminates dependency on system-installed PowerShell

3. Fix cross-platform objdump compatibility

  • Modified: scripts/buildsystems/msbuild/applocal.ps1
  • Updated regex from ^\tDLL Name: to ^[\t ]+DLL Name:
  • Supports both GNU objdump (tab) and BSD/macOS objdump (spaces)

Test Plan

Tested on macOS arm64 with MinGW cross-compilation:

./vcpkg install brotli:x64-mingw-dynamic --no-binarycaching

Result: ✅ Success

packages/brotli_x64-mingw-dynamic/tools/brotli/
├── brotli.exe
├── libbrotlidec.dll       ← Direct dependency ✓
├── libbrotlienc.dll       ← Direct dependency ✓
└── libbrotlicommon.dll    ← Recursive dependency ✓

Verified:

  • PowerShell Core automatically downloaded and cached
  • All vcpkg DLLs correctly identified and copied
  • System DLLs correctly skipped
  • Recursive dependencies (DLL → DLL) handled correctly

Impact

  • Zero breaking changes: Only affects Windows PE tools in cross-compilation scenarios
  • Backward compatible: Windows native builds continue using existing logic
  • Platform consistency: macOS, Linux, Windows use same tool and workflow
  • No manual setup: Users don't need to install PowerShell Core manually

🤖 Generated with Claude Code

…yment

This change enables cross-compilation from macOS/Linux hosts to Windows targets
by providing PowerShell Core as a vcpkg-managed tool, eliminating the requirement
for system-installed PowerShell.

Changes:
- Add vcpkg_find_acquire_program(PWSH).cmake: Downloads PowerShell Core 7.5.4
  for 7 platforms (Windows x86/x64/arm64, macOS arm64/x64, Linux x64/arm64)
- Update vcpkg_copy_tool_dependencies.cmake: Use vcpkg-managed PowerShell instead
  of system-installed pwsh
- Fix applocal.ps1: Support both GNU objdump (tab) and BSD objdump (spaces) output
  formats for cross-platform PE dependency analysis

Tested with brotli:x64-mingw-dynamic on macOS arm64, successfully deploying
libbrotlidec.dll, libbrotlienc.dll, and libbrotlicommon.dll to tools directory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zynfly
Copy link
Contributor Author

zynfly commented Feb 9, 2026

Replace this PR
#49887

@zynfly zynfly marked this pull request as draft February 9, 2026 12:31
@zynfly zynfly marked this pull request as ready for review February 9, 2026 13:15
@zynfly zynfly marked this pull request as draft February 9, 2026 13:18
@zynfly zynfly marked this pull request as ready for review February 9, 2026 13:21
Comment on lines +1 to +54
# PowerShell Core - Cross-platform shell and scripting language
# Used by vcpkg for cross-platform tool dependency deployment

set(program_name pwsh)
set(program_version 7.5.4)

if(CMAKE_HOST_WIN32)
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(archive_name "PowerShell-${program_version}-win-x86.zip")
set(download_sha512 221ddfc685ccb497d26fbdbc6a2d198460e082934a683cade961057282616b85a1f1e9e91e9e01e4a0b36fb3c523fd9983884c62f5c917ea70fd2dd9dfa4a85e)
set(tool_subdirectory "${program_version}-win-x86")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(archive_name "PowerShell-${program_version}-win-arm64.zip")
set(download_sha512 5cdc32ecfe5a9fee17194c136a076876e6ebf255004e8890535beefbbaa0d38867712a7a65fc33717fc2a599a1c8a070d8c947d773289e4e0cfa8e4c9927501f)
set(tool_subdirectory "${program_version}-win-arm64")
else()
set(archive_name "PowerShell-${program_version}-win-x64.zip")
set(download_sha512 fb5af273bd5fe7293dbf34a9476a74a9d3ffbaaf5dcc47d986ba69a716f3c77b8285f94c15cfcb9ff764fa210c359e8721d1c9d46dc4394143a4206863bb3cf4)
set(tool_subdirectory "${program_version}-win-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(archive_name "powershell-${program_version}-osx-arm64.tar.gz")
set(download_sha512 c93ffabdd01fa967bce32201dd9053409967d784f6bea6ce8edd19fb02ecaab15ad697518ff2202f19ee2c62781e17eb8b52bd970498554f931b0f23eb3226dc)
set(tool_subdirectory "${program_version}-osx-arm64")
else()
set(archive_name "powershell-${program_version}-osx-x64.tar.gz")
set(download_sha512 350fef6fe9f18a7d85a5ea09374eb64c6198d389a24080984c0909601490decf21b0ec65b74248ad56c22bfea95bc745a7c9d1edd20bdeb276a905278a09c2c0)
set(tool_subdirectory "${program_version}-osx-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
# PowerShell tar.gz archives don't have execute permission, so we need to add it
set(post_install_command chmod a+x pwsh)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
set(archive_name "powershell-${program_version}-linux-arm64.tar.gz")
set(download_sha512 ef721f209842f13a560a21373744ab953ee8af41a60a0ed2f434131f85f4cd1b11565e3615df538a7d78cb5dd2096e9e2ccb42f4ffda79208c80f5206bb40cad)
set(tool_subdirectory "${program_version}-linux-arm64")
else()
set(archive_name "powershell-${program_version}-linux-x64.tar.gz")
set(download_sha512 6ff028cee3b23c71136de736ae5a93beb7b625215db3398b034fbdb0dd7b034ebf53da32cc47880982f7506054514e9af3cc5defcb4d69a7dd4a08a766469f0b)
set(tool_subdirectory "${program_version}-linux-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
# PowerShell tar.gz archives don't have execute permission, so we need to add it
set(post_install_command chmod a+x pwsh)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# PowerShell Core - Cross-platform shell and scripting language
# Used by vcpkg for cross-platform tool dependency deployment
set(program_name pwsh)
set(program_version 7.5.4)
if(CMAKE_HOST_WIN32)
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86")
set(archive_name "PowerShell-${program_version}-win-x86.zip")
set(download_sha512 221ddfc685ccb497d26fbdbc6a2d198460e082934a683cade961057282616b85a1f1e9e91e9e01e4a0b36fb3c523fd9983884c62f5c917ea70fd2dd9dfa4a85e)
set(tool_subdirectory "${program_version}-win-x86")
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64")
set(archive_name "PowerShell-${program_version}-win-arm64.zip")
set(download_sha512 5cdc32ecfe5a9fee17194c136a076876e6ebf255004e8890535beefbbaa0d38867712a7a65fc33717fc2a599a1c8a070d8c947d773289e4e0cfa8e4c9927501f)
set(tool_subdirectory "${program_version}-win-arm64")
else()
set(archive_name "PowerShell-${program_version}-win-x64.zip")
set(download_sha512 fb5af273bd5fe7293dbf34a9476a74a9d3ffbaaf5dcc47d986ba69a716f3c77b8285f94c15cfcb9ff764fa210c359e8721d1c9d46dc4394143a4206863bb3cf4)
set(tool_subdirectory "${program_version}-win-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm64")
set(archive_name "powershell-${program_version}-osx-arm64.tar.gz")
set(download_sha512 c93ffabdd01fa967bce32201dd9053409967d784f6bea6ce8edd19fb02ecaab15ad697518ff2202f19ee2c62781e17eb8b52bd970498554f931b0f23eb3226dc)
set(tool_subdirectory "${program_version}-osx-arm64")
else()
set(archive_name "powershell-${program_version}-osx-x64.tar.gz")
set(download_sha512 350fef6fe9f18a7d85a5ea09374eb64c6198d389a24080984c0909601490decf21b0ec65b74248ad56c22bfea95bc745a7c9d1edd20bdeb276a905278a09c2c0)
set(tool_subdirectory "${program_version}-osx-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
# PowerShell tar.gz archives don't have execute permission, so we need to add it
set(post_install_command chmod a+x pwsh)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
set(archive_name "powershell-${program_version}-linux-arm64.tar.gz")
set(download_sha512 ef721f209842f13a560a21373744ab953ee8af41a60a0ed2f434131f85f4cd1b11565e3615df538a7d78cb5dd2096e9e2ccb42f4ffda79208c80f5206bb40cad)
set(tool_subdirectory "${program_version}-linux-arm64")
else()
set(archive_name "powershell-${program_version}-linux-x64.tar.gz")
set(download_sha512 6ff028cee3b23c71136de736ae5a93beb7b625215db3398b034fbdb0dd7b034ebf53da32cc47880982f7506054514e9af3cc5defcb4d69a7dd4a08a766469f0b)
set(tool_subdirectory "${program_version}-linux-x64")
endif()
set(download_urls "https://github.com/PowerShell/PowerShell/releases/download/v${program_version}/${archive_name}")
set(download_filename "${archive_name}")
set(paths_to_search "${DOWNLOADS}/tools/powershell-core-${tool_subdirectory}")
# PowerShell tar.gz archives don't have execute permission, so we need to add it
set(post_install_command chmod a+x pwsh)
endif()
z_use_vcpkg_fetch(powershell-core)

And add entries to scripts/vcpkg-tools.json for the missing platforms

The # PowerShell tar.gz archives don't have execute permission, so we need to add it part may need to be fixed up in vcpkg fetch itself sadly :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that other tools, such as coscli, also do not have executable permissions on Linux and macOS. This should be the same as pwsh. How can we handle this more elegantly?

Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should finally just wire up https://github.com/microsoft/vcpkg-tool/blob/main/src/vcpkg/commands.z-applocal.cpp one of these days :/

The only true blocker here is the invalidated authenticode signature.

# tIl2kFAoHb2cc1Cmr+A=
# SIG # End signature block

# SIG # Begin signature block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have invalidated the signature. This change needs to be made over in https://github.com/microsoft/vcpkg-tool/blob/main/scripts/applocal.ps1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed this C++ code, which is only enabled for WIN32. Should I modify this C++ code to replace the modifications made by pwsh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants