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.0.0.tar.gz" sha256 "49b5f0495cd681cbcb5296a4476853d4aea19a43bdd9f179c928a977308a0617" bottle do cellar :any sha256 "a338993572cfa5bfa0ab375e02284012659e2fe1a71e0fa94572d28c8a890cf4" => :catalina sha256 "a338993572cfa5bfa0ab375e02284012659e2fe1a71e0fa94572d28c8a890cf4" => :mojave sha256 "5a80f27525dbb8e21244c792e256e444b617321d83d96cc6e3eb706a5b498e10" => :high_sierra end depends_on "bazel" => :build depends_on :java => ["1.8", :build] depends_on "python" => :build def install venv_root = "#{buildpath}/venv" virtualenv_create(venv_root, "python3") cmd = Language::Java.java_home_cmd("1.8") ENV["JAVA_HOME"] = Utils.popen_read(cmd).chomp ENV["PYTHON_BIN_PATH"] = "#{venv_root}/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" system "bazel", "build", "--jobs", ENV.make_jobs, "--compilation_mode=opt", "--copt=-march=native", "tensorflow:libtensorflow.so" 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 #include 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