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 <csantosb@inventati.org>
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
This commit is contained in:
Nicolas Graves 2025-08-31 20:23:50 +02:00 committed by Sharlatan Hellseher
parent 3c26f155f3
commit 933bb42e58
No known key found for this signature in database
GPG key ID: 76D727BFF62CD2B5

View file

@ -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")))))))