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
(package
(name "tensorflow")
(version "2.4.0")
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/tensorflow/tensorflow")
(commit (string-append "v" version))))
(file-name (git-file-name name version))
(sha256
(base32
"0yl06aypfxrcs35828xf04mkidz1x0j89v0q5h4d2xps1cb5rv3f"))))
(build-system gnu-build-system)
(arguments
`(
#:tests? #f ; Worry about this later.
#:phases
(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)))
(newline)
(invoke "cat" bazelrc)
(newline)
(substitute* ".bazelrc"
(("PREFIX=/usr") (string-append "PREFIX=" out)))
;; Use the pre-downloaded files
(substitute* "WORKSPACE"
(("\\\".*github.com/bazelbuild/rules_closure/.*.tar.gz")
(string-append "\"file://" (assoc-ref inputs "io_bazel_rules_closure")))
)
(substitute* "third_party/toolchains/preconfig/generate/archives.bzl"
(("\\\".*github.com/bazelbuild/bazel-toolchains/.*.tar.gz")
(string-append "\"file://" (assoc-ref inputs "bazel_toolchains")))
)
(substitute* "tensorflow/workspace.bzl"
(("\\\".*github.com/bazelbuild/rules_swift/.*.tar.gz")
(string-append "\"file://" (assoc-ref inputs "build_bazel_rules_swift")))
(("\\\".*github.com/googleapis/googleapis/.*.zip")
(string-append "\"file://" (assoc-ref inputs "com_google_googleapis")))
(("\\\".*github.com/bazelbuild/bazel-skylib/.*.tar.gz")
(string-append "\"file://" (assoc-ref inputs "bazel_skylib")))
(("\\\".*github.com/bazelbuild/rules_cc/.*.zip")
(string-append "\"file://" (assoc-ref inputs "rules_cc")))
(("\\\".*github.com/bazelbuild/rules_android/.*.zip")
(string-append "\"file://" (assoc-ref inputs "build_bazel_rules_android")))
)
(substitute* "configure.py"
(("/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)
;(for-each
; (lambda (file)
; (copy-recursively file (string-append srcdeps "/" (strip-store-file-name file))))
; (list (assoc-ref inputs "io_bazel_rules_closure")))
#t)))
(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,"
"astor_archive,"
"astunparse_archive,"
;"boringssl,"
;"com_github_googleapis_googleapis,"
;"com_github_googlecloudplatform_google_cloud_cpp,"
"com_github_grpc_grpc,"
"com_google_protobuf,"
"com_googlesource_code_re2,"
"curl,"
"cython,"
"dill_archive,"
"double_conversion,"
;"enum34_archive," ; python2 only?
"flatbuffers,"
;"functools32_archive," ; python2 only?
"gast_archive,"
"gif,"
"hwloc,"
"icu,"
"jsoncpp_git,"
"libjpeg_turbo,"
"lmdb,"
"nasm,"
;"nsync,"
;"opt_einsum_archive,"
"org_sqlite,"
;"pasta,"
"pcre,"
"png,"
"pybind11,"
"six_archive,"
"snappy,"
"tblib_archive,"
"termcolor_archive,"
"typing_extensions_archive,"
"wrapt,"
"zlib"))
(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" "configure.py")
(invoke "./configure")
;(substitute* ".tf_configure.bazelrc"
; (("PYTHON_LIB_PATH.*") (string-append "PYTHON_LIB_PATH=\"" (getenv "PYTHONPATH") "\"\n")))
(invoke "bazel"
(string-append "--bazelrc=" bazelrc)
"build"
;"--config=opt"
"--config=avx_linux"
;"//tensorflow:libtensorflow_cc.so"
"//tensorflow/tools/pip_package:build_pip_package"
;"//tensorflow/tools/lib_package:libtensorflow"
)
)
))
)
))
(native-inputs
`(
("bazel" ,bazel-bootstrap)
("gcc:lib" ,gcc "lib")
("gcc-toolchain" ,gcc-toolchain)
("git" ,git)
("python" ,python)
("which" ,which)
;; https://github.com/tensorflow/tensorflow/blob/master/third_party/systemlibs/syslibs_configure.bzl
("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)
("io_bazel_rules_closure"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz")
(file-name "io_bazel_rules_closure.tar.gz")
(sha256
(base32
"1abbgk05f9flpv35zzw9fjjdvd3g1d8b0vbk0f2z4wfx10ykh02v"))))
("bazel_toolchains"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/bazel-toolchains/archive/92dd8a7a518a2fb7ba992d47c8b38299fe0be825.tar.gz")
(file-name "bazel_toolchains.tar.gz")
(sha256
(base32
"1xgyalc8pvy76rghkby28vz5y9ng1qhrqhn817vfwa1ny3wiis48"))))
("build_bazel_rules_swift"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/rules_swift/archive/3eeeb53cebda55b349d64c9fc144e18c5f7c0eb8.tar.gz")
(file-name "build_bazel_rules_swift.tar.gz")
(sha256
(base32
"11n8fmb5mf2zwgn202p8nmh82c8i1hm90pvajdks65yqvb33p0yh"))))
("com_google_googleapis"
,(origin
(method url-fetch)
(uri "https://github.com/googleapis/googleapis/archive/541b1ded4abadcc38e8178680b0677f65594ea6f.zip")
(file-name "com_google_googleapis.zip")
(sha256
(base32
"0059835rzfr9mb9x5m6ij7pi1y372qzdqls4a6vg8mf50qdv1fky"))))
("bazel_skylib"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/bazel-skylib/releases/download/0.9.0/bazel_skylib-0.9.0.tar.gz")
(file-name "bazel_skylib-0.9.0.tar.gz")
(sha256
(base32
"183w7h2cyzlq7q5q86yivzdwafyxvxc5dqii0yvksnhjj5a3dphx"))))
("rules_cc"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/rules_cc/archive/01d4a48911d5e7591ecb1c06d3b8af47fe872371.zip")
(file-name "rules_cc.zip")
(sha256
(base32
"1ybcjfwjykk7qii17dr640jivxssy1hb3x0hbd65bh461jlpcfyg"))))
("build_bazel_rules_android"
,(origin
(method url-fetch)
(uri "https://github.com/bazelbuild/rules_android/archive/v0.1.1.zip")
(file-name "build_bazel_rules_android.zip")
(sha256
(base32
"01kqga5xrkchw4kmr60r4m5xmy90zhxh1yb59mp94ndvv1fx21nd"))))
))
(home-page "https://www.tensorflow.org/")
(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
research.")
(license license:asl2.0)))