You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

302 lines
14 KiB

(define-module (gn packages tensorflow)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix utils)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix git-download)
#:use-module (guix build-system gnu)
#:use-module (gn packages bazel)
#:use-module (gnu packages assembly)
#:use-module (gnu packages base)
#:use-module (gnu packages commencement)
#:use-module (gnu packages compression)
#:use-module (gnu packages curl)
#:use-module (gnu packages databases)
#:use-module (gnu packages gcc)
#:use-module (gnu packages icu4c)
#:use-module (gnu packages image)
#:use-module (gnu packages maths)
#:use-module (gnu packages mpi)
#:use-module (gnu packages pcre)
#:use-module (gnu packages protobuf)
#:use-module (gnu packages python)
#:use-module (gnu packages python-xyz)
#:use-module (gnu packages rpc)
#:use-module (gnu packages regex)
#:use-module (gnu packages serialization)
#:use-module (gnu packages sqlite)
#:use-module (gnu packages version-control))
(define-public tensorflow
(name "tensorflow")
(version "2.4.0")
(source (origin
(method git-fetch)
(uri (git-reference
(url "")
(commit (string-append "v" version))))
(file-name (git-file-name name version))
(build-system gnu-build-system)
#:tests? #f ; Worry about this later.
(modify-phases %standard-phases
(delete 'configure)
(add-before 'build 'pre-build
(lambda* (#:key inputs outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(jdk (assoc-ref inputs "jdk"))
(HOME (string-append (getcwd) "/" ,name))
(bazelrc (string-append HOME "/bazelrc"))
(srcdeps (string-append HOME "/srcdeps"))
(setenv "HOME" HOME)
(with-output-to-file bazelrc
(lambda _
(format #t
"startup --server_javabase=~a~@
startup --batch~@
build --define=-copt=\"-Wl,-rpath -Wl,~a/lib\"~@
build --color=yes~@
build --action_env=PATH=~a~@
build --action_env=PYTHON_LIB_PATH=~a~@
build --define=PREFIX=~a~@
build --host_javabase='@local_jdk//:jdk'~%"
jdk (assoc-ref inputs "gcc:lib") (getenv "PATH") (getenv "PYTHONPATH") out)))
(invoke "cat" bazelrc)
(substitute* ".bazelrc"
(("PREFIX=/usr") (string-append "PREFIX=" out)))
;; Use the pre-downloaded files
(substitute* "WORKSPACE"
(string-append "\"file://" (assoc-ref inputs "io_bazel_rules_closure")))
(substitute* "third_party/toolchains/preconfig/generate/archives.bzl"
(string-append "\"file://" (assoc-ref inputs "bazel_toolchains")))
(substitute* "tensorflow/workspace.bzl"
(string-append "\"file://" (assoc-ref inputs "build_bazel_rules_swift")))
(string-append "\"file://" (assoc-ref inputs "com_google_googleapis")))
(string-append "\"file://" (assoc-ref inputs "bazel_skylib")))
(string-append "\"file://" (assoc-ref inputs "rules_cc")))
(string-append "\"file://" (assoc-ref inputs "build_bazel_rules_android")))
(substitute* ""
(("/usr/bin/ldd") (which "ldd")))
;; Lets fix some hardcoded /usr/bins
;(substitute* "third_party/toolchains/preconfig/generate/generate.bzl"
; (("/usr/bin/python")
; (string-append (dirname (or (which "python")
; (which "python3")))
; "/python"))
; )
;; cpu detection fails, hardcode Linux as OS.
;(substitute* "third_party/gpus/cuda_configure.bzl"
; ((".*Linux.*") " if True:\n"))
;(substitute* "third_party/remote_config/common.bzl"
; (("uname") (which "uname")))
;(substitute* "third_party/remote_config/common.bzl"
; ;(("\\\"which\\\"") (string-append "\"" (which "which") "\""))
; (("python_bin_path =.*") (string-append "python_bin_path = \"" (which "python") "\"\n"))
; )
;; Copy sources to one directory
;(mkdir-p srcdeps)
; (lambda (file)
; (copy-recursively file (string-append srcdeps "/" (strip-store-file-name file))))
; (list (assoc-ref inputs "io_bazel_rules_closure")))
(replace 'build
(lambda* (#:key inputs #:allow-other-keys)
(let* ((jdk (assoc-ref inputs "jdk"))
(HOME (string-append (getcwd) "/" ,name))
(bazelrc (string-append HOME "/bazelrc"))
(srcdeps (string-append HOME "/srcdeps"))
(setenv "TF_SYSTEM_LIBS" (string-append "absl_py,"
;"enum34_archive," ; python2 only?
;"functools32_archive," ; python2 only?
(setenv "PYTHON_BIN_PATH" (which "python"))
(setenv "GCC_HOST_COMPILER_PATH" (string-append (assoc-ref inputs "gcc-toolchain") "/bin/gcc"))
(setenv "GCC_HOST_COMPILER_PREFIX" (string-append (assoc-ref inputs "gcc-toolchain") "/bin"))
;(setenv "LD_LIBRARY_PATH" (string-append (assoc-ref inputs "gcc:lib") "/lib"))
(setenv "LD_LIBRARY_PATH" (string-append (assoc-ref inputs "gcc:lib")))
;(invoke "python3" "")
(invoke "./configure")
;(substitute* ".tf_configure.bazelrc"
; (("PYTHON_LIB_PATH.*") (string-append "PYTHON_LIB_PATH=\"" (getenv "PYTHONPATH") "\"\n")))
(invoke "bazel"
(string-append "--bazelrc=" bazelrc)
("bazel" ,bazel-bootstrap)
("gcc:lib" ,gcc "lib")
("gcc-toolchain" ,gcc-toolchain)
("git" ,git)
("python" ,python)
("which" ,which)
("absl_py" ,python-absl-py)
("astor_archive" ,python-astor)
("astunparse_archive" ,python-astunparse)
("com_googlesource_code_re2" ,re2)
("com_google_protobuf" ,protobuf)
("com_github_grpc_grpc" ,grpc)
("curl" ,curl)
("cython" ,python-cython)
("dill_archive" ,python-dill)
("double-conversion" ,double-conversion)
("flatbuffers" ,flatbuffers)
("gast_archive" ,python-gast)
("gif" ,giflib)
("hwloc" ,hwloc)
("icu" ,icu4c)
("jsoncpp_git" ,jsoncpp)
("libjpeg_turbo" ,libjpeg-turbo)
("lmdb" ,lmdb)
("nasm" ,nasm)
("org_sqlite" ,sqlite)
("pcre" ,pcre2)
("png" ,libpng)
("pybind11" ,pybind11)
("six_archive" ,python-six)
("snappy" ,snappy)
("tblib_archive" ,python-tblib)
("termcolor_archive" ,python-termcolor)
("typing_extensions_archive" ,python-typing-extensions)
("wrapt" ,python-wrapt)
("zlib" ,zlib)
(method url-fetch)
(uri "")
(file-name "io_bazel_rules_closure.tar.gz")
(method url-fetch)
(uri "")
(file-name "bazel_toolchains.tar.gz")
(method url-fetch)
(uri "")
(file-name "build_bazel_rules_swift.tar.gz")
(method url-fetch)
(uri "")
(file-name "")
(method url-fetch)
(uri "")
(file-name "bazel_skylib-0.9.0.tar.gz")
(method url-fetch)
(uri "")
(file-name "")
(method url-fetch)
(uri "")
(file-name "")
(home-page "")
(synopsis "Machine learning framework")
(description "TensorFlow is a flexible platform for building and training
machine learning models. It provides a library for high performance numerical
computation and includes high level Python APIs, including both a sequential API
for beginners that allows users to build models quickly by plugging together
building blocks and a subclassing API with an imperative style for advanced
(license license:asl2.0)))