diff options
28 files changed, 625 insertions, 17 deletions
diff --git a/tensorflow/tools/pip_package/BUILD b/tensorflow/tools/pip_package/BUILD index 63323c8623..6d876b786a 100644 --- a/tensorflow/tools/pip_package/BUILD +++ b/tensorflow/tools/pip_package/BUILD @@ -12,6 +12,7 @@ load( load("//third_party/mkl:build_defs.bzl", "if_mkl") load("//tensorflow:tensorflow.bzl", "if_cuda") load("@local_config_tensorrt//:build_defs.bzl", "if_tensorrt") +load("@local_config_syslibs//:build_defs.bzl", "if_not_system_lib") load("//tensorflow/core:platform/default/build_config_root.bzl", "tf_additional_license_deps") # This returns a list of headers of all public header libraries (e.g., @@ -145,7 +146,6 @@ filegroup( "@gast_archive//:PKG-INFO", "@gemmlowp//:LICENSE", "@gif_archive//:COPYING", - "@grpc//:LICENSE", "@highwayhash//:LICENSE", "@jemalloc//:COPYING", "@jpeg//:LICENSE.md", @@ -154,8 +154,6 @@ filegroup( "@lmdb//:LICENSE", "@local_config_nccl//:LICENSE", "@local_config_sycl//sycl:LICENSE.text", - "@grpc//third_party/nanopb:LICENSE.txt", - "@grpc//third_party/address_sorting:LICENSE", "@nasm//:LICENSE", "@nsync//:LICENSE", "@pcre//:LICENCE", @@ -170,7 +168,14 @@ filegroup( ] + if_mkl([ "//third_party/mkl:LICENSE", "//third_party/mkl_dnn:LICENSE", - ]) + tf_additional_license_deps(), + ]) + if_not_system_lib( + "grpc", + [ + "@grpc//:LICENSE", + "@grpc//third_party/nanopb:LICENSE.txt", + "@grpc//third_party/address_sorting:LICENSE", + ], + ) + tf_additional_license_deps(), ) sh_binary( diff --git a/tensorflow/tools/pip_package/build_pip_package.sh b/tensorflow/tools/pip_package/build_pip_package.sh index b0089d3360..4101b34a11 100755 --- a/tensorflow/tools/pip_package/build_pip_package.sh +++ b/tensorflow/tools/pip_package/build_pip_package.sh @@ -27,7 +27,7 @@ function cp_external() { pushd . cd "$src_dir" - for f in `find . ! -type d ! -name '*.py' ! -path '*local_config_cuda*' ! -path '*local_config_tensorrt*' ! -path '*org_tensorflow*'`; do + for f in `find . ! -type d ! -name '*.py' ! -path '*local_config_cuda*' ! -path '*local_config_tensorrt*' ! -path '*local_config_syslibs*' ! -path '*org_tensorflow*'`; do mkdir -p "${dest_dir}/$(dirname ${f})" cp "${f}" "${dest_dir}/$(dirname ${f})/" done diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index ed654c3285..378de4261c 100644 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -8,6 +8,7 @@ load("//third_party/git:git_configure.bzl", "git_configure") load("//third_party/py:python_configure.bzl", "python_configure") load("//third_party/sycl:sycl_configure.bzl", "sycl_configure") +load("//third_party/systemlibs:syslibs_configure.bzl", "syslibs_configure") load("//third_party/toolchains/clang6:repo.bzl", "clang6_configure") load("//third_party/toolchains/cpus/arm:arm_compiler_configure.bzl", "arm_compiler_configure") load("//third_party:repo.bzl", "tf_http_archive") @@ -35,6 +36,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): nccl_configure(name="local_config_nccl") git_configure(name="local_config_git") sycl_configure(name="local_config_sycl") + syslibs_configure(name="local_config_syslibs") python_configure(name="local_config_python") # For windows bazel build @@ -161,6 +163,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): ], sha256 = "2f945446b71336e7f5a2bcace1abcf0b23fbba368266c6a1be33de3de3b3c912", strip_prefix = "re2-2018-04-01", + system_build_file = clean_dep("//third_party/systemlibs:re2.BUILD"), ) tf_http_archive( @@ -226,6 +229,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "63ec86477ad3f0f6292325fd89e1d93aea2e2fd490070863f17d48f7cd387011", strip_prefix = "nasm-2.13.03", build_file = clean_dep("//third_party:nasm.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:nasm.BUILD"), ) tf_http_archive( @@ -237,6 +241,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "1a17020f859cb12711175a67eab5c71fc1904e04b587046218e36106e07eabde", strip_prefix = "libjpeg-turbo-1.5.3", build_file = clean_dep("//third_party/jpeg:jpeg.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:jpeg.BUILD"), ) tf_http_archive( @@ -249,6 +254,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): strip_prefix = "libpng-1.6.34", build_file = clean_dep("//third_party:png.BUILD"), patch_file = clean_dep("//third_party:png_fix_rpi.patch"), + system_build_file = clean_dep("//third_party/systemlibs:png.BUILD"), ) tf_http_archive( @@ -260,6 +266,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "ad68c1216c3a474cf360c7581a4001e952515b3649342100f2d7ca7c8e313da6", strip_prefix = "sqlite-amalgamation-3240000", build_file = clean_dep("//third_party:sqlite.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:sqlite.BUILD"), ) tf_http_archive( @@ -271,6 +278,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "34a7377ba834397db019e8eb122e551a49c98f49df75ec3fcc92b9a794a4f6d1", strip_prefix = "giflib-5.1.4", build_file = clean_dep("//third_party:gif.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:gif.BUILD"), ) tf_http_archive( @@ -282,6 +290,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a", strip_prefix = "six-1.10.0", build_file = clean_dep("//third_party:six.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:six.BUILD"), ) tf_http_archive( @@ -293,6 +302,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "ff6d2e2962d834acb125cc4dcc80c54a8c17c253f4cc9d9c43b5102a560bb75d", strip_prefix = "astor-0.6.2", build_file = clean_dep("//third_party:astor.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:astor.BUILD"), ) tf_http_archive( @@ -315,6 +325,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "1d6d69ce66211143803fbc56652b41d73b4a400a2891d7bf7a1cdf4c02de613b", strip_prefix = "termcolor-1.1.0", build_file = clean_dep("//third_party:termcolor.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:termcolor.BUILD"), ) tf_http_archive( @@ -421,6 +432,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): ], strip_prefix = "pcre-8.42", build_file = clean_dep("//third_party:pcre.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:pcre.BUILD"), ) tf_http_archive( @@ -433,6 +445,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): ], strip_prefix = "swig-3.0.8", build_file = clean_dep("//third_party:swig.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:swig.BUILD"), ) tf_http_archive( @@ -444,6 +457,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): ], strip_prefix = "curl-7.60.0", build_file = clean_dep("//third_party:curl.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:curl.BUILD"), ) tf_http_archive( @@ -454,6 +468,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): ], sha256 = "50db9cf2221354485eb7c3bd55a4c27190caef7048a2a1a15fbe60a498f98b44", strip_prefix = "grpc-1.13.0", + system_build_file = clean_dep("//third_party/systemlibs:grpc.BUILD"), ) tf_http_archive( @@ -489,6 +504,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "f3927859882eb608868c8c31586bb7eb84562a40a6bf5cc3e13b6b564641ea28", strip_prefix = "lmdb-LMDB_0.9.22/libraries/liblmdb", build_file = clean_dep("//third_party:lmdb.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:lmdb.BUILD"), ) tf_http_archive( @@ -500,6 +516,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "c49deac9e0933bcb7044f08516861a2d560988540b23de2ac1ad443b219afdb6", strip_prefix = "jsoncpp-1.8.4", build_file = clean_dep("//third_party:jsoncpp.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:jsoncpp.BUILD"), ) tf_http_archive( @@ -521,6 +538,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", strip_prefix = "zlib-1.2.11", build_file = clean_dep("//third_party:zlib.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:zlib.BUILD"), ) tf_http_archive( @@ -542,6 +560,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "3dfa02e873ff51a11ee02b9ca391807f0c8ea0529a4924afa645fbf97163f9d4", strip_prefix = "snappy-1.1.7", build_file = clean_dep("//third_party:snappy.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:snappy.BUILD"), ) tf_http_archive( @@ -612,6 +631,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): sha256 = "3c8f25c02e806c3ce0ab5fb7da1817f89fc9732709024e2a81b6b82f7cc792a8", strip_prefix = "jemalloc-4.4.0", build_file = clean_dep("//third_party:jemalloc.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:jemalloc.BUILD"), ) java_import_external( @@ -690,6 +710,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): strip_prefix = "cython-0.28.4", build_file = clean_dep("//third_party:cython.BUILD"), delete = ["BUILD.bazel"], + system_build_file = clean_dep("//third_party/systemlibs:cython.BUILD"), ) tf_http_archive( @@ -722,6 +743,7 @@ def tf_workspace(path_prefix="", tf_repo_name=""): "https://github.com/google/flatbuffers/archive/v1.9.0.tar.gz", ], build_file = clean_dep("//third_party/flatbuffers:flatbuffers.BUILD"), + system_build_file = clean_dep("//third_party/systemlibs:flatbuffers.BUILD"), ) native.new_http_archive( diff --git a/third_party/repo.bzl b/third_party/repo.bzl index 9cee1fcc4b..5cb42691c5 100644 --- a/third_party/repo.bzl +++ b/third_party/repo.bzl @@ -35,6 +35,15 @@ def _get_env_var(ctx, name): else: return None +# Checks if we should use the system lib instead of the bundled one +def _use_system_lib(ctx, name): + syslibenv = _get_env_var(ctx, "TF_SYSTEM_LIBS") + if syslibenv: + for n in syslibenv.strip().split(","): + if n.strip() == name: + return True + return False + # Executes specified command with arguments and calls 'fail' if it exited with # non-zero code def _execute_and_check_ret_code(repo_ctx, cmd_and_args): @@ -75,17 +84,28 @@ def _tf_http_archive(ctx): "Even if you don't have permission to mirror the file, please " + "put the correctly formatted mirror URL there anyway, because " + "someone will come along shortly thereafter and mirror the file.") - ctx.download_and_extract( - ctx.attr.urls, - "", - ctx.attr.sha256, - ctx.attr.type, - ctx.attr.strip_prefix) - if ctx.attr.delete: - _apply_delete(ctx, ctx.attr.delete) - if ctx.attr.patch_file != None: - _apply_patch(ctx, ctx.attr.patch_file) - if ctx.attr.build_file != None: + + use_syslib = _use_system_lib(ctx, ctx.attr.name) + if not use_syslib: + ctx.download_and_extract( + ctx.attr.urls, + "", + ctx.attr.sha256, + ctx.attr.type, + ctx.attr.strip_prefix) + if ctx.attr.delete: + _apply_delete(ctx, ctx.attr.delete) + if ctx.attr.patch_file != None: + _apply_patch(ctx, ctx.attr.patch_file) + + if use_syslib and ctx.attr.system_build_file != None: + # Use BUILD.bazel to avoid conflict with third party projects with + # BUILD or build (directory) underneath. + ctx.template("BUILD.bazel", ctx.attr.system_build_file, { + "%prefix%": ".." if _repos_are_siblings() else "external", + }, False) + + elif ctx.attr.build_file != None: # Use BUILD.bazel to avoid conflict with third party projects with # BUILD or build (directory) underneath. ctx.template("BUILD.bazel", ctx.attr.build_file, { @@ -102,7 +122,11 @@ tf_http_archive = repository_rule( "delete": attr.string_list(), "patch_file": attr.label(), "build_file": attr.label(), - }) + "system_build_file": attr.label(), + }, + environ=[ + "TF_SYSTEM_LIBS", + ]) """Downloads and creates Bazel repos for dependencies. This is a swappable replacement for both http_archive() and diff --git a/third_party/systemlibs/BUILD b/third_party/systemlibs/BUILD new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/third_party/systemlibs/BUILD diff --git a/third_party/systemlibs/BUILD.tpl b/third_party/systemlibs/BUILD.tpl new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/third_party/systemlibs/BUILD.tpl diff --git a/third_party/systemlibs/astor.BUILD b/third_party/systemlibs/astor.BUILD new file mode 100644 index 0000000000..497ec4bcea --- /dev/null +++ b/third_party/systemlibs/astor.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # New BSD + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +py_library( + name = "astor", + srcs_version = "PY2AND3", + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/build_defs.bzl.tpl b/third_party/systemlibs/build_defs.bzl.tpl new file mode 100644 index 0000000000..3faa46c581 --- /dev/null +++ b/third_party/systemlibs/build_defs.bzl.tpl @@ -0,0 +1,32 @@ +# -*- Python -*- +"""Skylark macros for system libraries. +""" + +SYSTEM_LIBS_ENABLED = %{syslibs_enabled} + +SYSTEM_LIBS_LIST = [ +%{syslibs_list} +] + + +def if_any_system_libs(a, b=[]): + """Conditional which evaluates to 'a' if any system libraries are configured.""" + if SYSTEM_LIBS_ENABLED: + return a + else: + return b + + +def if_system_lib(lib, a, b=[]): + """Conditional which evaluates to 'a' if we're using the system version of lib""" + + if SYSTEM_LIBS_ENABLED and lib in SYSTEM_LIBS_LIST: + return a + else: + return b + + +def if_not_system_lib(lib, a, b=[]): + """Conditional which evaluates to 'a' if we're using the system version of lib""" + + return if_system_lib(lib, b, a) diff --git a/third_party/systemlibs/curl.BUILD b/third_party/systemlibs/curl.BUILD new file mode 100644 index 0000000000..c5f125caa9 --- /dev/null +++ b/third_party/systemlibs/curl.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # MIT/X derivative license + +filegroup( + name = "COPYING", + visibility = ["//visibility:public"], +) + +cc_library( + name = "curl", + linkopts = ["-lcurl"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/cython.BUILD b/third_party/systemlibs/cython.BUILD new file mode 100644 index 0000000000..1d52587676 --- /dev/null +++ b/third_party/systemlibs/cython.BUILD @@ -0,0 +1,13 @@ +licenses(["notice"]) # Apache-2.0 + +genrule( + name = "lncython", + outs = ["cython"], + cmd = "ln -s $$(which cython) $@", +) + +sh_binary( + name = "cython_binary", + srcs = ["cython"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/flatbuffers.BUILD b/third_party/systemlibs/flatbuffers.BUILD new file mode 100644 index 0000000000..14fceada82 --- /dev/null +++ b/third_party/systemlibs/flatbuffers.BUILD @@ -0,0 +1,38 @@ +licenses(["notice"]) # Apache 2.0 + +filegroup( + name = "LICENSE.txt", + visibility = ["//visibility:public"], +) + +# Public flatc library to compile flatbuffer files at runtime. +cc_library( + name = "flatbuffers", + linkopts = ["-lflatbuffers"], + visibility = ["//visibility:public"], +) + +# Public flatc compiler library. +cc_library( + name = "flatc_library", + linkopts = ["-lflatbuffers"], + visibility = ["//visibility:public"], +) + +genrule( + name = "lnflatc", + outs = ["flatc.bin"], + cmd = "ln -s $$(which flatc) $@", +) + +# Public flatc compiler. +sh_binary( + name = "flatc", + srcs = ["flatc.bin"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "runtime_cc", + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/gif.BUILD b/third_party/systemlibs/gif.BUILD new file mode 100644 index 0000000000..5eb2c918ba --- /dev/null +++ b/third_party/systemlibs/gif.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # MIT + +filegroup( + name = "COPYING", + visibility = ["//visibility:public"], +) + +cc_library( + name = "gif", + linkopts = ["-lgif"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/grpc.BUILD b/third_party/systemlibs/grpc.BUILD new file mode 100644 index 0000000000..fd90eb0dd3 --- /dev/null +++ b/third_party/systemlibs/grpc.BUILD @@ -0,0 +1,54 @@ +licenses(["notice"]) # Apache v2 + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +cc_library( + name = "grpc", + linkopts = ["-lgrpc"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "grpc++", + linkopts = ["-lgrpc++"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "grpc_unsecure", + linkopts = ["-lgrpc_unsecure"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "grpc++_unsecure", + linkopts = ["-lgrpc++_unsecure"], + visibility = ["//visibility:public"], +) + +genrule( + name = "ln_grpc_cpp_plugin", + outs = ["grpc_cpp_plugin.bin"], + cmd = "ln -s $$(which grpc_cpp_plugin) $@", +) + +sh_binary( + name = "grpc_cpp_plugin", + srcs = ["grpc_cpp_plugin.bin"], + visibility = ["//visibility:public"], +) + +genrule( + name = "ln_grpc_python_plugin", + outs = ["grpc_python_plugin.bin"], + cmd = "ln -s $$(which grpc_python_plugin) $@", +) + +sh_binary( + name = "grpc_python_plugin", + srcs = ["grpc_python_plugin.bin"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/jemalloc.BUILD b/third_party/systemlibs/jemalloc.BUILD new file mode 100644 index 0000000000..6a48d582ba --- /dev/null +++ b/third_party/systemlibs/jemalloc.BUILD @@ -0,0 +1,30 @@ +licenses(["notice"]) # BSD + +filegroup( + name = "COPYING", + visibility = ["//visibility:public"], +) + +cc_library( + name = "jemalloc_headers", + defines = [ + "jemalloc_posix_memalign=posix_memalign", + "jemalloc_malloc=malloc", + "jemalloc_realloc=realloc", + "jemalloc_free=free", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "jemalloc_impl", + linkopts = ["-ljemalloc"], + defines = [ + "jemalloc_posix_memalign=posix_memalign", + "jemalloc_malloc=malloc", + "jemalloc_realloc=realloc", + "jemalloc_free=free", + ], + visibility = ["//visibility:public"], + deps = [":jemalloc_headers"], +) diff --git a/third_party/systemlibs/jpeg.BUILD b/third_party/systemlibs/jpeg.BUILD new file mode 100644 index 0000000000..f4f52da9bd --- /dev/null +++ b/third_party/systemlibs/jpeg.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # custom notice-style license, see LICENSE.md + +filegroup( + name = "LICENSE.md", + visibility = ["//visibility:public"], +) + +cc_library( + name = "jpeg", + linkopts = ["-ljpeg"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/jsoncpp.BUILD b/third_party/systemlibs/jsoncpp.BUILD new file mode 100644 index 0000000000..cf91917cfb --- /dev/null +++ b/third_party/systemlibs/jsoncpp.BUILD @@ -0,0 +1,37 @@ +licenses(["unencumbered"]) # Public Domain or MIT + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +HEADERS = [ + "include/json/autolink.h", + "include/json/config.h", + "include/json/features.h", + "include/json/forwards.h", + "include/json/json.h", + "include/json/reader.h", + "include/json/value.h", + "include/json/version.h", + "include/json/writer.h", +] + +genrule( + name = "link_headers", + outs = HEADERS, + cmd = """ + for i in $(OUTS); do + i=$${i##*/} + ln -vsf /usr/include/jsoncpp/json/$$i $(@D)/include/json/$$i + done + """, +) + +cc_library( + name = "jsoncpp", + hdrs = HEADERS, + includes = ["."], + linkopts = ["-ljsoncpp"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/lmdb.BUILD b/third_party/systemlibs/lmdb.BUILD new file mode 100644 index 0000000000..6177b095ec --- /dev/null +++ b/third_party/systemlibs/lmdb.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # OpenLDAP Public License + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +cc_library( + name = "lmdb", + linkopts = ["-llmdb"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/nasm.BUILD b/third_party/systemlibs/nasm.BUILD new file mode 100644 index 0000000000..10ef8d8832 --- /dev/null +++ b/third_party/systemlibs/nasm.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD 2-clause + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +sh_binary( + name = "nasm", + srcs = ["nasm"], + visibility = ["@jpeg//:__pkg__"], +) diff --git a/third_party/systemlibs/pcre.BUILD b/third_party/systemlibs/pcre.BUILD new file mode 100644 index 0000000000..df74238847 --- /dev/null +++ b/third_party/systemlibs/pcre.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD + +filegroup( + name = "LICENCE", + visibility = ["//visibility:public"], +) + +cc_library( + name = "pcre", + linkopts = ["-lpcre"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/png.BUILD b/third_party/systemlibs/png.BUILD new file mode 100644 index 0000000000..fc6b6f2d8b --- /dev/null +++ b/third_party/systemlibs/png.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD/MIT-like license + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +cc_library( + name = "png", + linkopts = ["-lpng"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/re2.BUILD b/third_party/systemlibs/re2.BUILD new file mode 100644 index 0000000000..c18e252dbc --- /dev/null +++ b/third_party/systemlibs/re2.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD/MIT-like license + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +cc_library( + name = "re2", + linkopts = ["-lre2"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/six.BUILD b/third_party/systemlibs/six.BUILD new file mode 100644 index 0000000000..ff9b1a540b --- /dev/null +++ b/third_party/systemlibs/six.BUILD @@ -0,0 +1,11 @@ +licenses(["notice"]) # MIT + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +py_library( + name = "six", + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/snappy.BUILD b/third_party/systemlibs/snappy.BUILD new file mode 100644 index 0000000000..fd2db9e2df --- /dev/null +++ b/third_party/systemlibs/snappy.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD 3-Clause + +filegroup( + name = "COPYING", + visibility = ["//visibility:public"], +) + +cc_library( + name = "snappy", + linkopts = ["-lsnappy"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/sqlite.BUILD b/third_party/systemlibs/sqlite.BUILD new file mode 100644 index 0000000000..20ee1ebbef --- /dev/null +++ b/third_party/systemlibs/sqlite.BUILD @@ -0,0 +1,15 @@ +licenses(["unencumbered"]) # Public Domain + +# Production build of SQLite library that's baked into TensorFlow. +cc_library( + name = "org_sqlite", + linkopts = ["-lsqlite3"], + visibility = ["//visibility:public"], +) + +# This is a Copybara sync helper for Google. +py_library( + name = "python", + srcs_version = "PY2AND3", + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/swig.BUILD b/third_party/systemlibs/swig.BUILD new file mode 100644 index 0000000000..4c9b74dadb --- /dev/null +++ b/third_party/systemlibs/swig.BUILD @@ -0,0 +1,23 @@ +licenses(["restricted"]) # GPLv3 + +filegroup( + name = "LICENSE", + visibility = ["//visibility:public"], +) + +filegroup( + name = "templates", + visibility = ["//visibility:public"], +) + +genrule( + name = "lnswiglink", + outs = ["swiglink"], + cmd = "ln -s $$(which swig) $@", +) + +sh_binary( + name = "swig", + srcs = ["swiglink"], + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/syslibs_configure.bzl b/third_party/systemlibs/syslibs_configure.bzl new file mode 100644 index 0000000000..07a44c317e --- /dev/null +++ b/third_party/systemlibs/syslibs_configure.bzl @@ -0,0 +1,160 @@ +# -*- Python -*- +"""Repository rule for system library autoconfiguration. + +`syslibs_configure` depends on the following environment variables: + + * `TF_SYSTEM_LIBS`: list of third party dependencies that should use + the system version instead +""" + +_TF_SYSTEM_LIBS="TF_SYSTEM_LIBS" + +VALID_LIBS=[ + "astor_archive", + "com_googlesource_code_re2", + "curl", + "cython", + "flatbuffers", + "gif_archive", + "grpc", + "jemalloc", + "jpeg", + "jsoncpp_git", + "lmdb", + "nasm", + "org_sqlite", + "pcre", + "png_archive", + "six_archive", + "snappy", + "swig", + "termcolor_archive", + "zlib_archive", +] + + +def auto_configure_fail(msg): + """Output failure message when syslibs configuration fails.""" + red = "\033[0;31m" + no_color = "\033[0m" + fail("\n%sSystem Library Configuration Error:%s %s\n" % (red, no_color, msg)) + + +def _is_windows(repository_ctx): + """Returns true if the host operating system is windows.""" + os_name = repository_ctx.os.name.lower() + if os_name.find("windows") != -1: + return True + return False + + +def _enable_syslibs(repository_ctx): + s = repository_ctx.os.environ.get(_TF_SYSTEM_LIBS, '').strip() + if not _is_windows(repository_ctx) and s != None and s != '': + return True + return False + + +def _get_system_lib_list(repository_ctx): + """Gets the list of deps that should use the system lib. + + Args: + repository_ctx: The repository context. + + Returns: + A string version of a python list + """ + if _TF_SYSTEM_LIBS not in repository_ctx.os.environ: + return [] + + libenv = repository_ctx.os.environ[_TF_SYSTEM_LIBS].strip() + libs = [] + + for lib in list(libenv.split(',')): + lib = lib.strip() + if lib == "": + continue + if lib not in VALID_LIBS: + auto_configure_fail("Invalid system lib set: %s" % lib) + return [] + libs.append(lib) + + return libs + + +def _format_system_lib_list(repository_ctx): + """Formats the list of deps that should use the system lib. + + Args: + repository_ctx: The repository context. + + Returns: + A list of the names of deps that should use the system lib. + """ + libs = _get_system_lib_list(repository_ctx) + ret = '' + for lib in libs: + ret += "'%s',\n" % lib + + return ret + + +def _tpl(repository_ctx, tpl, substitutions={}, out=None): + if not out: + out = tpl.replace(":", "") + repository_ctx.template( + out, + Label("//third_party/systemlibs%s.tpl" % tpl), + substitutions, + False) + + +def _create_dummy_repository(repository_ctx): + """Creates the dummy repository to build with all bundled libraries.""" + + _tpl(repository_ctx, ":BUILD") + _tpl(repository_ctx, ":build_defs.bzl", + { + "%{syslibs_enabled}": 'False', + "%{syslibs_list}": '', + }) + + +def _create_local_repository(repository_ctx): + """Creates the repository to build with system libraries.""" + + _tpl(repository_ctx, ":BUILD") + _tpl(repository_ctx, ":build_defs.bzl", + { + "%{syslibs_enabled}": 'True', + "%{syslibs_list}": _format_system_lib_list(repository_ctx), + }) + + +def _syslibs_autoconf_impl(repository_ctx): + """Implementation of the syslibs_configure repository rule.""" + if not _enable_syslibs(repository_ctx): + _create_dummy_repository(repository_ctx) + else: + _create_local_repository(repository_ctx) + + +syslibs_configure = repository_rule( + implementation = _syslibs_autoconf_impl, + environ = [ + _TF_SYSTEM_LIBS, + ], +) + +"""Configures the build to link to system libraries +instead of using bundled versions. + +Add the following to your WORKSPACE FILE: + +```python +syslibs_configure(name = "local_config_syslibs") +``` + +Args: + name: A unique name for this workspace rule. +""" diff --git a/third_party/systemlibs/termcolor.BUILD b/third_party/systemlibs/termcolor.BUILD new file mode 100644 index 0000000000..915eb621d5 --- /dev/null +++ b/third_party/systemlibs/termcolor.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # MIT + +filegroup( + name = "COPYING.txt", + visibility = ["//visibility:public"], +) + +py_library( + name = "termcolor", + srcs_version = "PY2AND3", + visibility = ["//visibility:public"], +) diff --git a/third_party/systemlibs/zlib.BUILD b/third_party/systemlibs/zlib.BUILD new file mode 100644 index 0000000000..69462ae6cb --- /dev/null +++ b/third_party/systemlibs/zlib.BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # BSD/MIT-like license (for zlib) + +filegroup( + name = "zlib.h", + visibility = ["//visibility:public"], +) + +cc_library( + name = "zlib", + linkopts = ["-lz"], + visibility = ["//visibility:public"], +) |