Incrementally swap portions of tensorflow's build to rules_cc's version of cc build rules. This is part of the build refactoring described in https://github.com/tensorflow/community/pull/179

PiperOrigin-RevId: 290466858
Change-Id: I9b38b1b7f44f1defea9be6ffb9e5da0c5ca99fb5
This commit is contained in:
Brian Zhao 2020-01-18 19:50:07 -08:00 committed by TensorFlower Gardener
parent d82cc1a08f
commit 1b58766589
23 changed files with 140 additions and 18 deletions

View File

@ -479,6 +479,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",

View File

@ -128,6 +128,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",

View File

@ -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 = [

View File

@ -1,3 +1,8 @@
load(
"//tensorflow/core/platform:rules_cc.bzl",
"cc_library",
)
package(
default_visibility = [
"//tensorflow:__subpackages__",

View File

@ -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 = [

View File

@ -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"],

View File

@ -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/**

View File

@ -3,6 +3,10 @@ load(
"if_linux_x86_64",
"tf_copts",
)
load(
"//tensorflow/core/platform:rules_cc.bzl",
"cc_library",
)
package(
default_visibility = [

View File

@ -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/**

View File

@ -1,3 +1,8 @@
load(
"//tensorflow/core/platform:rules_cc.bzl",
"cc_library",
)
package(
default_visibility = [
"//tensorflow/c/experimental/filesystem:__pkg__",

View File

@ -1,3 +1,8 @@
load(
"//tensorflow/core/platform:rules_cc.bzl",
"cc_library",
)
package(
default_visibility = [
"//tensorflow:__subpackages__",

View File

@ -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/**

View File

@ -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/**

View File

@ -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/**

View File

@ -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/**

View File

@ -31,6 +31,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_chromiumos",
@ -1415,6 +1420,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"),
)

View File

@ -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 = [

View File

@ -4,6 +4,10 @@ load(
"if_windows",
"tf_copts",
)
load(
"//tensorflow/core/platform:rules_cc.bzl",
"cc_library",
)
package(
default_visibility = [

View File

@ -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",

View File

@ -148,6 +148,7 @@ tensorflow/third_party/pybind11.BUILD
tensorflow/third_party/python_runtime/BUILD
tensorflow/third_party/repo.bzl
tensorflow/third_party/rules_closure.patch
tensorflow/third_party/rules_swift.patch
tensorflow/third_party/six.BUILD
tensorflow/third_party/snappy.BUILD
tensorflow/third_party/sqlite.BUILD

View File

@ -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",
@ -122,7 +128,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])
def if_android_x86(a):
return select({
@ -367,7 +373,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"],
@ -571,7 +577,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,
@ -632,7 +638,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(),
@ -675,7 +681,7 @@ def tf_native_cc_binary(
copts = tf_copts(),
linkopts = [],
**kwargs):
native.cc_binary(
cc_binary(
name = name,
copts = copts,
linkopts = select({
@ -815,7 +821,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,
@ -832,7 +838,7 @@ def tf_gen_op_wrappers_cc(
alwayslink = 1,
visibility = visibility,
)
native.cc_library(
cc_library(
name = name + "_internal",
srcs = internalsrcs,
hdrs = internalhdrs,
@ -996,7 +1002,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,
@ -1153,7 +1159,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,
@ -1240,7 +1246,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(),
@ -1402,7 +1408,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",
@ -1570,7 +1576,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,
@ -1723,7 +1729,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,
@ -2371,7 +2377,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,
@ -2427,7 +2433,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",
@ -2489,7 +2495,7 @@ def pybind_extension(
visibility = ["//visibility:private"],
testonly = testonly,
)
native.cc_binary(
cc_binary(
name = so_file,
srcs = srcs + hdrs,
data = data,

View File

@ -926,6 +926,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 = [
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_swift/releases/download/0.12.1/rules_swift.0.12.1.tar.gz",

25
third_party/rules_swift.patch vendored Normal file
View File

@ -0,0 +1,25 @@
From 4c1a4d676d1633ff9f67bda3540d24ea5fa31c8f Mon Sep 17 00:00:00 2001
From: Brian Zhao <bmzhao@google.com>
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