From 933bb42e584396cfb4d36b9a5314a7d679a8d6f1 Mon Sep 17 00:00:00 2001 From: Nicolas Graves Date: Sun, 31 Aug 2025 20:23:50 +0200 Subject: [PATCH] gnu: python-pytorch: Fix Caffe2 cmake-bound dependents. Caffe2Targets.cmake has httplib::httplib but it doesn't seem imported anywhere beforehand. For me, this broke the build of python-torchaudio. Also add a few minor improvements. * gnu/packages/machine-learning.scm (python-pytorch)[arguments] <#:phases>: Improve phase 'cmake-patches (using site-packages and search-input-directory). Ensure httplib:httplib is defined when used. Improve phases 'remove-caffe2-onnx-scripts. Change-Id: If2cb3da00e579db2e22f734261ebfa30f15880c7 Reviewed-by: Cayetano Santos Signed-off-by: Sharlatan Hellseher --- gnu/packages/machine-learning.scm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm index d43c5227ff3..598a8a4bd31 100644 --- a/gnu/packages/machine-learning.scm +++ b/gnu/packages/machine-learning.scm @@ -5029,7 +5029,7 @@ PyTorch.") #:phases #~(modify-phases %standard-phases (add-after 'unpack 'cmake-patches - (lambda* (#:key inputs #:allow-other-keys) + (lambda* (#:key inputs outputs #:allow-other-keys) (substitute* "cmake/Dependencies.cmake" (("#POCKETFFT_INCLUDE_DIR") (string-append @@ -5038,8 +5038,7 @@ PyTorch.") (string-append #$(this-package-input "fp16") "/include")) (("#CONCURRENTQUEUE_INCLUDE_DIR") - (dirname (search-input-file inputs - "include/concurrentqueue/concurrentqueue.h"))) + (search-input-directory inputs "include/concurrentqueue")) ;; Disable opentelemetry ((".*(add_library|target_include_directories).*opentelemetry.*") "")) @@ -5048,9 +5047,11 @@ PyTorch.") ;; Fix Python install directory (substitute* "caffe2/CMakeLists.txt" (("\\$\\{Python_SITELIB\\}") - (string-append #$output "/lib/python" - #$(version-major+minor (package-version python)) - "/site-packages"))))) + (site-packages inputs outputs))) + ;; Ensure httplib::httplib is defined when used. + (substitute* "cmake/Caffe2Config.cmake.in" + (("include *\\(.*Caffe2Targets\\.cmake.*\\)" all) + (string-append "find_package(httplib REQUIRED)\n" all))))) ;; This entry point is broken, because it refers to a module that is ;; (intentionally) not installed ;; (https://github.com/pytorch/pytorch/pull/134729), which causes @@ -5204,9 +5205,8 @@ PyTorch.") (find-files python-site "(^test_cpp_rpc|_test)$"))))) (add-after 'install2 'remove-caffe2-onnx-scripts - (lambda* (#:key outputs #:allow-other-keys) - (let* ((out (assoc-ref outputs "out")) - (bin (string-append out "/bin"))) + (lambda _ + (let ((bin (string-append #$output "/bin"))) ;; Remove 'convert-caffe2-to-onnx' and ;; 'convert-onnx-to-caffe2': they seem to be ;; deprecated and they cause a failure of the @@ -5218,7 +5218,7 @@ PyTorch.") (for-each delete-file (find-files bin "^convert-.*caffe2")) - (substitute* (find-files out "^entry_points\\.txt$") + (substitute* (find-files #$output "^entry_points\\.txt$") (("^convert-.*" all) (string-append "# " all "\n")))))))