diff --git a/.gitignore b/.gitignore index b46c39e263..722d193462 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ settings.json [Rr]eleases/ x64/ x86/ +arm64/ AnyCPU/ Fuzzing/ bld/ diff --git a/src/VcpkgPortOverlay/CreatePortOverlay.ps1 b/src/VcpkgPortOverlay/CreatePortOverlay.ps1 index 6cda2cedff..f3ff774fb8 100644 --- a/src/VcpkgPortOverlay/CreatePortOverlay.ps1 +++ b/src/VcpkgPortOverlay/CreatePortOverlay.ps1 @@ -208,6 +208,44 @@ function Add-PatchToPortFile $modifiedPortFile | Out-File $portFilePath } +# Removes all patches from portfile.cmake +function Remove-PortPatches +{ + param( + [Parameter(Mandatory)] + [string]$Port + ) + + # Look for the line that says "PATCHES" + + $portFilePath = Join-Path $OverlayRoot $Port "portfile.cmake" + $originalPortFile = Get-Content $portFilePath + + $modifiedPortFile = @() + foreach ($line in $originalPortFile) + { + if ($line.TrimEnd().EndsWith("PATCHES")) + { + $foundPatches = $true + } + elseif ($line -eq ")") + { + $foundParen = $true + $modifiedPortFile += $line + } + elseif ($foundPatches -and -not $foundParen) + { + # Drop line + } + else + { + $modifiedPortFile += $line + } + } + + $modifiedPortFile | Out-File $portFilePath +} + # Adds a patch to a port function Add-PatchToPort { @@ -275,13 +313,12 @@ function Update-PortSource [Parameter(Mandatory)] [string]$Commit, [Parameter(Mandatory)] - [string]$SourceHash + [string]$SourceHash, + [string]$RefPattern = '[0-9a-f]{40}( #.*)?$' ) - $portDir = Join-Path $OverlayRoot $Port - # For the REF, we also delete any comments after it that may say the wrong version - Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern '[0-9a-f]{40}( #.*)?$' -NewValue "$Commit # Unreleased" + Set-ParameterInPortFile $Port -ParameterName 'REF' -CurrentValuePattern $RefPattern -NewValue "$Commit # Unreleased" Set-ParameterInPortFile $Port -ParameterName 'SHA512' -CurrentValuePattern '[0-9a-f]{128}' -NewValue $SourceHash } @@ -302,6 +339,10 @@ function Update-PortVersion New-PortOverlay cpprestsdk -Version 2.10.18 -PortVersion 4 Add-PatchToPort cpprestsdk -PatchRepo 'microsoft/winget-cli' -PatchCommit '888b4ed8f4f7d25cb05a47210e083fe29348163b' -PatchName 'add-server-certificate-validation.patch' -PatchRoot 'src/cpprestsdk/cpprestsdk' +New-PortOverlay detours -Version 4.0.1 -PortVersion 8 +Update-PortSource detours -RefPattern 'v4.0.1' -Commit '404c153ff390cb14f1787c7feeb4908c6d79b0ab' -SourceHash '1f3f26657927fa153116dce13dbfa3319ea368e6c9017f4999b6ec24d6356c335b3d5326718d3ec707b92832763ffea092088df52596f016d7ca9b8127f7033d' +Remove-PortPatches detours + New-PortOverlay libyaml -Version 0.2.5 -PortVersion 5 Update-PortSource libyaml -Commit '840b65c40675e2d06bf40405ad3f12dec7f35923' -SourceHash 'de85560312d53a007a2ddf1fe403676bbd34620480b1ba446b8c16bb366524ba7a6ed08f6316dd783bf980d9e26603a9efc82f134eb0235917b3be1d3eb4b302' Update-PortVersion libyaml diff --git a/src/VcpkgPortOverlay/README.md b/src/VcpkgPortOverlay/README.md index e8063e8081..9b38261af4 100644 --- a/src/VcpkgPortOverlay/README.md +++ b/src/VcpkgPortOverlay/README.md @@ -12,7 +12,18 @@ Note that we use v2.10.18, which is not the latest. Changes: * Add patch file: `add-server-certificate-validation.patch` - Patch source: https://github.com/microsoft/winget-cli/commit/888b4ed8f4f7d25cb05a47210e083fe29348163b +* Patch source: https://github.com/microsoft/winget-cli/commit/888b4ed8f4f7d25cb05a47210e083fe29348163b + +## detours + +We use the version used by UndockedRegFreeWinRT (https://github.com/microsoft/winget-cli/tree/release-v1.10/src/Xlang/UndockedRegFreeWinRT/src/UndockedRegFreeWinRT/detours). +The only official release of detours (4.0.1) does not include complete support for ARM64. +While the exact version that we pulled from UndockedRegFreeWinRT is unclear (https://github.com/microsoft/xlang/pull/644), through manually comparing versions it is equivalent to +https://github.com/microsoft/Detours/commit/404c153ff390cb14f1787c7feeb4908c6d79b0ab (only some whitespace changes are present). + +Changes: +* New source commit: https://github.com/microsoft/Detours/commit/404c153ff390cb14f1787c7feeb4908c6d79b0ab +* Remove the patch on the official port as it is already present in the newer commit ## libyaml diff --git a/src/VcpkgPortOverlay/detours/find-jmp-bounds-arm64.patch b/src/VcpkgPortOverlay/detours/find-jmp-bounds-arm64.patch new file mode 100644 index 0000000000..21390cec05 --- /dev/null +++ b/src/VcpkgPortOverlay/detours/find-jmp-bounds-arm64.patch @@ -0,0 +1,24 @@ +diff --git a/src/detours.cpp b/src/detours.cpp +index 8345c4d..3cd0e9d 100644 +--- a/src/detours.cpp ++++ b/src/detours.cpp +@@ -974,6 +974,19 @@ inline PBYTE detour_skip_jmp(PBYTE pbCode, PVOID *ppGlobals) + return pbCode; + } + ++inline void detour_find_jmp_bounds(PBYTE pbCode, ++ PDETOUR_TRAMPOLINE *ppLower, ++ PDETOUR_TRAMPOLINE *ppUpper) ++{ ++ // We have to place trampolines within +/- 2GB of code. ++ ULONG_PTR lo = detour_2gb_below((ULONG_PTR)pbCode); ++ ULONG_PTR hi = detour_2gb_above((ULONG_PTR)pbCode); ++ DETOUR_TRACE(("[%p..%p..%p]\n", lo, pbCode, hi)); ++ ++ *ppLower = (PDETOUR_TRAMPOLINE)lo; ++ *ppUpper = (PDETOUR_TRAMPOLINE)hi; ++} ++ + inline BOOL detour_does_code_end_function(PBYTE pbCode) + { + ULONG Opcode = fetch_opcode(pbCode); diff --git a/src/VcpkgPortOverlay/detours/portfile.cmake b/src/VcpkgPortOverlay/detours/portfile.cmake new file mode 100644 index 0000000000..1a025f9a04 --- /dev/null +++ b/src/VcpkgPortOverlay/detours/portfile.cmake @@ -0,0 +1,34 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO microsoft/Detours + REF 404c153ff390cb14f1787c7feeb4908c6d79b0ab # Unreleased + SHA512 1f3f26657927fa153116dce13dbfa3319ea368e6c9017f4999b6ec24d6356c335b3d5326718d3ec707b92832763ffea092088df52596f016d7ca9b8127f7033d + HEAD_REF master +) + +vcpkg_build_nmake( + SOURCE_PATH "${SOURCE_PATH}" + PROJECT_SUBPATH "src" + PROJECT_NAME "Makefile" + OPTIONS "PROCESSOR_ARCHITECTURE=${VCPKG_TARGET_ARCHITECTURE}" + OPTIONS_RELEASE "DETOURS_CONFIG=Release" + OPTIONS_DEBUG "DETOURS_CONFIG=Debug" +) + +if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/lib.${VCPKG_TARGET_ARCHITECTURE}Release/" DESTINATION "${CURRENT_PACKAGES_DIR}/lib") +endif() +if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/lib.${VCPKG_TARGET_ARCHITECTURE}Debug/" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib") +endif() + +if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/include/" DESTINATION "${CURRENT_PACKAGES_DIR}/include" RENAME detours) +else() + file(INSTALL "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/include/" DESTINATION "${CURRENT_PACKAGES_DIR}/include" RENAME detours) +endif() + +file(INSTALL "${SOURCE_PATH}/LICENSE.md" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/src/VcpkgPortOverlay/detours/usage b/src/VcpkgPortOverlay/detours/usage new file mode 100644 index 0000000000..00f978fb68 --- /dev/null +++ b/src/VcpkgPortOverlay/detours/usage @@ -0,0 +1,7 @@ +detours can be used from CMake via: + + find_path(DETOURS_INCLUDE_DIRS "detours/detours.h") + find_library(DETOURS_LIBRARY detours REQUIRED) + + target_include_directories(main PRIVATE ${DETOURS_INCLUDE_DIRS}) + target_link_libraries(main PRIVATE ${DETOURS_LIBRARY}) diff --git a/src/VcpkgPortOverlay/detours/vcpkg.json b/src/VcpkgPortOverlay/detours/vcpkg.json new file mode 100644 index 0000000000..b0f745daf6 --- /dev/null +++ b/src/VcpkgPortOverlay/detours/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "detours", + "version": "4.0.1", + "port-version": 8, + "description": "Detours is a software package for monitoring and instrumenting API calls on Windows.", + "homepage": "https://github.com/microsoft/Detours", + "license": "MIT", + "supports": "windows & !uwp" +}