-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Portfile
229 lines (203 loc) · 9.59 KB
/
Portfile
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
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
PortSystem 1.0
PortGroup python 1.0
PortGroup java 1.0
PortGroup github 1.0
PortGroup compilers 1.0
PortGroup xcodeversion 1.0
PortGroup compiler_blacklist_versions 1.0
PortGroup xcode_workaround 1.0
name py-tensorflow
version 2.2.0
revision 0
github.setup tensorflow tensorflow ${version} v
platforms darwin
supported_archs x86_64
license Apache-2
maintainers {emcrisostomo @emcrisostomo} {jonesc @cjones051073} openmaintainer
description TensorFlow helps the tensors flow
long_description ${description}
homepage https://www.tensorflow.org/
github.livecheck.regex {([0-9.]+)}
checksums rmd160 53b38674e167f00d13eacef4ac7da5c8a364f1f6 \
sha256 92b44979b36ab6a9760a777b5faba50df20ad5a9d590f02fa3084e06d8901791 \
size 42104809
set min_darwin 16
if { ${os.major} < ${min_darwin} } {
known_fail yes
# https://trac.macports.org/ticket/58518
pre-fetch {
ui_error "${name} ${version} requires Darwin ${min_darwin} or newer."
return -code error "incompatible macOS version"
}
}
# Required java version
java.version 11+
# JDK port to install if required java not found
java.fallback openjdk14
# JDK only needed at build time, but java PG sets lib dependency so
# declare no conflict to allow redistribution of binaries.
license_noconflict ${java.fallback}
# require c++14
compiler.cxx_standard 2014
# The oldest Xcode version to use default Xcode compiler
# https://github.com/tensorflow/tensorflow/issues/39262
set tf_min_xcode 10.2
compiler.blacklist-append {clang < 1001}
# Work out if we should be using macports clang
set use_mp_clang [ expr ( [ string match macports-clang-* ${configure.compiler} ] || [ vercmp ${xcodeversion} ${tf_min_xcode} ] < 0 ) ]
# https://trac.macports.org/ticket/59192
xcode_workaround.type avoid_xcode_compiler
xcode_workaround.os_versions 18 19
xcode_workaround.fixed_xcode_version 11.4
#patch.pre_args -p1
variant mkl description {Enable Intel Math Kernel Library support} {
# Not obvious if this dep is needed ?
#depends_lib-append port:libomp
}
# Enable MKL by default on 10.12 and newer.
# Currently not working due to
# external/mkl_dnn_v1/src/common/dnnl_thread.hpp:42:10: fatal error: 'omp.h' file not found
#if {${os.major} >= 16} {
# default_variants-append +mkl
#}
variant native description {Build from source for best native platform support} { }
# Support python versions
python.versions 37 38
python.default_version 38
if {${name} ne ${subport}} {
# TF versions 1 and 2 cannot be installed at once
conflicts py${python.version}-tensorflow1
depends_build-append \
port:py${python.version}-future \
port:py${python.version}-pip \
port:py${python.version}-mock \
port:bazel-2.0 \
port:cctools
depends_lib-append \
port:py${python.version}-absl \
port:py${python.version}-astor \
port:py${python.version}-gast \
port:py${python.version}-google-pasta \
port:py${python.version}-grpcio \
port:py${python.version}-keras \
port:py${python.version}-numpy \
port:py${python.version}-protobuf3 \
port:py${python.version}-six \
port:py${python.version}-tensorboard \
port:py${python.version}-tensorflow_estimator \
port:py${python.version}-termcolor \
port:py${python.version}-wheel \
port:py${python.version}-wrapt
use_configure yes
# Options passed to configure script via env vars
configure.env-append PYTHON_LIB_PATH=${python.prefix}/lib/python${python.branch}/site-packages
configure.env-append PYTHON_BIN_PATH=${prefix}/bin/python${python.branch}
configure.env-append JAVA_HOME=${java.home}
build.env-append TMPDIR=${workpath}/tmp
build.env-append JAVA_HOME=${java.home}
set base_march "-march=x86-64"
if {![variant_isset native]} {
configure.env-append CC_OPT_FLAGS=${base_march}
build.env-append CC_OPT_FLAGS=${base_march}
notes "This version is built based on a base architecture for convenience,
which may not be optimized for your system. To build a version
customized for your machine, use the +native variant"
}
# Disable Xcode detection on older OSes, as we want the
# MP provided commandline utilities to be used instead.
if { ${use_mp_clang} } {
configure.env-append BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
build.env-append BAZEL_USE_CPP_ONLY_TOOLCHAIN=1
}
# Remove all arguments
configure.args
configure.pre_args
# configure command
configure.cmd ./configure
# Patch configuration
pre-configure {
# enforce correct build settings
# note final / is because ${worksrcpath} is a sym-link
foreach f [ exec find ${worksrcpath}/ -name "configure" -or -name "configure.py" -or -name "compile.sh" -or -name "*.tpl" -or -name "*.bzl" -or -name "CROSSTOOL" -or -name "configure.py" -or -name "MOCK_CROSSTOOL" ] {
foreach cmd {ar nm strip libtool ld objdump} {
reinplace -q "s|/usr/bin/${cmd}|${prefix}/bin/${cmd}|g" ${f}
}
reinplace -q "s|/usr/bin/clang|\"${configure.cc}\"|g" ${f}
reinplace -q "s|\"clang\"|\"${configure.cc}\"|g" ${f}
reinplace -q "s| clang | ${configure.cc} |g" ${f}
reinplace -q "s|/usr/local/include|${prefix}/include|g" ${f}
reinplace -q "s|std=c++0x|std=c++11|g" ${f}
reinplace -q "s|std=c++1y|std=c++14|g" ${f}
reinplace -q "s|std=c++1z|std=c++17|g" ${f}
}
# If not native build, make sure not used...
if {![variant_isset native]} {
foreach f [ exec find ${worksrcpath}/ -name "configure" -or -name "configure.py" -or -name "CMakeLists.txt" -or -name "Makefile" -or -name "*.sh" ] {
reinplace -q "s|-march=native|${base_march}|g" ${f}
}
}
}
build {
# tensorflow(via bazel) cannot be built if gcc is 'port selected'
# https://trac.macports.org/ticket/58569
# https://trac.macports.org/ticket/58679
# Until it can be figured out how to stop bazel finding and using macports gcc
# just detect when this situation arises and error out...
if { [file exists ${prefix}/bin/gcc] } {
ui_error "${subport} cannot be built with 'port select gcc' active."
ui_error "Please run 'sudo port select gcc none' and try again."
ui_error "Once the build is complete, you can safely re-select your preferred gcc."
return -code error "build error"
}
# Build using the wonderful bazel build system ...
set tf_bazel_cmd "bazel --max_idle_secs=60 --output_user_root=${workpath}"
set tf_bazel_build_opts "-s -c opt --verbose_failures --config=opt"
# Explicitly pass SDK https://github.com/bazelbuild/rules_go/issues/1554
set tf_bazel_build_opts "${tf_bazel_build_opts} --macos_sdk_version=${configure.sdk_version}"
# hack to try and transfer MP c, c++ and ld options to bazel...
foreach opt [list {*}${configure.cflags} ] {
set tf_bazel_build_opts "${tf_bazel_build_opts} --conlyopt '${opt}'"
}
foreach opt [list {*}${configure.cxxflags} ] {
set tf_bazel_build_opts "${tf_bazel_build_opts} --cxxopt '${opt}'"
}
foreach opt [list {*}${configure.ldflags} ] {
set tf_bazel_build_opts "${tf_bazel_build_opts} --linkopt '${opt}'"
}
if { ${use_mp_clang} } {
set tf_bazel_build_opts "${tf_bazel_build_opts} --action_env CC=${configure.cc}"
set tf_bazel_cmd "BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 ${tf_bazel_cmd}"
}
if {[variant_isset mkl]} {
set tf_bazel_build_opts "${tf_bazel_build_opts} --config=mkl"
# Is this required ?
#set tf_bazel_build_opts "${tf_bazel_build_opts} --cxxopt '-I${prefix}/include/libomp' --linkopt '-L${prefix}/lib/libomp'"
}
if {![variant_isset native]} {
set tf_bazel_build_opts "${tf_bazel_build_opts} --copt=${base_march}"
set tf_bazel_cmd "CC_OPT_FLAGS=${base_march} ${tf_bazel_cmd}"
}
ui_debug "Bazel build command : ${tf_bazel_cmd}"
ui_debug "Bazel build options : ${tf_bazel_build_opts}"
# Run the build
system -W ${worksrcpath} "${tf_bazel_cmd} build ${tf_bazel_build_opts} //tensorflow/tools/pip_package:build_pip_package"
# Build the python wheel
system -W ${worksrcpath} "./bazel-bin/tensorflow/tools/pip_package/build_pip_package ${workpath}"
# Clean up
system -W ${worksrcpath} "${tf_bazel_cmd} clean"
}
destroot.cmd pip-${python.branch}
destroot.args \
--ignore-installed \
--no-cache-dir \
--no-dependencies \
--root ${destroot} \
${workpath}/tensorflow-*.whl
destroot.post_args
post-destroot {
file delete ${destroot}${python.prefix}/bin/tensorboard
file delete ${destroot}${prefix}/bin/tensorboard-${python.branch}
}
livecheck.type none
}