diff options
author | Asim Shankar <ashankar@google.com> | 2017-01-18 07:57:08 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-01-18 08:05:27 -0800 |
commit | 31f7498f9731e259ddb5021fc76b7b9eca782c68 (patch) | |
tree | 3ac8d7a78eaa2fbc1681dc03d8b88dbe6f84509d /tensorflow/tools/lib_package | |
parent | 7cf8f65d0f62c0ecbcf0a6f856e854a39e3d6a64 (diff) |
Automated rollback of change 144673014
Change: 144834404
Diffstat (limited to 'tensorflow/tools/lib_package')
-rw-r--r-- | tensorflow/tools/lib_package/BUILD | 107 | ||||
-rw-r--r-- | tensorflow/tools/lib_package/README.md | 31 | ||||
-rwxr-xr-x | tensorflow/tools/lib_package/concat_licenses.sh | 28 | ||||
-rw-r--r-- | tensorflow/tools/lib_package/libtensorflow_test.c | 28 | ||||
-rwxr-xr-x | tensorflow/tools/lib_package/libtensorflow_test.sh | 48 |
5 files changed, 242 insertions, 0 deletions
diff --git a/tensorflow/tools/lib_package/BUILD b/tensorflow/tools/lib_package/BUILD new file mode 100644 index 0000000000..41e7221efe --- /dev/null +++ b/tensorflow/tools/lib_package/BUILD @@ -0,0 +1,107 @@ +# Packaging the TensorFlow C API into a small, standalone archive for use with +# language bindings and installations without Python. +# +# TODO(ashankar): Something similar for the JNI library for Java? +# TODO(ashankar): Something similar for the C++ API (caveat: ABI compatibility) + +package(default_visibility = ["//visibility:private"]) + +load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") + +pkg_tar( + name = "libtensorflow", + extension = "tar.gz", + # Mark as "manual" till + # https://github.com/bazelbuild/bazel/issues/2352 + # and https://github.com/bazelbuild/bazel/issues/1580 + # are resolved, otherwise these rules break when built + # with Python 3. + tags = ["manual"], + deps = [ + ":cheaders", + ":clib", + ":clicenses", + ], +) + +pkg_tar( + name = "cheaders", + files = ["//tensorflow/c:headers"], + package_dir = "include/tensorflow/c", + # Mark as "manual" till + # https://github.com/bazelbuild/bazel/issues/2352 + # and https://github.com/bazelbuild/bazel/issues/1580 + # are resolved, otherwise these rules break when built + # with Python 3. + tags = ["manual"], +) + +pkg_tar( + name = "clib", + files = ["//tensorflow:libtensorflow.so"], + package_dir = "lib", + # Mark as "manual" till + # https://github.com/bazelbuild/bazel/issues/2352 + # and https://github.com/bazelbuild/bazel/issues/1580 + # are resolved, otherwise these rules break when built + # with Python 3. + tags = ["manual"], +) + +pkg_tar( + name = "clicenses", + files = [":include/tensorflow/c/LICENSE"], + package_dir = "include/tensorflow/c", + # Mark as "manual" till + # https://github.com/bazelbuild/bazel/issues/2352 + # and https://github.com/bazelbuild/bazel/issues/1580 + # are resolved, otherwise these rules break when built + # with Python 3. + tags = ["manual"], +) + +genrule( + name = "clicenses_generate", + srcs = [ + "//third_party/hadoop:LICENSE.txt", + "//third_party/eigen3:LICENSE", + "@boringssl//:LICENSE", + "@com_googlesource_code_re2//:LICENSE", + "@curl//:COPYING", + "@eigen_archive//:COPYING.MPL2", + "@farmhash_archive//:COPYING", + "@gemmlowp//:LICENSE", + "@gif_archive//:COPYING", + "@grpc//:LICENSE", + "@highwayhash//:LICENSE", + "@jemalloc//:COPYING", + "@jpeg//:LICENSE.md", + "@libxsmm_archive//:LICENSE", + "@local_config_sycl//sycl:LICENSE.text", + "@nanopb_git//:LICENSE.txt", + "@png_archive//:LICENSE", + "@protobuf//:LICENSE", + "@zlib_archive//:zlib.h", + ], + outs = ["include/tensorflow/c/LICENSE"], + cmd = "$(location :concat_licenses.sh) $(SRCS) >$@", + tools = [":concat_licenses.sh"], +) + +sh_test( + name = "libtensorflow_test", + size = "small", + srcs = ["libtensorflow_test.sh"], + data = [ + "libtensorflow_test.c", + ":libtensorflow.tar.gz", + ], + # Mark as "manual" till + # https://github.com/bazelbuild/bazel/issues/2352 + # and https://github.com/bazelbuild/bazel/issues/1580 + # are resolved, otherwise these rules break when built + # with Python 3. + # Till then, this test is explicitly executed when building + # the release by tensorflow/tools/ci_build/builds/libtensorflow.sh + tags = ["manual"], +) diff --git a/tensorflow/tools/lib_package/README.md b/tensorflow/tools/lib_package/README.md new file mode 100644 index 0000000000..fbec0a067a --- /dev/null +++ b/tensorflow/tools/lib_package/README.md @@ -0,0 +1,31 @@ +Bazel rules to package the TensorFlow C-library and [header +files](https://www.tensorflow.org/code/tensorflow/c/c_api.h) +into an archive. + +## TensorFlow C library + +The TensorFlow [C +API](https://www.tensorflow.org/code/tensorflow/c/c_api.h) +is typically a requirement of TensorFlow APIs in other languages such as +[Go](https://www.tensorflow.org/code/tensorflow/go) +and [Rust](https://github.com/tensorflow/rust). + +The command: + +```sh +bazel build -c opt //tensorflow/tools/lib_package:libtensorflow +``` + +produces `bazel-bin/tensorflow/tools/lib_package/libtensorflow.tar.gz`, which +can be distributed and installed using something like: + +```sh +tar -C /usr/local -xzf libtensorflow.tar.gz +``` + +## Release + +Scripts to generate archives using these rules for release are in +[tensorflow/tools/ci_build/linux](https://www.tensorflow.org/code/tensorflow/tools/ci_build/linux) +and +[tensorflow/tools/ci_build/osx](https://www.tensorflow.org/code/tensorflow/tools/ci_build/osx) diff --git a/tensorflow/tools/lib_package/concat_licenses.sh b/tensorflow/tools/lib_package/concat_licenses.sh new file mode 100755 index 0000000000..2070f64e9f --- /dev/null +++ b/tensorflow/tools/lib_package/concat_licenses.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +# +# Script aimed to combining multiple license files into a single one. + +for f in $@ +do + echo "--------------------------------------------------------------------------------" + echo "BEGIN LICENSE FOR $f" + echo "--------------------------------------------------------------------------------" + cat $f + echo "--------------------------------------------------------------------------------" + echo "END LICENSE FOR $f" + echo "--------------------------------------------------------------------------------" +done diff --git a/tensorflow/tools/lib_package/libtensorflow_test.c b/tensorflow/tools/lib_package/libtensorflow_test.c new file mode 100644 index 0000000000..dff6fb77ec --- /dev/null +++ b/tensorflow/tools/lib_package/libtensorflow_test.c @@ -0,0 +1,28 @@ +/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Companion source file for libtensorflow_test.sh + +#include <tensorflow/c/c_api.h> + +int main() { + TF_Status* s = TF_NewStatus(); + TF_SetStatus(s, TF_UNKNOWN, "Some error"); + if (TF_GetCode(s) != TF_UNKNOWN) { + return 1; + } + TF_DeleteStatus(s); + return 0; +} diff --git a/tensorflow/tools/lib_package/libtensorflow_test.sh b/tensorflow/tools/lib_package/libtensorflow_test.sh new file mode 100755 index 0000000000..6463ecea70 --- /dev/null +++ b/tensorflow/tools/lib_package/libtensorflow_test.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Copyright 2016 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +set -ex + +# Sanity test for the package C-library archive. +# - Unarchive +# - Compile a trivial C file that uses the archive +# - Run it + +# Tools needed: A C-compiler and tar +CC="${CC}" +TAR="${TAR}" + +[ -z "${CC}" ] && CC="/usr/bin/gcc" +[ -z "${TAR}"] && TAR="tar" + +# bazel tests run with ${PWD} set to the root of the bazel workspace +TARFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow.tar.gz" +CFILE="${PWD}/tensorflow/tools/lib_package/libtensorflow_test.c" + +cd ${TEST_TMPDIR} + +# Extract the archive into tensorflow/ +mkdir tensorflow +${TAR} -xzf ${TARFILE} -Ctensorflow + +# Compile the test .c file +${CC} ${CFILE} -Itensorflow/include -Ltensorflow/lib -ltensorflow -oa.out + +# Execute it, with the shared library available. +# DYLD_LIBRARY_PATH is used on OS X, LD_LIBRARY_PATH on Linux +export DYLD_LIBRARY_PATH=tensorflow/lib +export LD_LIBRARY_PATH=tensorflow/lib +./a.out |