103 lines
3.3 KiB
Ruby
103 lines
3.3 KiB
Ruby
class Libtensorflow < Formula
|
|
include Language::Python::Virtualenv
|
|
|
|
desc "C interface for Google's OS library for Machine Intelligence"
|
|
homepage "https://www.tensorflow.org/"
|
|
url "https://github.com/tensorflow/tensorflow/archive/v2.1.0.tar.gz"
|
|
sha256 "638e541a4981f52c69da4a311815f1e7989bf1d67a41d204511966e1daed14f7"
|
|
|
|
bottle do
|
|
cellar :any
|
|
sha256 "109857dcfdd331ef2f85b4ae4edb473c4cafec838b87a75e22a4b666978845a5" => :catalina
|
|
sha256 "109857dcfdd331ef2f85b4ae4edb473c4cafec838b87a75e22a4b666978845a5" => :mojave
|
|
sha256 "3f58a6409532f372ba6be7d8dafd4b057dcf84d237129908ca94626fb296b394" => :high_sierra
|
|
end
|
|
|
|
depends_on "bazel" => :build
|
|
depends_on :java => ["1.8", :build]
|
|
depends_on "python@3.8" => :build
|
|
|
|
resource "numpy" do
|
|
url "https://files.pythonhosted.org/packages/40/de/0ea5092b8bfd2e3aa6fdbb2e499a9f9adf810992884d414defc1573dca3f/numpy-1.18.1.zip"
|
|
sha256 "b6ff59cee96b454516e47e7721098e6ceebef435e3e21ac2d6c3b8b02628eb77"
|
|
end
|
|
|
|
resource "six" do
|
|
url "https://files.pythonhosted.org/packages/94/3e/edcf6fef41d89187df7e38e868b2dd2182677922b600e880baad7749c865/six-1.13.0.tar.gz"
|
|
sha256 "30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66"
|
|
end
|
|
|
|
def install
|
|
# Bazel fails if version from .bazelversion doesn't match bazel version, so just to use the latest one
|
|
rm_f ".bazelversion"
|
|
|
|
cmd = Language::Java.java_home_cmd("1.8")
|
|
ENV["JAVA_HOME"] = Utils.popen_read(cmd).chomp
|
|
|
|
venv = virtualenv_create("#{buildpath}/venv", "python3")
|
|
venv.pip_install resources
|
|
ENV["PYTHON_BIN_PATH"] = "#{buildpath}/venv/bin/python"
|
|
|
|
ENV["CC_OPT_FLAGS"] = "-march=native"
|
|
ENV["TF_IGNORE_MAX_BAZEL_VERSION"] = "1"
|
|
ENV["TF_NEED_JEMALLOC"] = "1"
|
|
ENV["TF_NEED_GCP"] = "0"
|
|
ENV["TF_NEED_HDFS"] = "0"
|
|
ENV["TF_ENABLE_XLA"] = "0"
|
|
ENV["USE_DEFAULT_PYTHON_LIB_PATH"] = "1"
|
|
ENV["TF_NEED_OPENCL"] = "0"
|
|
ENV["TF_NEED_CUDA"] = "0"
|
|
ENV["TF_NEED_MKL"] = "0"
|
|
ENV["TF_NEED_VERBS"] = "0"
|
|
ENV["TF_NEED_MPI"] = "0"
|
|
ENV["TF_NEED_S3"] = "1"
|
|
ENV["TF_NEED_GDR"] = "0"
|
|
ENV["TF_NEED_KAFKA"] = "0"
|
|
ENV["TF_NEED_OPENCL_SYCL"] = "0"
|
|
ENV["TF_NEED_ROCM"] = "0"
|
|
ENV["TF_DOWNLOAD_CLANG"] = "0"
|
|
ENV["TF_SET_ANDROID_WORKSPACE"] = "0"
|
|
ENV["TF_CONFIGURE_IOS"] = "0"
|
|
system "./configure"
|
|
|
|
bazel_args =%W[
|
|
--jobs=#{ENV.make_jobs}
|
|
--compilation_mode=opt
|
|
--copt=-march=native
|
|
]
|
|
targets = %w[
|
|
tensorflow:libtensorflow.so
|
|
]
|
|
system "bazel", "build", *bazel_args, *targets
|
|
|
|
lib.install Dir["bazel-bin/tensorflow/*.so*", "bazel-bin/tensorflow/*.dylib*"]
|
|
(include/"tensorflow/c").install %w[
|
|
tensorflow/c/c_api.h
|
|
tensorflow/c/c_api_experimental.h
|
|
tensorflow/c/tf_attrtype.h
|
|
tensorflow/c/tf_datatype.h
|
|
tensorflow/c/tf_status.h
|
|
tensorflow/c/tf_tensor.h
|
|
]
|
|
|
|
(lib/"pkgconfig/tensorflow.pc").write <<~EOS
|
|
Name: tensorflow
|
|
Description: Tensorflow library
|
|
Version: #{version}
|
|
Libs: -L#{lib} -ltensorflow
|
|
Cflags: -I#{include}
|
|
EOS
|
|
end
|
|
|
|
test do
|
|
(testpath/"test.c").write <<~EOS
|
|
#include <stdio.h>
|
|
#include <tensorflow/c/c_api.h>
|
|
int main() {
|
|
printf("%s", TF_Version());
|
|
}
|
|
EOS
|
|
system ENV.cc, "-L#{lib}", "-ltensorflow", "-o", "test_tf", "test.c"
|
|
assert_equal version, shell_output("./test_tf")
|
|
end
|
|
end
|