diff --git a/.bazelrc b/.bazelrc index 9ac5a1bbf40..99bf0c9166b 100644 --- a/.bazelrc +++ b/.bazelrc @@ -123,6 +123,11 @@ build:monolithic --define framework_shared_object=false # opts in to modular op registration support by default. build --define framework_shared_object=true +# As part of Tensorflow's build refactoring, https://github.com/tensorflow/community/pull/179, +# we plan on migrating TF to use bazel's cc_shared_library. This requires always setting +# the flag "--experimental_cc_shared_library" on all builds: https://github.com/bazelbuild/rules_cc/blob/7e650b11fe6d49f70f2ca7a1c4cb8bcc4a1fe239/examples/experimental_cc_shared_library.bzl#L3-L5 +build --experimental_cc_shared_library + # Flags for open source build, always set to be true. build --define open_source_build=true test --define open_source_build=true diff --git a/tensorflow/BUILD b/tensorflow/BUILD index d8a681c3999..6bfcdca7a9e 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -478,6 +478,7 @@ bzl_library( visibility = ["//visibility:public"], deps = [ "//tensorflow/core/platform:build_config_root_bzl", + "//tensorflow/core/platform:rules_cc_bzl", "//tensorflow/core/platform/default:cuda_build_defs_bzl", "//third_party/mkl:build_defs_bzl", "//third_party/mkl_dnn:build_defs_bzl", diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index b32acbedcf1..d70ef895fea 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -132,6 +132,10 @@ load( "tf_protos_profiler_impl", "tf_pyclif_proto_library", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) load( "//tensorflow/core/platform:build_config_root.bzl", "if_dynamic_kernels", diff --git a/tensorflow/core/framework/BUILD b/tensorflow/core/framework/BUILD index eae10268f5d..70635a36a47 100644 --- a/tensorflow/core/framework/BUILD +++ b/tensorflow/core/framework/BUILD @@ -15,6 +15,10 @@ load( "//tensorflow/core/platform:build_config_root.bzl", "if_static", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = [ diff --git a/tensorflow/core/lib/bfloat16/BUILD b/tensorflow/core/lib/bfloat16/BUILD index 4f955c37f3f..d78bee42461 100644 --- a/tensorflow/core/lib/bfloat16/BUILD +++ b/tensorflow/core/lib/bfloat16/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ "//tensorflow:__subpackages__", diff --git a/tensorflow/core/lib/core/BUILD b/tensorflow/core/lib/core/BUILD index a3ed21f8771..28213f0b790 100644 --- a/tensorflow/core/lib/core/BUILD +++ b/tensorflow/core/lib/core/BUILD @@ -1,4 +1,8 @@ load("//tensorflow/core/platform:build_config.bzl", "tf_proto_library") +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = [ diff --git a/tensorflow/core/lib/db/BUILD b/tensorflow/core/lib/db/BUILD index bf24de9a70c..b3b941a2dfd 100644 --- a/tensorflow/core/lib/db/BUILD +++ b/tensorflow/core/lib/db/BUILD @@ -2,6 +2,10 @@ # Libraries for storing tensors in SQL databases. load("//tensorflow:tensorflow.bzl", "tf_cc_test", "tf_copts") +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = ["//tensorflow:internal"], diff --git a/tensorflow/core/lib/gtl/BUILD b/tensorflow/core/lib/gtl/BUILD index ffac0ce12ea..4adae6575eb 100644 --- a/tensorflow/core/lib/gtl/BUILD +++ b/tensorflow/core/lib/gtl/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/lib/hash/BUILD b/tensorflow/core/lib/hash/BUILD index ffe5ef957c2..1d7039fbcd2 100644 --- a/tensorflow/core/lib/hash/BUILD +++ b/tensorflow/core/lib/hash/BUILD @@ -3,6 +3,10 @@ load( "if_linux_x86_64", "tf_copts", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = [ diff --git a/tensorflow/core/lib/histogram/BUILD b/tensorflow/core/lib/histogram/BUILD index 9108a09dd15..de72187a5bf 100644 --- a/tensorflow/core/lib/histogram/BUILD +++ b/tensorflow/core/lib/histogram/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/lib/io/BUILD b/tensorflow/core/lib/io/BUILD index 8f8e0dd0da8..5616b8153b7 100644 --- a/tensorflow/core/lib/io/BUILD +++ b/tensorflow/core/lib/io/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ "//tensorflow/c/experimental/filesystem:__pkg__", diff --git a/tensorflow/core/lib/math/BUILD b/tensorflow/core/lib/math/BUILD index 07d0a3e07cd..063e5db5401 100644 --- a/tensorflow/core/lib/math/BUILD +++ b/tensorflow/core/lib/math/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ "//tensorflow:__subpackages__", diff --git a/tensorflow/core/lib/monitoring/BUILD b/tensorflow/core/lib/monitoring/BUILD index ef796fd4663..62744a5e3e0 100644 --- a/tensorflow/core/lib/monitoring/BUILD +++ b/tensorflow/core/lib/monitoring/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/lib/png/BUILD b/tensorflow/core/lib/png/BUILD index 56bdba7172a..db2ab4801ee 100644 --- a/tensorflow/core/lib/png/BUILD +++ b/tensorflow/core/lib/png/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/lib/random/BUILD b/tensorflow/core/lib/random/BUILD index 770d00051e3..019797b1dda 100644 --- a/tensorflow/core/lib/random/BUILD +++ b/tensorflow/core/lib/random/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/lib/strings/BUILD b/tensorflow/core/lib/strings/BUILD index 31425aabc10..3308edd04bf 100644 --- a/tensorflow/core/lib/strings/BUILD +++ b/tensorflow/core/lib/strings/BUILD @@ -1,3 +1,8 @@ +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) + package( default_visibility = [ # tensorflow/core:lib effectively exposes all targets under tensorflow/core/lib/** diff --git a/tensorflow/core/platform/BUILD b/tensorflow/core/platform/BUILD index 5dfeeb89c43..dea8cd1353e 100644 --- a/tensorflow/core/platform/BUILD +++ b/tensorflow/core/platform/BUILD @@ -30,6 +30,11 @@ load( "tf_protobuf_deps", "tf_windows_aware_platform_deps", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_binary", + "cc_library", +) load( "//tensorflow:tensorflow.bzl", "if_not_android", @@ -1462,6 +1467,12 @@ bzl_library( name = "build_config_root_bzl", srcs = [ "build_config_root.bzl", - "//tensorflow/core/platform/default:build_config_root.bzl", - ], + ] + tf_platform_alias("build_config_root.bzl"), +) + +bzl_library( + name = "rules_cc_bzl", + srcs = [ + "rules_cc.bzl", + ] + tf_platform_alias("rules_cc.bzl"), ) diff --git a/tensorflow/core/platform/default/BUILD b/tensorflow/core/platform/default/BUILD index 346018153d5..41e3d65574f 100644 --- a/tensorflow/core/platform/default/BUILD +++ b/tensorflow/core/platform/default/BUILD @@ -1,6 +1,10 @@ # Tensorflow default + linux implementations of tensorflow/core/platform libraries. load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("//tensorflow:tensorflow.bzl", "tf_copts") +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = [ diff --git a/tensorflow/core/platform/windows/BUILD b/tensorflow/core/platform/windows/BUILD index f3a995bcff6..7ed2518f216 100644 --- a/tensorflow/core/platform/windows/BUILD +++ b/tensorflow/core/platform/windows/BUILD @@ -4,6 +4,10 @@ load( "if_windows", "tf_copts", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) package( default_visibility = [ diff --git a/tensorflow/core/util/BUILD b/tensorflow/core/util/BUILD index 2e4ea69659e..f60c77ffebb 100644 --- a/tensorflow/core/util/BUILD +++ b/tensorflow/core/util/BUILD @@ -3,6 +3,10 @@ load( "tf_kernel_tests_linkstatic", "tf_proto_library", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_library", +) load( "//tensorflow:tensorflow.bzl", "tf_cc_test", diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files index 5bcde2b9515..62d203138c1 100644 --- a/tensorflow/opensource_only.files +++ b/tensorflow/opensource_only.files @@ -146,6 +146,7 @@ tensorflow/third_party/py/python_configure.bzl tensorflow/third_party/pybind11.BUILD tensorflow/third_party/python_runtime/BUILD tensorflow/third_party/repo.bzl +tensorflow/third_party/rules_swift.patch tensorflow/third_party/six.BUILD tensorflow/third_party/snappy.BUILD tensorflow/third_party/sqlite.BUILD diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index b82e7b9c4eb..4e5f01f1e20 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -11,6 +11,12 @@ load( "tf_gpu_tests_tags", "tf_sycl_tests_tags", ) +load( + "//tensorflow/core/platform:rules_cc.bzl", + "cc_binary", + "cc_library", + "cc_test", +) load( "@local_config_tensorrt//:build_defs.bzl", "if_tensorrt", @@ -111,7 +117,7 @@ def tf_android_core_proto_headers(core_proto_sources_relative): # Wrapper for portable protos which currently just creates an empty rule. def tf_portable_proto_library(name, proto_deps, deps = [], **kwargs): _ignore = [kwargs] - native.cc_library(name = name, deps = deps + [dep + "_cc" for dep in proto_deps]) + cc_library(name = name, deps = deps + [dep + "_cc" for dep in proto_deps]) # Sanitize a dependency so that it works correctly from code that includes # TensorFlow as a submodule. @@ -360,7 +366,7 @@ def tf_gen_op_libs(op_lib_names, deps = None, is_external = True): if not deps: deps = [] for n in op_lib_names: - native.cc_library( + cc_library( name = n + "_op_lib", copts = tf_copts(is_external = is_external), srcs = ["ops/" + n + ".cc"], @@ -564,7 +570,7 @@ def tf_cc_shared_object( if framework_so != []: data_extra = tf_binary_additional_data_deps() - native.cc_binary( + cc_binary( name = name_os_full, srcs = srcs + framework_so, deps = deps, @@ -625,7 +631,7 @@ def tf_cc_binary( else: names = [name] for name_os in names: - native.cc_binary( + cc_binary( name = name_os, copts = copts, srcs = srcs + tf_binary_additional_srcs(), @@ -668,7 +674,7 @@ def tf_native_cc_binary( copts = tf_copts(), linkopts = [], **kwargs): - native.cc_binary( + cc_binary( name = name, copts = copts, linkopts = select({ @@ -808,7 +814,7 @@ def tf_gen_op_wrappers_cc( internalsrcs += ["ops/" + n + "_internal.cc"] internalhdrs += ["ops/" + n + "_internal.h"] - native.cc_library( + cc_library( name = name, srcs = subsrcs, hdrs = subhdrs, @@ -825,7 +831,7 @@ def tf_gen_op_wrappers_cc( alwayslink = 1, visibility = visibility, ) - native.cc_library( + cc_library( name = name + "_internal", srcs = internalsrcs, hdrs = internalhdrs, @@ -989,7 +995,7 @@ def tf_cc_test( linkopts = [], kernels = [], **kwargs): - native.cc_test( + cc_test( name = "%s%s" % (name, suffix), srcs = srcs + tf_binary_additional_srcs(), copts = tf_copts() + extra_copts, @@ -1146,7 +1152,7 @@ def tf_gpu_only_cc_test( deps = deps, testonly = 1, ) - native.cc_test( + cc_test( name = "%s%s" % (name, "_gpu"), size = size, args = args, @@ -1233,7 +1239,7 @@ def tf_cc_test_mkl( disable_header_modules = ["-use_header_modules"] for src in srcs: - native.cc_test( + cc_test( name = src_to_test_name(src), srcs = if_mkl([src]) + tf_binary_additional_srcs(), copts = tf_copts(allow_exceptions = True) + tf_openmp_copts(), @@ -1395,7 +1401,7 @@ def tf_gpu_library(deps = None, cuda_deps = None, copts = tf_copts(), **kwargs): cuda_deps = [] kwargs["features"] = kwargs.get("features", []) + ["-use_header_modules"] - native.cc_library( + cc_library( deps = deps + if_cuda_is_configured_compat(cuda_deps + [ clean_dep("//tensorflow/stream_executor/cuda:cudart_stub"), "@local_config_cuda//cuda:cuda_headers", @@ -1563,7 +1569,7 @@ def tf_mkl_kernel_library( # -fno-exceptions in nocopts breaks compilation if header modules are enabled. disable_header_modules = ["-use_header_modules"] - native.cc_library( + cc_library( name = name, srcs = if_mkl(srcs), hdrs = hdrs, @@ -1716,7 +1722,7 @@ def transitive_hdrs(name, deps = [], **kwargs): # the libraries in deps. def cc_header_only_library(name, deps = [], includes = [], extra_deps = [], **kwargs): _transitive_hdrs(name = name + "_gather", deps = deps) - native.cc_library( + cc_library( name = name, hdrs = [":" + name + "_gather"], includes = includes, @@ -2364,7 +2370,7 @@ def tf_generate_proto_text_sources(name, srcs_relative_dir, srcs, protodeps = [] visibility = visibility, ) - native.cc_library( + cc_library( name = name, srcs = out_srcs, hdrs = out_hdrs, @@ -2420,7 +2426,7 @@ def cc_library_with_android_deps( copts = tf_copts(), **kwargs): deps = if_not_android(deps) + if_android(android_deps) + common_deps - native.cc_library(deps = deps, copts = copts, **kwargs) + cc_library(deps = deps, copts = copts, **kwargs) register_extension_info( extension_name = "cc_library_with_android_deps", @@ -2481,7 +2487,7 @@ def pybind_extension( visibility = ["//visibility:private"], testonly = testonly, ) - native.cc_binary( + cc_binary( name = so_file, srcs = srcs + hdrs, data = data, diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index 403cac97837..4f5a75d7262 100755 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -903,6 +903,7 @@ def tf_repositories(path_prefix = "", tf_repo_name = ""): # https://github.com/bazelbuild/rules_swift/releases tf_http_archive( name = "build_bazel_rules_swift", + patch_file = clean_dep("//third_party:rules_swift.patch"), sha256 = "18cd4df4e410b0439a4935f9ca035bd979993d42372ba79e7f2d4fafe9596ef0", urls = [ "http://mirror.tensorflow.org/github.com/bazelbuild/rules_swift/releases/download/0.12.1/rules_swift.0.12.1.tar.gz", diff --git a/third_party/rules_swift.patch b/third_party/rules_swift.patch new file mode 100644 index 00000000000..5e4e24b40ce --- /dev/null +++ b/third_party/rules_swift.patch @@ -0,0 +1,25 @@ +From 4c1a4d676d1633ff9f67bda3540d24ea5fa31c8f Mon Sep 17 00:00:00 2001 +From: Brian Zhao +Date: Tue, 14 Jan 2020 18:23:34 -0800 +Subject: [PATCH] Adding linker_inputs flag to create_linking_context, in + preparation for bazel's cc_shared_library rule. Note that this cannot be + enabled as of now unless --experimental_cc_shared_library is passed to bazel. + +--- + swift/internal/utils.bzl | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/swift/internal/utils.bzl b/swift/internal/utils.bzl +index 5cf1498..44d7559 100644 +--- a/swift/internal/utils.bzl ++++ b/swift/internal/utils.bzl +@@ -98,6 +98,7 @@ def create_cc_info( + + this_cc_info = CcInfo( + linking_context = cc_common.create_linking_context( ++ linker_inputs = None, + additional_inputs = all_additional_inputs, + libraries_to_link = libraries_to_link, + user_link_flags = all_user_link_flags, +-- +2.25.0.rc1.283.g88dfdc4193-goog