summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2026-03-03 09:44:35 +0100
committerRicardo Wurmus <rekado@elephly.net>2026-03-05 13:31:27 +0100
commit55834534bebb51428fb735136f513ed3c6ae0b05 (patch)
treeea991cd459f0a9ee54250816ab73748828ff4bab
parent6f5d409ea19d652b70d5f1f5d6f6f68f28d26c2e (diff)
python: tensorflow: Update to 2.18.1.wip-tensorflow
Unlike version 2.20.0, this version lets us use Bazel 6.5, which we have previously packaged. Unlike 2.13.1 this version works with Numpy 2, which has become the default for Python packages in Guix. * guix-science/packages/python.scm (tensorflow-system-libs): Adjust. (tensorflow)[source]: Patch sources to inject a patch for Python toolchain discovery. [arguments]: Use bazel-6.5; update the fetch and build targets; adjust the 'configure phase; override the platforms repository; adjust 'install phase due to script name change. [native-inputs]: Remove python-setuptools and add bazel platforms 0.0.8.
-rw-r--r--guix-science/packages/python.scm110
1 files changed, 91 insertions, 19 deletions
diff --git a/guix-science/packages/python.scm b/guix-science/packages/python.scm
index 208c194..7dd42ad 100644
--- a/guix-science/packages/python.scm
+++ b/guix-science/packages/python.scm
@@ -54,6 +54,7 @@
54 #:use-module (guix search-paths) 54 #:use-module (guix search-paths)
55 #:use-module (guix utils) 55 #:use-module (guix utils)
56 #:use-module (guix-science build-system bazel) 56 #:use-module (guix-science build-system bazel)
57 #:use-module (guix-science packages bazel)
57 #:use-module (guix-science packages machine-learning) 58 #:use-module (guix-science packages machine-learning)
58 #:use-module (guix-science packages python-xyz) 59 #:use-module (guix-science packages python-xyz)
59 #:use-module (guix-science packages serialization) 60 #:use-module (guix-science packages serialization)
@@ -485,7 +486,7 @@ differentiable optimizers in JAX.
485 ;;"astunparse_archive" 486 ;;"astunparse_archive"
486 ;;"boringssl" 487 ;;"boringssl"
487 ;;"com_github_googlecloudplatform_google_cloud_cpp" 488 ;;"com_github_googlecloudplatform_google_cloud_cpp"
488 "com_github_grpc_grpc" 489 ;;"com_github_grpc_grpc"
489 ;;"com_google_absl" 490 ;;"com_google_absl"
490 ;;"com_google_protobuf" 491 ;;"com_google_protobuf"
491 ;;"com_googlesource_code_re2" 492 ;;"com_googlesource_code_re2"
@@ -493,7 +494,7 @@ differentiable optimizers in JAX.
493 "cython" 494 "cython"
494 ;;"dill_archive" 495 ;;"dill_archive"
495 "double_conversion" 496 "double_conversion"
496 "flatbuffers" 497 ;;"flatbuffers"
497 ;;"functools32_archive" 498 ;;"functools32_archive"
498 "gast_archive" 499 "gast_archive"
499 "gif" 500 "gif"
@@ -503,11 +504,10 @@ differentiable optimizers in JAX.
503 "libjpeg_turbo" 504 "libjpeg_turbo"
504 "nasm" 505 "nasm"
505 "nsync" 506 "nsync"
506 "opt_einsum_archive"
507 ;;"org_sqlite" 507 ;;"org_sqlite"
508 "pasta" 508 "pasta"
509 "png" 509 "png"
510 ;;"pybind11" ;Our 2.8.1 does not support "const_name" attribute 510 ;;"pybind11"
511 "six_archive" 511 "six_archive"
512 ;;"snappy" 512 ;;"snappy"
513 ;;"tblib_archive" 513 ;;"tblib_archive"
@@ -573,7 +573,7 @@ mechanism for serializing structured data.")
573(define-public tensorflow 573(define-public tensorflow
574 (package 574 (package
575 (name "tensorflow") 575 (name "tensorflow")
576 (version "2.13.1") 576 (version "2.18.1")
577 (source 577 (source
578 (origin 578 (origin
579 (method git-fetch) 579 (method git-fetch)
@@ -582,11 +582,73 @@ mechanism for serializing structured data.")
582 (commit (string-append "v" version)))) 582 (commit (string-append "v" version))))
583 (file-name (git-file-name name version)) 583 (file-name (git-file-name name version))
584 (sha256 584 (sha256
585 (base32 "09mfskmpvpbq919wibnw3bnhi1y3hkx3qrzm72gdr0gsivn1yb3w")))) 585 (base32 "0swxxjd1c77jzym22d4azb1rf55b2gzn79653za7n63mqxdimpng"))
586 (modules '((guix build utils)))
587 (snippet
588 '(begin
589 (let ((generator
590 (lambda _
591 (display "\
592--- a/python/repositories.bzl
593+++ b/python/repositories.bzl
594@@ -218,7 +218,7 @@
595 else:
596 fail(\"The current user has CAP_DAC_OVERRIDE set, please drop this capability when using the hermetic Python interpreter. See https://github.com/bazelbuild/rules_python/pull/713.\")
597
598- python_bin = \"python.exe\" if (\"windows\" in platform) else \"bin/python3\"
599+ python_bin = \"python.exe\" if (\"windows\" in platform) else rctx.os.environ.get(\"GUIX_PYTHON_PREFIX_DIR\")
600
601 glob_include = []
602 glob_exclude = [
603@@ -359,7 +359,7 @@
604 }}),
605 )
606
607-exports_files([\"python\", \"{python_path}\"])
608+exports_files([\"python\", \"bin/python\"])
609
610 # Used to only download coverage toolchain when the coverage is collected by
611 # bazel.
612@@ -373,7 +373,7 @@
613 name = \"py3_runtime\",
614 files = [\":files\"],
615 {coverage_attr}
616- interpreter = \"{python_path}\",
617+ interpreter = \"bin/python\",
618 interpreter_version_info = {{
619 \"major\": \"{interpreter_version_info_major}\",
620 \"minor\": \"{interpreter_version_info_minor}\",
621@@ -413,7 +413,12 @@
622 interpreter_version_info_micro = python_version_info[2],
623 )
624 rctx.delete(\"python\")
625- rctx.symlink(python_bin, \"python\")
626+ rctx.delete(\"bin\")
627+ rctx.delete(\"lib\")
628+ rctx.symlink(python_bin + \"/bin/python\", \"bin/python\")
629+ rctx.symlink(python_bin + \"/bin/python\", \"bin/python3\")
630+ rctx.symlink(python_bin + \"/lib\", \"lib\")
631+
632 rctx.file(STANDALONE_INTERPRETER_FILENAME, \"# File intentionally left blank. Indicates that this is an interpreter repo created by rules_python.\")
633 rctx.file(\"BUILD.bazel\", build_content)
634 "))))
635 (with-output-to-file "third_party/py/guix_python.patch"
636 generator)
637 (with-output-to-file "third_party/xla/third_party/py/guix_python.patch"
638 generator))
639 (substitute* '("third_party/py/python_init_rules.bzl"
640 "third_party/xla/third_party/py/python_init_rules.bzl")
641 (("patches = \\[Label\\(\"//third_party/py:rules_python.patch\"\\)\\],")
642 "patches = [
643Label(\"//third_party/py:guix_python.patch\"),
644Label(\"//third_party/py:rules_python.patch\")
645],
646"))))))
586 (build-system bazel-build-system) 647 (build-system bazel-build-system)
587 (arguments 648 (arguments
588 (list 649 (list
589 #:tests? #false ;there are none 650 #:tests? #false ;there are none
651 #:bazel bazel-6.5
590 #:bazel-configuration 652 #:bazel-configuration
591 ;; TODO: is the union build *really* necessary? 653 ;; TODO: is the union build *really* necessary?
592 (with-imported-modules (source-module-closure '((guix build utils) 654 (with-imported-modules (source-module-closure '((guix build utils)
@@ -596,25 +658,32 @@ mechanism for serializing structured data.")
596 (use-modules (guix build union)) 658 (use-modules (guix build union))
597 (union-build (string-append (getenv "NIX_BUILD_TOP") "/site-packages") 659 (union-build (string-append (getenv "NIX_BUILD_TOP") "/site-packages")
598 (parse-path (getenv "GUIX_PYTHONPATH"))) 660 (parse-path (getenv "GUIX_PYTHONPATH")))
661 (setenv "RULES_PYTHON_REPO_DEBUG" "1")
599 (setenv "PYTHON_LIB_PATH" (string-append (getenv "NIX_BUILD_TOP") "/site-packages")) 662 (setenv "PYTHON_LIB_PATH" (string-append (getenv "NIX_BUILD_TOP") "/site-packages"))
600 (setenv "PYTHON_BIN_PATH" 663 (setenv "PYTHON_BIN_PATH"
601 (string-append 664 (string-append
602 #$(this-package-input "python-wrapper") 665 #$(this-package-input "python-wrapper")
603 "/bin/python")) 666 "/bin/python"))
667 (setenv "GUIX_PYTHON_PREFIX_DIR"
668 #$(this-package-input "python-wrapper"))
604 (setenv "TF_PYTHON_VERSION" 669 (setenv "TF_PYTHON_VERSION"
605 #$(version-major+minor 670 #$(version-major+minor
606 (package-version (this-package-input "python-wrapper")))) 671 (package-version (this-package-input "python-wrapper"))))
607 (setenv "TF_SYSTEM_LIBS" 672 (setenv "TF_SYSTEM_LIBS"
608 (string-join '#$tensorflow-system-libs ",")))) 673 (string-join '#$tensorflow-system-libs ","))))
609 #:fetch-targets 674 #:fetch-targets
610 '(list "//tensorflow/tools/pip_package:build_pip_package" 675 '(list "//tensorflow/tools/pip_package:wheel"
611 "//tensorflow/tools/lib_package:libtensorflow") 676 "//tensorflow/tools/lib_package:libtensorflow")
612 #:build-targets 677 #:build-targets
613 '(list "//tensorflow/tools/pip_package:build_pip_package" 678 '(list "//tensorflow/tools/pip_package:wheel"
614 "//tensorflow/tools/lib_package:libtensorflow") 679 "//tensorflow/tools/lib_package:libtensorflow")
615 #:bazel-arguments 680 #:bazel-arguments
616 #~(list 681 #~(list
617 "--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain_nonstrict" 682 "--extra_toolchains=@bazel_tools//tools/python:autodetecting_toolchain_nonstrict"
683 ;; We need a more recent version of platforms, because the
684 ;; included cpu package does not define cpu:wasm32.
685 (string-append "--override_repository=platforms="
686 #$(this-package-native-input "bazel-platforms-0.0.8-checkout"))
618 "--action_env=PYTHON_LIB_PATH" 687 "--action_env=PYTHON_LIB_PATH"
619 "--host_action_env=PYTHON_LIB_PATH" 688 "--host_action_env=PYTHON_LIB_PATH"
620 "--action_env=PYTHON_BIN_PATH" 689 "--action_env=PYTHON_BIN_PATH"
@@ -623,21 +692,16 @@ mechanism for serializing structured data.")
623 #$(this-package-input "python-wrapper") 692 #$(this-package-input "python-wrapper")
624 "/bin/python")) 693 "/bin/python"))
625 #:vendored-inputs-hash 694 #:vendored-inputs-hash
626 "0bqlwf9br68mrm5ambnm3dg31gnpsa12wfm2q2gqszknhmk1nyj8" 695 "1gqaiq1800v895kxppi5z8nzagk4fbpc8vwq33466kh06m25yy6c"
627 #:phases 696 #:phases
628 #~(modify-phases %standard-phases 697 #~(modify-phases %standard-phases
629 (add-after 'unpack-vendored-inputs 'configure 698 (add-after 'unpack-vendored-inputs 'configure
630 (lambda _ 699 (lambda _
631 (define bazel-out 700 (define bazel-out
632 (string-append (getenv "NIX_BUILD_TOP") "/output")) 701 (string-append (getenv "NIX_BUILD_TOP") "/output"))
633 ;; XXX: Our version of protobuf leads to "File already
634 ;; exists in database" when loading in Python.
635 (substitute* (string-append bazel-out "/external/tf_runtime/third_party/systemlibs/protobuf.BUILD")
636 (("-lprotobuf") "-l:libprotobuf.a")
637 (("-lprotoc") "-l:libprotoc.a"))
638 ;; Do not mess with RUNPATH 702 ;; Do not mess with RUNPATH
639 (substitute* "tensorflow/tools/pip_package/build_pip_package.sh" 703 (substitute* "tensorflow/tools/pip_package/build_pip_package.py"
640 (("patchelf ") "echo -- ")) 704 (("\"patchelf\", ") "\"echo\", \"--\", "))
641 (setenv "BAZEL_USE_CPP_ONLY_TOOLCHAIN" "1") 705 (setenv "BAZEL_USE_CPP_ONLY_TOOLCHAIN" "1")
642 (setenv "USER" "homeless-shelter") 706 (setenv "USER" "homeless-shelter")
643 (setenv "TF_SYSTEM_LIBS" 707 (setenv "TF_SYSTEM_LIBS"
@@ -666,10 +730,10 @@ Cflags: -I~a/include/tensorflow
666 ;; Install python bindings 730 ;; Install python bindings
667 ;; Build the source code, then copy it to the "python" output. 731 ;; Build the source code, then copy it to the "python" output.
668 ;; 732 ;;
669 ;; TODO: build_pip_package includes symlinks so we must 733 ;; TODO: build_pip_package.py includes symlinks so we must
670 ;; dereference them. 734 ;; dereference them.
671 (let ((here (string-append (getcwd) "/dist"))) 735 (let ((here (string-append (getcwd) "/dist")))
672 (invoke "bazel-bin/tensorflow/tools/pip_package/build_pip_package" 736 (invoke "python3" "bazel-bin/tensorflow/tools/pip_package/build_pip_package.py"
673 "--src" here) 737 "--src" here)
674 (copy-recursively here #$output:python))))))) 738 (copy-recursively here #$output:python)))))))
675 (outputs '("out" "python")) 739 (outputs '("out" "python"))
@@ -740,7 +804,15 @@ Cflags: -I~a/include/tensorflow
740 (list perl 804 (list perl
741 python-lit 805 python-lit
742 python-pypa-build 806 python-pypa-build
743 python-setuptools)) 807 (origin
808 (method git-fetch)
809 (uri (git-reference
810 (url "https://github.com/bazelbuild/platforms")
811 (commit "0.0.8")))
812 (file-name (git-file-name "bazel-platforms" "0.0.8"))
813 (sha256
814 (base32
815 "1wx2348w49vxr3z9kjfls5zsrwr0div6r3irbvdlawan87sx5yfs")))))
744 (home-page "https://tensorflow.org") 816 (home-page "https://tensorflow.org")
745 (synopsis "Machine learning framework") 817 (synopsis "Machine learning framework")
746 (description "TensorFlow is a flexible platform for building and 818 (description "TensorFlow is a flexible platform for building and