summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2024-01-12 22:56:42 +0100
committerRicardo Wurmus <rekado@elephly.net>2024-01-12 23:00:20 +0100
commit792477d8539a058ee919791c3b9c8d12e3f9a2b3 (patch)
tree60190ae58f191197415a208f807e7fd0e9a78d30
parentbef5e47475f81aa95397249751b82488993b150a (diff)
python: bazel-vendored-inputs: Remove any build tool references.
* guix-science/packages/python.scm (bazel-vendored-inputs): Remove bazel_tools, embedded_jdk, and any local_* repository to avoid keeping copies of JDK, Python, or GCC toolchain binaries or references to them. (python-jaxlib/wheel, tensorflow, python-tensorflow-probability)[arguments]: Remove code that fiddles with these references.
-rw-r--r--guix-science/packages/python.scm129
1 files changed, 38 insertions, 91 deletions
diff --git a/guix-science/packages/python.scm b/guix-science/packages/python.scm
index be79118..80e752e 100644
--- a/guix-science/packages/python.scm
+++ b/guix-science/packages/python.scm
@@ -821,6 +821,7 @@ NumPy @code{dtype} extensions used in machine learning libraries, including:
821 (guix build gnu-build-system))) 821 (guix build gnu-build-system)))
822 #~(begin 822 #~(begin
823 (use-modules (guix build utils) 823 (use-modules (guix build utils)
824 (ice-9 ftw)
824 (ice-9 match) 825 (ice-9 match)
825 (ice-9 string-fun)) 826 (ice-9 string-fun))
826 (define input-directories '#$(map cadr inputs)) 827 (define input-directories '#$(map cadr inputs))
@@ -882,33 +883,49 @@ NumPy @code{dtype} extensions used in machine learning libraries, including:
882 (list #$@bazel-targets))) 883 (list #$@bazel-targets)))
883 884
884 (with-directory-excursion %bazel-out 885 (with-directory-excursion %bazel-out
886 (for-each (lambda (file)
887 (delete-file (string-append "external/" file)))
888 (scandir "external"
889 (lambda (file)
890 (or (member file '("@bazel_tools.marker"
891 "@embedded_jdk.marker"))
892 (and (string-prefix? "@local_" file)
893 (string-suffix? ".marker" file))))))
885 (for-each delete-file-recursively 894 (for-each delete-file-recursively
886 (append 895 (append
887 #; 896 (list "external/bazel_tools")
888 (find-files "external" ; 897 (map (lambda (file)
889 "@?(bazel_tools|embedded_jdk|local_.*)(\\.marker)?") 898 (string-append "external/" file))
899 (scandir "external"
900 (lambda (file)
901 (and (string-prefix? "local_" file)
902 (eq? 'directory
903 (stat:type
904 (stat (string-append "external/" file))))))))
890 (find-files "external" 905 (find-files "external"
891 "^\\.(git|svn|hg)$"))) 906 "^\\.(git|svn|hg)$"
892 907 #:directories? #true)))
893 ;; Do not keep a copy of the JDK. The JDK files are not
894 ;; source code and they may change as the JDK package (or
895 ;; any of its inputs) changes.
896 908
897 ;; These are all symlinks from the "jdk" output of the 909 ;; Clear markers
898 ;; openjdk package, except for BUILD.bazel and WORKSPACE.
899 (for-each delete-file
900 (find-files "external/local_jdk"
901 (lambda (file-name stat)
902 (eq? (stat:type stat) 'symlink))))
903 ;; The BUILD file contains a store reference to the JDK.
904 (substitute* "external/local_jdk/BUILD.bazel"
905 (("java_home = .*,")
906 "java_home = \"@GUIX_JAVA_HOME@\","))
907
908 ;; Erase markers
909 (for-each (lambda (file) 910 (for-each (lambda (file)
910 (truncate-file file 0)) 911 (truncate-file file 0))
911 (find-files "external" "@.*\\.marker")) 912 (find-files "external" "@.*\\.marker"))
913
914 ;; Remove top-level symlinks along with their markers.
915 ;; This is needed because they sometimes point to
916 ;; temporary locations.
917 (for-each (lambda (file)
918 (delete-file (string-append "external/" file))
919 (let ((marker
920 (format #false "external/@~a.marker" (basename file))))
921 (false-if-exception
922 (delete-file marker))))
923 (scandir "external"
924 (lambda (file)
925 (eq? 'symlink
926 (stat:type
927 (lstat (string-append "external/" file)))))))
928
912 ;; Remove symlink references to the build directory. These 929 ;; Remove symlink references to the build directory. These
913 ;; will be rewritten to the current build directory by 930 ;; will be rewritten to the current build directory by
914 ;; users of this archive. 931 ;; users of this archive.
@@ -1034,45 +1051,10 @@ NumPy @code{dtype} extensions used in machine learning libraries, including:
1034 (string-contains (readlink file-name) 1051 (string-contains (readlink file-name)
1035 "GUIX_BUILD_TOP"))) 1052 "GUIX_BUILD_TOP")))
1036 #:stat lstat)) 1053 #:stat lstat))
1037 (substitute* (string-append bazel-out "/external/local_jdk/BUILD.bazel")
1038 (("@GUIX_JAVA_HOME@") #$(this-package-native-input "openjdk")))
1039 (setenv "HOME" (getenv "NIX_BUILD_TOP")) 1054 (setenv "HOME" (getenv "NIX_BUILD_TOP"))
1040 1055
1041 (invoke "python" "build/build.py" "--configure_only") 1056 (invoke "python" "build/build.py" "--configure_only")
1042 1057
1043 ;; Bazel aborts when a source file includes a header
1044 ;; that isn't declared. It prints something like this:
1045 ;;
1046 ;; "this rule is missing dependency declarations for
1047 ;; the following files included by..."
1048 ;;
1049 ;; Since we pass through C_INCLUDE_PATH and
1050 ;; CPLUS_INCLUDE_PATH there are many headers that are
1051 ;; visible to the toolchain, but that Bazel refuses to
1052 ;; allow.
1053 ;;
1054 ;; The biggest problem is that the kernel headers are
1055 ;; never declared as dependencies anywhere, so we need
1056 ;; to modify the toolchain declaration to allow headers
1057 ;; from this location.
1058 ;;
1059 ;; There are other headers that cause trouble, though,
1060 ;; such as those for zlib in the
1061 ;; @com_google_protobuf//:protobuf target. There must
1062 ;; be some other mechanism to fix this (e.g. in the
1063 ;; protobuf target itself), but I find it easier to just
1064 ;; allow all locations that appear on these INCLUDE_PATH
1065 ;; variables.
1066 (substitute* (string-append bazel-out "/external/local_config_cc/BUILD")
1067 (("cxx_builtin_include_directories = \\[" m)
1068 (string-append m
1069 (string-join
1070 (map
1071 (lambda (dir) (string-append "\"" dir "\""))
1072 (append (parse-path (getenv "C_INCLUDE_PATH") '())
1073 (parse-path (getenv "CPLUS_INCLUDE_PATH") '())))
1074 "," 'suffix))))
1075
1076 ;; XXX: Our version of protobuf leads to "File already 1058 ;; XXX: Our version of protobuf leads to "File already
1077 ;; exists in database" when loading jax in Python. 1059 ;; exists in database" when loading jax in Python.
1078 ;; Using the static library is what Nix does, but it 1060 ;; Using the static library is what Nix does, but it
@@ -1439,42 +1421,9 @@ mechanism for serializing structured data.")
1439 (string-contains (readlink file-name) 1421 (string-contains (readlink file-name)
1440 "GUIX_BUILD_TOP"))) 1422 "GUIX_BUILD_TOP")))
1441 #:stat lstat)) 1423 #:stat lstat))
1442 (substitute* (string-append bazel-out "/external/local_jdk/BUILD.bazel") 1424
1443 (("@GUIX_JAVA_HOME@") #$(this-package-native-input "openjdk")))
1444 (setenv "HOME" (getenv "NIX_BUILD_TOP")) 1425 (setenv "HOME" (getenv "NIX_BUILD_TOP"))
1445 1426
1446 ;; Bazel aborts when a source file includes a header
1447 ;; that isn't declared. It prints something like this:
1448 ;;
1449 ;; "this rule is missing dependency declarations for
1450 ;; the following files included by..."
1451 ;;
1452 ;; Since we pass through C_INCLUDE_PATH and
1453 ;; CPLUS_INCLUDE_PATH there are many headers that are
1454 ;; visible to the toolchain, but that Bazel refuses to
1455 ;; allow.
1456 ;;
1457 ;; The biggest problem is that the kernel headers are
1458 ;; never declared as dependencies anywhere, so we need
1459 ;; to modify the toolchain declaration to allow headers
1460 ;; from this location.
1461 ;;
1462 ;; There are other headers that cause trouble, though,
1463 ;; such as those for zlib in the
1464 ;; @com_google_protobuf//:protobuf target. There must
1465 ;; be some other mechanism to fix this (e.g. in the
1466 ;; protobuf target itself), but I find it easier to just
1467 ;; allow all locations that appear on these INCLUDE_PATH
1468 ;; variables.
1469 (substitute* (string-append bazel-out "/external/local_config_cc/BUILD")
1470 (("cxx_builtin_include_directories = \\[" m)
1471 (string-append m
1472 (string-join
1473 (map
1474 (lambda (dir) (string-append "\"" dir "\""))
1475 (append (parse-path (getenv "C_INCLUDE_PATH") '())
1476 (parse-path (getenv "CPLUS_INCLUDE_PATH") '())))
1477 "," 'suffix))))
1478 ;; XXX: Our version of protobuf leads to "File already 1427 ;; XXX: Our version of protobuf leads to "File already
1479 ;; exists in database" when loading in Python. 1428 ;; exists in database" when loading in Python.
1480 (substitute* (string-append bazel-out "/external/tf_runtime/third_party/systemlibs/protobuf.BUILD") 1429 (substitute* (string-append bazel-out "/external/tf_runtime/third_party/systemlibs/protobuf.BUILD")
@@ -1787,8 +1736,6 @@ subclassing API with an imperative style for advanced research.")
1787 (string-contains (readlink file-name) 1736 (string-contains (readlink file-name)
1788 "GUIX_BUILD_TOP"))) 1737 "GUIX_BUILD_TOP")))
1789 #:stat lstat)) 1738 #:stat lstat))
1790 (substitute* (string-append bazel-out "/external/local_jdk/BUILD.bazel")
1791 (("@GUIX_JAVA_HOME@") #$(this-package-native-input "openjdk")))
1792 (setenv "HOME" (getenv "NIX_BUILD_TOP")))) 1739 (setenv "HOME" (getenv "NIX_BUILD_TOP"))))
1793 (replace 'build 1740 (replace 'build
1794 (lambda _ 1741 (lambda _