From 971e559c8e23f5b1699d6749e75de7b67182f496 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Thu, 9 Jul 2026 05:37:15 +0000 Subject: [PATCH 01/11] [libtorch] update to 2.13.0 --- ports/libtorch/fix-system-fmt.patch | 19 ++-- ports/libtorch/fix-windows-install-dirs.patch | 97 +++++++++++-------- ports/libtorch/portfile.cmake | 2 +- ports/libtorch/vcpkg.json | 2 +- versions/baseline.json | 2 +- versions/l-/libtorch.json | 5 + 6 files changed, 71 insertions(+), 56 deletions(-) diff --git a/ports/libtorch/fix-system-fmt.patch b/ports/libtorch/fix-system-fmt.patch index ef1b28ffa230b0..072d79fdc2118f 100644 --- a/ports/libtorch/fix-system-fmt.patch +++ b/ports/libtorch/fix-system-fmt.patch @@ -1,7 +1,8 @@ +diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake +index 2baa187..65f9e01 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake -@@ -1597,22 +1597,24 @@ - # Install `fmtlib` header. +@@ -1633,6 +1633,7 @@ endif() # This was the default behavior before version 12.0.0. # Since PyTorch C API depends on it, make it available for projects that # depend on PyTorch. @@ -9,16 +10,9 @@ set(FMT_INSTALL ON) set(TEMP_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}) set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libs" FORCE) - add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/fmt) - - # Disable compiler feature checks for `fmt`. - # - # CMake compiles a little program to check compiler features. Some of our build - # configurations (notably the mobile build analyzer) will populate - # CMAKE_CXX_FLAGS in ways that break feature checks. Since we already know - # `fmt` is compatible with a superset of the compilers that PyTorch is, it - # shouldn't be too bad to just disable the checks. - set_target_properties(fmt-header-only PROPERTIES INTERFACE_COMPILE_FEATURES "") +@@ -1658,8 +1659,9 @@ target_compile_definitions(fmt PUBLIC "FMT_NO_UNIQUE_ADDRESS=${_fmt_no_unique_ad + target_compile_definitions(fmt-header-only INTERFACE "FMT_NO_UNIQUE_ADDRESS=${_fmt_no_unique_address}") + unset(_fmt_no_unique_address) +endif() +find_package(fmt REQUIRED) @@ -26,3 +20,4 @@ -set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE) # ---[ Kineto + # edge profiler depends on KinetoProfiler but it only does cpu diff --git a/ports/libtorch/fix-windows-install-dirs.patch b/ports/libtorch/fix-windows-install-dirs.patch index eedeaca402c595..ee87416dc364bc 100644 --- a/ports/libtorch/fix-windows-install-dirs.patch +++ b/ports/libtorch/fix-windows-install-dirs.patch @@ -1,6 +1,8 @@ +diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt +index bd138d2..8e63fe8 100644 --- a/c10/CMakeLists.txt +++ b/c10/CMakeLists.txt -@@ -161,7 +161,10 @@ +@@ -162,7 +162,10 @@ if(NOT BUILD_LIBTORCHLESS) # Note: for now, we will put all export path into one single Caffe2Targets group # to deal with the cmake deployment need. Inside the Caffe2Targets set, the # individual libraries like libc10.so and libcaffe2.so are still self-contained. @@ -12,9 +14,11 @@ endif() install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR} +diff --git a/c10/cuda/CMakeLists.txt b/c10/cuda/CMakeLists.txt +index a337614..425287e 100644 --- a/c10/cuda/CMakeLists.txt +++ b/c10/cuda/CMakeLists.txt -@@ -86,7 +86,10 @@ +@@ -86,7 +86,10 @@ if(NOT BUILD_LIBTORCHLESS) # Note: for now, we will put all export path into one single Caffe2Targets group # to deal with the cmake deployment need. Inside the Caffe2Targets set, the # individual libraries like libc10.so and libcaffe2.so are still self-contained. @@ -26,9 +30,11 @@ endif() +diff --git a/c10/hip/CMakeLists.txt b/c10/hip/CMakeLists.txt +index 0f86f03..64e0bb3 100644 --- a/c10/hip/CMakeLists.txt +++ b/c10/hip/CMakeLists.txt -@@ -56,7 +56,10 @@ +@@ -52,7 +52,10 @@ if(NOT BUILD_LIBTORCHLESS) $ $ $) @@ -40,9 +46,11 @@ set(C10_HIP_LIB c10_hip) endif() +diff --git a/c10/xpu/CMakeLists.txt b/c10/xpu/CMakeLists.txt +index 349b209..b1ba10e 100644 --- a/c10/xpu/CMakeLists.txt +++ b/c10/xpu/CMakeLists.txt -@@ -49,7 +49,10 @@ +@@ -49,7 +49,10 @@ if(NOT BUILD_LIBTORCHLESS) $ $ ) @@ -54,9 +62,11 @@ set(C10_XPU_LIB c10_xpu) add_subdirectory(test) endif() +diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt +index e4a0454..2901fc4 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt -@@ -573,7 +573,10 @@ +@@ -561,7 +561,10 @@ if(USE_CUDA) endif() target_link_libraries(caffe2_nvrtc PRIVATE caffe2::nvrtc ${DELAY_LOAD_FLAGS}) @@ -68,7 +78,7 @@ if(USE_NCCL) list(APPEND Caffe2_GPU_SRCS ${TORCH_SRC_DIR}/csrc/cuda/nccl.cpp) -@@ -656,7 +659,10 @@ +@@ -645,7 +648,10 @@ if(USE_ROCM) target_link_libraries(caffe2_nvrtc hip::amdhip64 hiprtc::hiprtc) target_include_directories(caffe2_nvrtc PRIVATE ${CMAKE_BINARY_DIR}) target_compile_definitions(caffe2_nvrtc PRIVATE USE_ROCM __HIP_PLATFORM_AMD__) @@ -80,7 +90,7 @@ endif() if(NOT NO_API AND NOT BUILD_LITE_INTERPRETER) -@@ -1067,7 +1073,10 @@ +@@ -1065,7 +1071,10 @@ elseif(USE_CUDA) target_compile_definitions(torch_cuda PUBLIC USE_NVSHMEM) target_compile_definitions(torch_nvshmem PUBLIC USE_NVSHMEM) target_link_libraries(torch_cuda PRIVATE torch_nvshmem) @@ -92,7 +102,7 @@ else() message(STATUS "NVSHMEM not found, not building with NVSHMEM support.") endif() -@@ -1130,7 +1139,10 @@ +@@ -1128,7 +1137,10 @@ elseif(USE_CUDA) CUDA::culibos ${CMAKE_DL_LIBS}) endif() set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/../aten/src/ATen/native/cuda/LinearAlgebraStubs.cpp PROPERTIES COMPILE_FLAGS "-DBUILD_LAZY_CUDA_LINALG") @@ -104,20 +114,20 @@ endif() if(USE_PRECOMPILED_HEADERS) -@@ -1528,8 +1540,10 @@ - target_link_libraries(torch_rocshmem PRIVATE roc::rocshmem) - target_link_libraries(torch_hip PRIVATE torch_rocshmem) +@@ -1520,8 +1532,10 @@ if(USE_ROCM) + target_link_libraries(torch_rocshmem PRIVATE roc::rocshmem) + target_link_libraries(torch_hip PRIVATE torch_rocshmem) -- install(TARGETS torch_rocshmem EXPORT Caffe2Targets DESTINATION -- "${TORCH_INSTALL_LIB_DIR}") -+ install(TARGETS torch_rocshmem EXPORT Caffe2Targets -+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}" -+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}" -+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}") - elseif(rocshmem_FOUND) - message(STATUS - "rocSHMEM found but skipped: PYTORCH_ROCM_ARCH has no entry in " -@@ -1676,17 +1690,32 @@ +- install(TARGETS torch_rocshmem EXPORT Caffe2Targets DESTINATION +- "${TORCH_INSTALL_LIB_DIR}") ++ install(TARGETS torch_rocshmem EXPORT Caffe2Targets ++ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}" ++ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}" ++ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}") + else() + message(STATUS + "rocSHMEM found but skipped: PYTORCH_ROCM_ARCH has no entry in " +@@ -1673,17 +1687,32 @@ endif() caffe2_interface_library(torch torch_library) @@ -155,7 +165,7 @@ target_link_libraries(torch PUBLIC torch_cpu_library) -@@ -1829,7 +1858,10 @@ +@@ -1826,7 +1855,10 @@ if(BUILD_SHARED_LIBS) target_link_libraries(torch_global_deps torch::nvtoolsext) endif() endif() @@ -167,23 +177,11 @@ endif() # ---[ Caffe2 HIP sources. ---- a/torch/CMakeLists.txt -+++ b/torch/CMakeLists.txt -@@ -459,7 +459,10 @@ - set_target_properties(torch_python PROPERTIES LINK_FLAGS ${TORCH_PYTHON_LINK_FLAGS}) - endif() - --install(TARGETS torch_python DESTINATION "${TORCH_INSTALL_LIB_DIR}") -+install(TARGETS torch_python -+ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}" -+ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}" -+ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}") - - # Generate torch/version.py from the appropriate CMake cache variables. - if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") +diff --git a/test/cpp/c10d/CMakeLists.txt b/test/cpp/c10d/CMakeLists.txt +index aa98db5..616bba8 100644 --- a/test/cpp/c10d/CMakeLists.txt +++ b/test/cpp/c10d/CMakeLists.txt -@@ -79,7 +79,10 @@ +@@ -80,7 +80,10 @@ if(USE_CUDA) LINK_LIBRARIES torch_cpu c10d_cuda_test gtest_main __caffe2_nccl INSTALL_TEST ${INSTALL_TEST}) target_compile_definitions(NCCLDevCommManagerTest PRIVATE USE_CUDA USE_NCCL) if(INSTALL_TEST) @@ -195,7 +193,7 @@ endif() endif() if(USE_UCC AND USE_C10D_UCC) -@@ -91,7 +94,10 @@ +@@ -92,7 +95,10 @@ if(USE_CUDA) ProcessGroupUCCTest.cpp LINK_LIBRARIES torch_cpu c10d_cuda_test gtest_main __caffe2_ucc INSTALL_TEST ${INSTALL_TEST}) if(INSTALL_TEST) @@ -207,7 +205,7 @@ endif() endif() elseif(USE_ROCM) -@@ -107,7 +113,10 @@ +@@ -108,7 +114,10 @@ elseif(USE_ROCM) hip/ProcessGroupNCCLErrorsTest.cpp LINK_LIBRARIES torch_cpu c10d_hip_test gtest_main __caffe2_nccl INSTALL_TEST ${INSTALL_TEST}) if(INSTALL_TEST) @@ -219,7 +217,7 @@ endif() endif() if(USE_UCC AND USE_C10D_UCC) -@@ -115,7 +124,10 @@ +@@ -116,7 +125,10 @@ elseif(USE_ROCM) hip/ProcessGroupUCCTest.cpp LINK_LIBRARIES torch_cpu c10d_hip_test gtest_main __caffe2_ucc INSTALL_TEST ${INSTALL_TEST}) if(INSTALL_TEST) @@ -231,9 +229,11 @@ endif() endif() else() +diff --git a/test/cpp/jit/CMakeLists.txt b/test/cpp/jit/CMakeLists.txt +index 552f8cf..2299940 100644 --- a/test/cpp/jit/CMakeLists.txt +++ b/test/cpp/jit/CMakeLists.txt -@@ -32,9 +32,18 @@ +@@ -32,9 +32,18 @@ endif() target_link_libraries(backend_with_compiler torch) if(INSTALL_TEST) @@ -255,4 +255,19 @@ endif() # Build the cpp gtest binary containing the cpp-only tests. +diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt +index 23aa88d..2381304 100644 +--- a/torch/CMakeLists.txt ++++ b/torch/CMakeLists.txt +@@ -439,7 +439,10 @@ if(NOT TORCH_PYTHON_LINK_FLAGS STREQUAL "") + set_target_properties(torch_python PROPERTIES LINK_FLAGS "${TORCH_PYTHON_LINK_FLAGS}") + endif() + +-install(TARGETS torch_python DESTINATION "${TORCH_INSTALL_LIB_DIR}") ++install(TARGETS torch_python ++ RUNTIME DESTINATION "${TORCH_INSTALL_BIN_DIR}" ++ LIBRARY DESTINATION "${TORCH_INSTALL_LIB_DIR}" ++ ARCHIVE DESTINATION "${TORCH_INSTALL_LIB_DIR}") + # Build the torch._C Python extension module from the thin stub that + # forwards to torch_python. This was historically built by setuptools; diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index fc83a1659f17a3..77338f57399373 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -4,7 +4,7 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO pytorch/pytorch REF "v${VERSION}" - SHA512 f5ab0f6933d88271f772b416f8c9b3b0d3e1ffaf8d00838b455206266b40d7c805e34003d84b01cddc7f1ad917dd72d6f79a05063b0962cbf223d9042cff3206 + SHA512 0f7465835ae9206746d507e1b927afb94f8860248473f2d1c5d71ccd40defbd23d0e3e27a1b09deb907e753a7c9008352830170b53441701ade0916d68a42562 HEAD_REF master PATCHES fix-osx-protobuf.patch diff --git a/ports/libtorch/vcpkg.json b/ports/libtorch/vcpkg.json index c578633192755d..7d3a4295e4e148 100644 --- a/ports/libtorch/vcpkg.json +++ b/ports/libtorch/vcpkg.json @@ -1,6 +1,6 @@ { "name": "libtorch", - "version": "2.12.0", + "version": "2.13.0", "description": "Tensors and Dynamic neural networks in Python with strong GPU acceleration", "homepage": "https://pytorch.org/", "license": null, diff --git a/versions/baseline.json b/versions/baseline.json index 1aab93d91319f0..abf5ece34836c3 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5785,7 +5785,7 @@ "port-version": 3 }, "libtorch": { - "baseline": "2.12.0", + "baseline": "2.13.0", "port-version": 0 }, "libtorrent": { diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 3c3884503c5744..6438b4bf5dfa23 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "7881557b25fc3372ffaf4ae7a154b4162a259f59", + "version": "2.13.0", + "port-version": 0 + }, { "git-tree": "2fa89b0a6cafef5e0abc5a21d72441119738595e", "version": "2.12.0", From eaa4158efd6beaf19741b284c3534c3a7c5feeaa Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 10 Jul 2026 04:54:22 +0000 Subject: [PATCH 02/11] [libtorch] fix XNNPACK imported target type on Windows dynamic triplets Dependencies.cmake's system-xnnpack fallback (used because USE_SYSTEM_LIBS forces USE_SYSTEM_XNNPACK=ON while USE_XNNPACK itself stays off) declares XNNPACK/microkernels-prod as SHARED IMPORTED, but vcpkg's xnnpack port always builds them statically (vcpkg_check_linkage(ONLY_STATIC_LIBRARY)). CMake only enforces IMPORTED_IMPLIB for SHARED imported targets when an actual link step needs them, so this only failed on Windows dynamic-linkage triplets (x64-windows, x64-windows-release) with a generate-time "IMPORTED_IMPLIB not set" error; static-linkage triplets and non-Windows platforms tolerated the mismatch silently. Co-Authored-By: Claude Sonnet 5 --- ports/libtorch/fix-system-xnnpack.patch | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ports/libtorch/fix-system-xnnpack.patch b/ports/libtorch/fix-system-xnnpack.patch index 4df7389dd218dc..4a2e48c2348362 100644 --- a/ports/libtorch/fix-system-xnnpack.patch +++ b/ports/libtorch/fix-system-xnnpack.patch @@ -10,3 +10,17 @@ + list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) +endif() if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK) +@@ -613,7 +619,11 @@ endif() + include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) + list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) + elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) +- add_library(XNNPACK SHARED IMPORTED) +- add_library(microkernels-prod SHARED IMPORTED) ++ # vcpkg's xnnpack port always builds statically (vcpkg_check_linkage(ONLY_STATIC_LIBRARY) ++ # in ports/xnnpack/portfile.cmake); declaring these SHARED leaves IMPORTED_IMPLIB unset, ++ # which fails CMake's generate step on Windows dynamic-linkage triplets (x64-windows, ++ # x64-windows-release) once torch_cpu actually needs to link against them. ++ add_library(XNNPACK STATIC IMPORTED) ++ add_library(microkernels-prod STATIC IMPORTED) + find_library(XNNPACK_LIBRARY XNNPACK) + find_library(microkernels-prod_LIBRARY microkernels-prod) From ef0efd2604ddc5059d99239d12019830888bdb35 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 10 Jul 2026 06:46:11 +0000 Subject: [PATCH 03/11] fixed baseline --- versions/l-/libtorch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 6438b4bf5dfa23..e5ff8f4b5573c3 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "7881557b25fc3372ffaf4ae7a154b4162a259f59", + "git-tree": "c04c632db5dfa8182d4bd42715c137fcaf318246", "version": "2.13.0", "port-version": 0 }, From d1bfe66100323f5dff93903479dc2c3fd3dbd9ba Mon Sep 17 00:00:00 2001 From: Steve brain Date: Mon, 20 Jul 2026 06:34:28 +0000 Subject: [PATCH 04/11] [libtorch] do not install python package data PyTorch 2.13 added cmake/PackageData.cmake, included unconditionally from the top-level CMakeLists.txt. It installs the Python package's data files using destinations relative to CMAKE_INSTALL_PREFIX, which is correct for a wheel build (where the prefix maps to torch/) but under vcpkg resolves to the package root. The type-stub rule is the worst offender: install(DIRECTORY "${TORCH_SRC_DIR}/" DESTINATION "." FILES_MATCHING PATTERN "*.pyi" PATTERN "py.typed") FILES_MATCHING still creates the whole directory skeleton, so the install produced 347 empty directories plus py.typed in the package root, failing both the empty-directories and misplaced-regular-files post-build checks on every triplet that builds this port. The module installs nothing but Python package data and the portfile already configures with -DBUILD_PYTHON=OFF, so guard the include rather than deleting hundreds of paths after the fact. Verified on x64-linux: the port builds with no post-build check problems, the installed tree has no empty directories and no stray package-root entries, and a consumer linking torch builds and runs. --- ports/libtorch/fix-python-package-data.patch | 15 +++++++++++++++ ports/libtorch/portfile.cmake | 1 + versions/l-/libtorch.json | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 ports/libtorch/fix-python-package-data.patch diff --git a/ports/libtorch/fix-python-package-data.patch b/ports/libtorch/fix-python-package-data.patch new file mode 100644 index 00000000000000..0df106c7faa9e1 --- /dev/null +++ b/ports/libtorch/fix-python-package-data.patch @@ -0,0 +1,15 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a64c8d5..12e40d9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1475,7 +1475,9 @@ include(cmake/FileMirroring.cmake) + # headers, etc.) into the torch package. Previously declared via + # setup.py package_data; now consolidated here for both scikit-build-core + # and setuptools builds. +-include(cmake/PackageData.cmake) ++if(BUILD_PYTHON) ++ include(cmake/PackageData.cmake) ++endif() + + include(cmake/PostBuildSteps.cmake) + diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index 77338f57399373..d200cea78df256 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -35,6 +35,7 @@ vcpkg_from_github( fix-cudnn-frontend.patch fix-windows-install-dirs.patch fix-async-mm-cutlass.patch + fix-python-package-data.patch ) file(REMOVE_RECURSE "${SOURCE_PATH}/caffe2/core/macros.h") # We must use generated header files diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index e5ff8f4b5573c3..6d310cef3a5c8e 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "c04c632db5dfa8182d4bd42715c137fcaf318246", + "git-tree": "84edff35cfe0bea729a4207ef31b39837a30e563", "version": "2.13.0", "port-version": 0 }, From e183ddf8a9c627a000376d88bda9a4ed91d7e15b Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 31 Jul 2026 01:50:55 +0000 Subject: [PATCH 05/11] [libtorch] fix glog and CUDA build failures Two CI regressions in the 2.13.0 update: 1. glog (arm64-osx, x64-windows, x64-windows-release) pytorch 2.13 added a second use of glog's internal google::glog_internal_namespace_::IsGoogleLoggingInitialized() in c10/util/Exception.cpp (WarningHandler::process). fix-glog.patch only rewrote the existing call in c10/util/Logging.cpp, so c10 failed to link: Exception.cpp.obj : error LNK2019: unresolved external symbol "bool __cdecl google::glog_internal_namespace_::IsGoogleLoggingInitialized(void)" Apply the same treatment to Exception.cpp: drop the hand-rolled declaration of the internal symbol and call the public google::IsGoogleLoggingInitialized(), which glog 0.7.1 exports from as GLOG_EXPORT. 2. CUDA (x64-linux, x64-windows-release) Configure aborted with: CMake Error at cmake/FileMirroring.cmake:56 (message): CuTeDSL source not found at .../third_party/cutlass/examples/python/ CuTeDSL/blackwell/grouped_gemm.py. FileMirroring.cmake exists purely to populate the Python package tree (SKBUILD_PLATLIB_DIR), and it hard-errors on USE_CUDA when the bundled cutlass submodule is absent -- which it always is, since the port uses system nvidia-cutlass. fix-python-package-data.patch already guarded the sibling include(cmake/PackageData.cmake) with BUILD_PYTHON; guard include(cmake/FileMirroring.cmake) the same way. This also stops the mirroring install() rules from writing into PROJECT_SOURCE_DIR, which is what SKBUILD_PLATLIB_DIR falls back to when scikit-build-core is not driving the build. The port always configures with -DBUILD_PYTHON=OFF (passed after FEATURE_OPTIONS), so neither mirroring nor package data is ever wanted. Verified: all 30 patches apply in order against pristine v2.13.0, and a local libtorch[core,glog]:x64-linux build links libc10 with C10_USE_GLOG defined -- google::IsGoogleLoggingInitialized() resolves and no glog_internal_namespace_ reference to it remains. Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/fix-glog.patch | 30 ++++++++++++++++++++ ports/libtorch/fix-python-package-data.patch | 13 +++++++-- versions/l-/libtorch.json | 2 +- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/ports/libtorch/fix-glog.patch b/ports/libtorch/fix-glog.patch index c3e7d9ad79fb42..9160cb7c8d23ab 100644 --- a/ports/libtorch/fix-glog.patch +++ b/ports/libtorch/fix-glog.patch @@ -45,3 +45,33 @@ } } // namespace c10 +--- a/c10/util/Exception.cpp ++++ b/c10/util/Exception.cpp +@@ -9,18 +9,6 @@ + #include + #include + +-// Google glog's api does not have an external function that allows one to check +-// if glog is initialized or not. It does have an internal function - so we are +-// declaring it here. This is a hack but has been used by a bunch of others too +-// (e.g. Torch, common/init). See also Logging.cpp in this directory. +-#ifdef C10_USE_GLOG +-namespace google { +-namespace glog_internal_namespace_ { +-bool IsGoogleLoggingInitialized(); +-} // namespace glog_internal_namespace_ +-} // namespace google +-#endif +- + namespace c10 { + + Error::Error(std::string msg, Backtrace backtrace, const void* caller) +@@ -265,7 +253,7 @@ + // During static initialization (before InitGoogleLogging), glog's global + // flags may not be constructed yet. Accessing them causes SIOF crashes + // (T253115013, D96553733). Fall back to stderr in that case. +- if (!::google::glog_internal_namespace_::IsGoogleLoggingInitialized()) { ++ if (!::google::IsGoogleLoggingInitialized()) { + std::cerr << warning.source_location().file << ':' + << warning.source_location().line + << ": Warning: " << warning.msg() << " (function " diff --git a/ports/libtorch/fix-python-package-data.patch b/ports/libtorch/fix-python-package-data.patch index 0df106c7faa9e1..e04c533c607d69 100644 --- a/ports/libtorch/fix-python-package-data.patch +++ b/ports/libtorch/fix-python-package-data.patch @@ -1,8 +1,15 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index a64c8d5..12e40d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -1475,7 +1475,9 @@ include(cmake/FileMirroring.cmake) +@@ -1466,13 +1466,17 @@ + # inductor templates, and symlink-replacement copies. Previously handled + # by setup.py; now consolidated here for both scikit-build-core and + # setuptools builds. +-include(cmake/FileMirroring.cmake) ++if(BUILD_PYTHON) ++ include(cmake/FileMirroring.cmake) ++endif() + + # Package data: install non-Python data files (type stubs, templates, # headers, etc.) into the torch package. Previously declared via # setup.py package_data; now consolidated here for both scikit-build-core # and setuptools builds. diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 6d310cef3a5c8e..e53b0fe66eb791 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "84edff35cfe0bea729a4207ef31b39837a30e563", + "git-tree": "2fc53fd612ece5c70bdc493d1844ec34c373eba5", "version": "2.13.0", "port-version": 0 }, From 4018fbf663e18fb417e4e4e8a04861bf39fcb545 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Mon, 3 Aug 2026 23:28:04 +0000 Subject: [PATCH 06/11] [libtorch] avoid build-time cmake regenerate from headeronly glob pytorch 2.13 configure_file()s torch/headeronly/version.h into the source tree from caffe2/CMakeLists.txt, after torch/headeronly/CMakeLists.txt has already taken its CONFIGURE_DEPENDS glob snapshot of *.h. ninja/MSBuild therefore re-run cmake at the start of every build, and that second configure fails for CUDA builds with 'Found two conflicting CUDA versions'. Backport the upstream fix: drop *.h from the glob and list version.h explicitly. Also drop the explanatory comment from fix-system-xnnpack.patch. Its rationale: vcpkg's xnnpack port is static only (vcpkg_check_linkage ONLY_STATIC_LIBRARY), so declaring the imported targets SHARED leaves IMPORTED_IMPLIB unset and fails CMake's generate step on Windows dynamic-linkage triplets. Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/fix-headeronly-glob.patch | 19 +++++++++++++++++++ ports/libtorch/fix-system-xnnpack.patch | 6 +----- ports/libtorch/portfile.cmake | 1 + versions/l-/libtorch.json | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 ports/libtorch/fix-headeronly-glob.patch diff --git a/ports/libtorch/fix-headeronly-glob.patch b/ports/libtorch/fix-headeronly-glob.patch new file mode 100644 index 00000000000000..41f0526e0c112a --- /dev/null +++ b/ports/libtorch/fix-headeronly-glob.patch @@ -0,0 +1,19 @@ +--- a/torch/headeronly/CMakeLists.txt ++++ b/torch/headeronly/CMakeLists.txt +@@ -19,13 +19,15 @@ configure_file( + ${CMAKE_BINARY_DIR}/torch/headeronly/macros/cmake_macros.h) + + file(GLOB HEADERONLY_HEADERS CONFIGURE_DEPENDS +- *.h + core/**/*.h + cpu/**/*.h + macros/*.h + util/*.h + ) + ++set_source_files_properties(version.h PROPERTIES GENERATED TRUE) ++list(APPEND HEADERONLY_HEADERS ${CMAKE_CURRENT_LIST_DIR}/version.h) ++ + add_library(headeronly INTERFACE ${HEADERONLY_HEADERS}) + + install(FILES ${CMAKE_BINARY_DIR}/torch/headeronly/macros/cmake_macros.h diff --git a/ports/libtorch/fix-system-xnnpack.patch b/ports/libtorch/fix-system-xnnpack.patch index 4a2e48c2348362..bdee1c5e884f52 100644 --- a/ports/libtorch/fix-system-xnnpack.patch +++ b/ports/libtorch/fix-system-xnnpack.patch @@ -10,16 +10,12 @@ + list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) +endif() if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK) -@@ -613,7 +619,11 @@ endif() +@@ -613,7 +619,7 @@ endif() include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) - add_library(XNNPACK SHARED IMPORTED) - add_library(microkernels-prod SHARED IMPORTED) -+ # vcpkg's xnnpack port always builds statically (vcpkg_check_linkage(ONLY_STATIC_LIBRARY) -+ # in ports/xnnpack/portfile.cmake); declaring these SHARED leaves IMPORTED_IMPLIB unset, -+ # which fails CMake's generate step on Windows dynamic-linkage triplets (x64-windows, -+ # x64-windows-release) once torch_cpu actually needs to link against them. + add_library(XNNPACK STATIC IMPORTED) + add_library(microkernels-prod STATIC IMPORTED) find_library(XNNPACK_LIBRARY XNNPACK) diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index d200cea78df256..3eae8f7e4a3fd0 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -36,6 +36,7 @@ vcpkg_from_github( fix-windows-install-dirs.patch fix-async-mm-cutlass.patch fix-python-package-data.patch + fix-headeronly-glob.patch ) file(REMOVE_RECURSE "${SOURCE_PATH}/caffe2/core/macros.h") # We must use generated header files diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index e53b0fe66eb791..88167c2e3362e6 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "2fc53fd612ece5c70bdc493d1844ec34c373eba5", + "git-tree": "5ddef093121b300675f9f63c1c02735ad1d8ae41", "version": "2.13.0", "port-version": 0 }, From f6acf14c57bec53ad4f8f8c0c5e4b16ad818ce65 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 7 Aug 2026 00:05:45 +0000 Subject: [PATCH 07/11] [libtorch] address review: xnnpack, moodycamel, miniz, fbgemm Disable XNNPACK unconditionally. PyTorch 2.13 flipped the USE_XNNPACK default to OFF (pytorch/pytorch@61cead47b8) because the backend only serves the deprecated PyTorch Mobile, with ExecuTorch as the replacement. Rather than restore the old default, follow upstream and drop the now unused xnnpack dependency. Upstream's system-XNNPACK fallback in cmake/Dependencies.cmake is gated on USE_SYSTEM_XNNPACK but not on USE_XNNPACK, and USE_SYSTEM_LIBS=ON force-sets the former with a plain set(), so it cannot be turned off from the command line. Left alone it would find_library() XNNPACK behind the disabled flag and FATAL_ERROR once the dependency is gone; that same branch is what the removed x86-windows workaround was papering over. fix-disable-xnnpack.patch adds the missing USE_XNNPACK guard, which makes the whole section inert and lets fix-system-xnnpack.patch go away. Use the vcpkg concurrentqueue port instead of the vendored third_party/concurrentqueue. Its headers install to include/concurrentqueue/moodycamel/, exactly the paths that the public c10/util/Semaphore.h includes on libstdc++, so the GCC fallback is now resolvable from the installed tree. The include_directories() call is kept because torch_cpu compiles torch/nativert sources that include Semaphore.h without linking moodycamel in non-[dist] builds. Install the bundled miniz LICENSE. The vcpkg miniz port cannot be used here: PyTorch's third_party/miniz-3.0.2 is a fork adding a public MZ_ZIP_FLAG_DO_NOT_COMPUTE_CRC32 flag (used in inline_container.cc) and an m_pSeek hook, neither of which exists upstream. It stays vendored and compiled into torch_cpu, so it needs its own notice. Teach upstream's FBGEMM architecture guard the MSVC CMAKE_SYSTEM_PROCESSOR spellings. It accepted only x86_64/aarch64, so x64-windows reported AMD64, warned, and forced USE_FBGEMM OFF while the port still staged fbgemm. The guard's own comment says it exists to reject 32-bit x86, so accepting AMD64/ARM64 matches its intent. Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/fix-disable-xnnpack.patch | 9 +++++++ ports/libtorch/fix-fbgemm-arch-check.patch | 11 +++++++++ .../libtorch/fix-system-concurrentqueue.patch | 10 ++++++++ ports/libtorch/fix-system-xnnpack.patch | 22 ----------------- ports/libtorch/portfile.cmake | 24 +++++++++---------- ports/libtorch/vcpkg.json | 4 ++-- versions/l-/libtorch.json | 2 +- 7 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 ports/libtorch/fix-disable-xnnpack.patch create mode 100644 ports/libtorch/fix-fbgemm-arch-check.patch create mode 100644 ports/libtorch/fix-system-concurrentqueue.patch delete mode 100644 ports/libtorch/fix-system-xnnpack.patch diff --git a/ports/libtorch/fix-disable-xnnpack.patch b/ports/libtorch/fix-disable-xnnpack.patch new file mode 100644 index 00000000000000..11f67491511493 --- /dev/null +++ b/ports/libtorch/fix-disable-xnnpack.patch @@ -0,0 +1,9 @@ +--- a/cmake/Dependencies.cmake ++++ b/cmake/Dependencies.cmake +@@ -610,5 +610,5 @@ if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK) + include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) + list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) +-elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) ++elseif(USE_XNNPACK AND NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) + add_library(XNNPACK SHARED IMPORTED) + add_library(microkernels-prod SHARED IMPORTED) diff --git a/ports/libtorch/fix-fbgemm-arch-check.patch b/ports/libtorch/fix-fbgemm-arch-check.patch new file mode 100644 index 00000000000000..5c566c5c06a24b --- /dev/null +++ b/ports/libtorch/fix-fbgemm-arch-check.patch @@ -0,0 +1,11 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -913,7 +913,7 @@ include(ExternalProject) + + # ---[ Dependencies ---[ FBGEMM doesn't work on x86 32bit and + # CMAKE_SYSTEM_PROCESSOR thinks its 64bit +-if(USE_FBGEMM AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|aarch64)$") ++if(USE_FBGEMM AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|aarch64|ARM64)$") + message(WARNING + "x86_64 or aarch64 required for FBGEMM. " + "Not compiling with FBGEMM. " diff --git a/ports/libtorch/fix-system-concurrentqueue.patch b/ports/libtorch/fix-system-concurrentqueue.patch new file mode 100644 index 00000000000000..c8acca75889206 --- /dev/null +++ b/ports/libtorch/fix-system-concurrentqueue.patch @@ -0,0 +1,10 @@ +--- a/cmake/Dependencies.cmake ++++ b/cmake/Dependencies.cmake +@@ -1774,3 +1774,5 @@ + # Include moodycamel +-add_library(moodycamel INTERFACE IMPORTED) +-include_directories(moodycamel SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/concurrentqueue) ++find_package(concurrentqueue CONFIG REQUIRED) ++add_library(moodycamel ALIAS concurrentqueue::concurrentqueue) ++get_target_property(moodycamel_INCLUDE_DIRS concurrentqueue::concurrentqueue INTERFACE_INCLUDE_DIRECTORIES) ++include_directories(SYSTEM ${moodycamel_INCLUDE_DIRS}) diff --git a/ports/libtorch/fix-system-xnnpack.patch b/ports/libtorch/fix-system-xnnpack.patch deleted file mode 100644 index bdee1c5e884f52..00000000000000 --- a/ports/libtorch/fix-system-xnnpack.patch +++ /dev/null @@ -1,22 +0,0 @@ ---- a/cmake/Dependencies.cmake -+++ b/cmake/Dependencies.cmake -@@ -530,3 +530,9 @@ endif() - - # ---[ XNNPACK -+if(USE_XNNPACK) -+ find_package(unofficial-xnnpack CONFIG REQUIRED) -+ add_library(XNNPACK ALIAS unofficial::xnnpack::XNNPACK) -+ add_library(microkernels-prod ALIAS unofficial::xnnpack::microkernels-prod) -+ list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) -+endif() - if(USE_XNNPACK AND NOT USE_SYSTEM_XNNPACK) -@@ -613,7 +619,7 @@ endif() - include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR}) - list(APPEND Caffe2_DEPENDENCY_LIBS XNNPACK microkernels-prod) - elseif(NOT TARGET XNNPACK AND USE_SYSTEM_XNNPACK) -- add_library(XNNPACK SHARED IMPORTED) -- add_library(microkernels-prod SHARED IMPORTED) -+ add_library(XNNPACK STATIC IMPORTED) -+ add_library(microkernels-prod STATIC IMPORTED) - find_library(XNNPACK_LIBRARY XNNPACK) - find_library(microkernels-prod_LIBRARY microkernels-prod) diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index 3eae8f7e4a3fd0..b349c5f5ee136e 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -20,11 +20,13 @@ vcpkg_from_github( fix-system-flatbuffers.patch fix-system-httplib.patch fix-system-nlohmann.patch + fix-system-concurrentqueue.patch fix-system-pthreadpool.patch fix-system-cpuinfo.patch - fix-system-xnnpack.patch + fix-disable-xnnpack.patch fix-system-onnx.patch fix-system-cutlass.patch + fix-fbgemm-arch-check.patch fix-system-fbgemm.patch fix-system-nnpack.patch fix-system-kleidiai.patch @@ -177,17 +179,6 @@ if(VCPKG_TARGET_IS_LINUX AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") list(APPEND FEATURE_OPTIONS -DUSE_PRIORITIZED_TEXT_FOR_LD=OFF) endif() -if(VCPKG_TARGET_IS_WINDOWS AND VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") - # PyTorch ends up reporting "USE_XNNPACK: OFF" on x86-windows anyway (some - # later guard flips it), but fix-system-xnnpack.patch fires at Dependencies.cmake:530 - # while USE_XNNPACK is still ON and appends XNNPACK + microkernels-prod to - # Caffe2_DEPENDENCY_LIBS. That list never gets cleaned up, and the x86-windows - # imported targets fail the generate-time IMPORTED_IMPLIB check (x64-windows - # tolerates the same shape). Force the option off from the start so our patch - # branch is skipped entirely. - list(APPEND FEATURE_OPTIONS -DUSE_XNNPACK=OFF) -endif() - set(TARGET_IS_MOBILE OFF) if(VCPKG_TARGET_IS_ANDROID OR VCPKG_TARGET_IS_IOS) set(TARGET_IS_MOBILE ON) @@ -224,6 +215,7 @@ vcpkg_cmake_configure( -DUSE_PYTORCH_METAL=OFF -DUSE_PYTORCH_METAL_EXPORT=OFF -DUSE_PYTORCH_QNNPACK:BOOL=OFF + -DUSE_XNNPACK:BOOL=OFF # deprecated with PyTorch Mobile; off by default upstream -DUSE_ITT=OFF -DUSE_OBSERVERS=OFF -DUSE_KINETO=OFF @@ -296,7 +288,13 @@ file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share" ) -vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") +# miniz is a fork carrying PyTorch-specific additions (MZ_ZIP_FLAG_DO_NOT_COMPUTE_CRC32, +# an m_pSeek hook), so it cannot be replaced by the vcpkg miniz port; it is compiled +# into torch_cpu and needs its own notice. +vcpkg_install_copyright(FILE_LIST + "${SOURCE_PATH}/LICENSE" + "${SOURCE_PATH}/third_party/miniz-3.0.2/LICENSE" +) set(VCPKG_POLICY_DLLS_WITHOUT_EXPORTS enabled) # torch_global_deps.dll is empty.c and just for linking deps diff --git a/ports/libtorch/vcpkg.json b/ports/libtorch/vcpkg.json index 7d3a4295e4e148..a39cd96d48075a 100644 --- a/ports/libtorch/vcpkg.json +++ b/ports/libtorch/vcpkg.json @@ -6,6 +6,7 @@ "license": null, "supports": "(windows & !static) | osx | linux", "dependencies": [ + "concurrentqueue", "cpp-httplib", "cpuinfo", "eigen3", @@ -56,8 +57,7 @@ { "name": "vcpkg-get-python-packages", "host": true - }, - "xnnpack" + } ], "default-features": [ "blas" diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 88167c2e3362e6..8d724a152e729b 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "5ddef093121b300675f9f63c1c02735ad1d8ae41", + "git-tree": "3db1d8c5730abd1de81365efd7b18d0039b6c4dd", "version": "2.13.0", "port-version": 0 }, From c8ba49f77f9ca67e9268ac1742f5a9526c9b997d Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 7 Aug 2026 00:29:46 +0000 Subject: [PATCH 08/11] [libtorch] explain what torch_global_deps actually is The old one-liner said the DLL is "just for linking deps", which reads as if a consumer links it; nothing does. It is built from a zero-byte translation unit and exists purely so Python's _load_global_deps() can dlopen it with RTLD_GLOBAL, pulling its own link-time MPI/MKL/CUDA dependencies into the global symbol namespace -- see upstream Note [Global dependencies]. That matters because libtorch is otherwise loaded in a local scope, which breaks libraries like OpenMPI that dlopen plugins expecting their symbols to be globally visible. None of that applies to this port: BUILD_PYTHON=OFF, and _load_global_deps() returns immediately on Windows since there is no RTLD_GLOBAL there. It ships anyway because upstream guards the target only on BUILD_SHARED_LIBS and installs it unconditionally. Being empty, it exports nothing, which is what VCPKG_POLICY_DLLS_WITHOUT_EXPORTS is suppressing. Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/portfile.cmake | 8 +++++++- versions/l-/libtorch.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index b349c5f5ee136e..4cd890239fd80e 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -297,5 +297,11 @@ vcpkg_install_copyright(FILE_LIST ) -set(VCPKG_POLICY_DLLS_WITHOUT_EXPORTS enabled) # torch_global_deps.dll is empty.c and just for linking deps +# torch_global_deps is built from an empty .c file; nothing links it. It exists so that +# Python's _load_global_deps() can dlopen it with RTLD_GLOBAL and thereby pull its own +# link-time deps (MPI/MKL/CUDA) into the global symbol namespace, which OpenMPI-style +# plugin dlopen needs -- see upstream Note [Global dependencies] in caffe2/CMakeLists.txt. +# Irrelevant here (BUILD_PYTHON=OFF, and _load_global_deps returns early on Windows), but +# upstream installs it unconditionally under BUILD_SHARED_LIBS, and being empty it exports nothing. +set(VCPKG_POLICY_DLLS_WITHOUT_EXPORTS enabled) diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 8d724a152e729b..dd34eae51dbc16 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "3db1d8c5730abd1de81365efd7b18d0039b6c4dd", + "git-tree": "b5879954eb1630bb855162475eafba7e35e9a50e", "version": "2.13.0", "port-version": 0 }, From 95619b1d0bca4d75355a85518ad62b59fc5df2b7 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 7 Aug 2026 01:28:15 +0000 Subject: [PATCH 09/11] [libtorch] declare cpuinfo[clog] explicitly fix-system-cpuinfo.patch does add_library(clog ALIAS cpuinfo::clog) unconditionally, but the port never declared the feature that provides that target. It worked only because the xnnpack dependency pulled in cpuinfo[clog] transitively, and dropping xnnpack removed that path: _add_library cannot create ALIAS target "clog" because target "cpuinfo::clog" does not already exist. clog stopped being unconditional in the cpuinfo 2026-04-13 update, so plain cpuinfo now exports no cpuinfo::clog at all. libtorch consumes the target directly and should declare it rather than free-ride on another port's dependency. Only fxdiv was otherwise reachable through xnnpack alone, and fix-system-fxdiv.patch already wraps both of its uses in if(FALSE). Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/vcpkg.json | 7 ++++++- versions/l-/libtorch.json | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ports/libtorch/vcpkg.json b/ports/libtorch/vcpkg.json index a39cd96d48075a..55e0c2bec6d966 100644 --- a/ports/libtorch/vcpkg.json +++ b/ports/libtorch/vcpkg.json @@ -8,7 +8,12 @@ "dependencies": [ "concurrentqueue", "cpp-httplib", - "cpuinfo", + { + "name": "cpuinfo", + "features": [ + "clog" + ] + }, "eigen3", { "name": "fbgemm", diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index dd34eae51dbc16..4d6b4085f06b4b 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "b5879954eb1630bb855162475eafba7e35e9a50e", + "git-tree": "56a2eb6a2af8e414fb6d99cbff597b5678b52c4f", "version": "2.13.0", "port-version": 0 }, From 2d67bd0afafdd0d9d4dd92a9b964698d4091ba88 Mon Sep 17 00:00:00 2001 From: Steve brain Date: Fri, 7 Aug 2026 12:02:57 +0000 Subject: [PATCH 10/11] [libtorch] fix [dist] build against cpp-httplib 0.52.0 cpp-httplib 0.52.0 (microsoft/vcpkg#53223) changed httplib::Params from std::multimap to the new insertion-ordered detail::insertion_ordered_multimap. PyTorch's RequestImpl returns req_.params directly as a const std::multimap reference, so torch_cpu no longer compiles with [dist]: error: invalid initialization of reference of type 'const std::multimap<...>&' from expression of type 'const httplib::Params' Request::params() is an abstract interface with a second implementation in torch/csrc/distributed/c10d/init.cpp that has nothing to do with httplib, so changing the interface type is not an option. Materialize a multimap member in RequestImpl instead. The new type exposes const iterators over std::pair, so this compiles against both 0.51.0 and 0.52.0. The only behavioural difference is that iteration is sorted by key rather than insertion-ordered. The two consumers do not depend on that ordering: Request::getParam does a find(), and FlightRecorderCuda looks up fixed parameter names. Co-Authored-By: Claude Opus 5 (1M context) --- ports/libtorch/fix-httplib-params.patch | 26 +++++++++++++++++++++++++ ports/libtorch/portfile.cmake | 1 + versions/l-/libtorch.json | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 ports/libtorch/fix-httplib-params.patch diff --git a/ports/libtorch/fix-httplib-params.patch b/ports/libtorch/fix-httplib-params.patch new file mode 100644 index 00000000000000..87eb111618e797 --- /dev/null +++ b/ports/libtorch/fix-httplib-params.patch @@ -0,0 +1,26 @@ +--- a/torch/csrc/distributed/c10d/control_plane/WorkerServer.cpp ++++ b/torch/csrc/distributed/c10d/control_plane/WorkerServer.cpp +@@ -13,19 +13,21 @@ namespace c10d::control_plane { + namespace { + class RequestImpl : public Request { + public: +- RequestImpl(const httplib::Request& req) : req_(req) {} ++ RequestImpl(const httplib::Request& req) ++ : req_(req), params_(req.params.begin(), req.params.end()) {} + + const std::string& body() const override { + return req_.body; + } + + const std::multimap& params() const override { +- return req_.params; ++ return params_; + } + + private: + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) + const httplib::Request& req_; ++ std::multimap params_; + }; + + class ResponseImpl : public Response { diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index 4cd890239fd80e..8bb9efb79f4b65 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -19,6 +19,7 @@ vcpkg_from_github( fix-glog.patch fix-system-flatbuffers.patch fix-system-httplib.patch + fix-httplib-params.patch fix-system-nlohmann.patch fix-system-concurrentqueue.patch fix-system-pthreadpool.patch diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index 4d6b4085f06b4b..ab524e0395e81a 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "56a2eb6a2af8e414fb6d99cbff597b5678b52c4f", + "git-tree": "286d92d057bbf17ab167fcc026b8ff689c35144d", "version": "2.13.0", "port-version": 0 }, From bb6060e1bcf496f48719d47d4f540218df06faff Mon Sep 17 00:00:00 2001 From: Steve brain Date: Sat, 8 Aug 2026 05:40:27 +0000 Subject: [PATCH 11/11] [libtorch] don't build torch_global_deps torch_global_deps is an empty .c compiled into a shared library. Nothing links it; it exists solely so Python's _load_global_deps() can dlopen it with RTLD_GLOBAL and pull its MPI/MKL/CUDA link-time deps into the global symbol namespace, which OpenMPI-style plugin dlopen needs -- see upstream Note [Global dependencies] in caffe2/CMakeLists.txt. The port hard-sets BUILD_PYTHON=OFF, so it is dead weight here, and being empty it exports nothing, which required VCPKG_POLICY_DLLS_WITHOUT_EXPORTS to silence the post-build check on Windows. Guard the target on the option that actually governs it instead, and drop the policy. It is not referenced by Caffe2Targets/TorchConfig and is a leaf in the build graph, so no consumer sees a difference. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_012htN6VLAChphedAc8y5wFf --- ports/libtorch/fix-torch-global-deps.patch | 11 +++++++++++ ports/libtorch/portfile.cmake | 11 +---------- versions/l-/libtorch.json | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 ports/libtorch/fix-torch-global-deps.patch diff --git a/ports/libtorch/fix-torch-global-deps.patch b/ports/libtorch/fix-torch-global-deps.patch new file mode 100644 index 00000000000000..dae9d364a63e75 --- /dev/null +++ b/ports/libtorch/fix-torch-global-deps.patch @@ -0,0 +1,11 @@ +--- a/caffe2/CMakeLists.txt ++++ b/caffe2/CMakeLists.txt +@@ -1835,7 +1835,7 @@ endif() + # namespaces, so libtorch is loaded with all its dependencies in a local scope. + # That usually leads to missing symbol errors at run-time, so to avoid a situation like + # this we have to preload those libs in a global namespace. +-if(BUILD_SHARED_LIBS) ++if(BUILD_SHARED_LIBS AND BUILD_PYTHON) + add_library(torch_global_deps SHARED ${TORCH_SRC_DIR}/csrc/empty.c) + if(HAVE_SOVERSION) + set_target_properties(torch_global_deps PROPERTIES diff --git a/ports/libtorch/portfile.cmake b/ports/libtorch/portfile.cmake index 8bb9efb79f4b65..9c34a0767a7dda 100644 --- a/ports/libtorch/portfile.cmake +++ b/ports/libtorch/portfile.cmake @@ -40,6 +40,7 @@ vcpkg_from_github( fix-async-mm-cutlass.patch fix-python-package-data.patch fix-headeronly-glob.patch + fix-torch-global-deps.patch ) file(REMOVE_RECURSE "${SOURCE_PATH}/caffe2/core/macros.h") # We must use generated header files @@ -296,13 +297,3 @@ vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE" "${SOURCE_PATH}/third_party/miniz-3.0.2/LICENSE" ) - - -# torch_global_deps is built from an empty .c file; nothing links it. It exists so that -# Python's _load_global_deps() can dlopen it with RTLD_GLOBAL and thereby pull its own -# link-time deps (MPI/MKL/CUDA) into the global symbol namespace, which OpenMPI-style -# plugin dlopen needs -- see upstream Note [Global dependencies] in caffe2/CMakeLists.txt. -# Irrelevant here (BUILD_PYTHON=OFF, and _load_global_deps returns early on Windows), but -# upstream installs it unconditionally under BUILD_SHARED_LIBS, and being empty it exports nothing. -set(VCPKG_POLICY_DLLS_WITHOUT_EXPORTS enabled) - diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index ab524e0395e81a..27d7a07ed925c0 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "286d92d057bbf17ab167fcc026b8ff689c35144d", + "git-tree": "c6fbf85724803f1b6df9c2f29f0a1632dee4c86b", "version": "2.13.0", "port-version": 0 },