homebrew-core/Formula/libtensorflow.rb
2018-11-06 00:17:22 +01:00

64 lines
2.1 KiB
Ruby

class Libtensorflow < Formula
desc "C interface for Google's OS library for Machine Intelligence"
homepage "https://www.tensorflow.org/"
url "https://github.com/tensorflow/tensorflow/archive/v1.11.0.tar.gz"
sha256 "f49ce3f1d04cee854bc9f74fa9696991140b34a2e2447f35f01391b72c8bfa9f"
bottle do
cellar :any
sha256 "17d24f41a141f61d1e1002b922af489425484b3ec3c11ace9c39d5db69a3454b" => :mojave
sha256 "24c5188904edd4c4834c1c70824b0f4687955975aa163eb0553a52744e3dc974" => :high_sierra
sha256 "c9444e684dfd38a879378501ba085002117a63e3c06faafc6ec11a841aa9ee72" => :sierra
end
depends_on "bazel" => :build
depends_on :java => ["1.8", :build]
def install
cmd = Language::Java.java_home_cmd("1.8")
ENV["JAVA_HOME"] = Utils.popen_read(cmd).chomp
ENV["PYTHON_BIN_PATH"] = which("python").to_s
ENV["CC_OPT_FLAGS"] = "-march=native"
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_DOWNLOAD_CLANG"] = "0"
ENV["TF_SET_ANDROID_WORKSPACE"] = "0"
system "./configure"
system "bazel", "build", "--compilation_mode=opt", "--copt=-march=native", "tensorflow:libtensorflow.so"
lib.install Dir["bazel-bin/tensorflow/*.so"]
(include/"tensorflow/c").install "tensorflow/c/c_api.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