1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
(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)))
|