From 52167ad65887b4d5f433b719d9c3654e02daafd5 Mon Sep 17 00:00:00 2001
From: "A. Unique TensorFlower" <gardener@tensorflow.org>
Date: Fri, 25 Oct 2019 15:26:19 -0700
Subject: [PATCH] Update TF for Bazel 1.0's
 --incompatible_remove_legacy_whole_archive
 https://github.com/bazelbuild/bazel/issues/7362

This PR updates `cc_library`s to use `alwayslink=1` when needed. Currently, library archives and library object groups are wrapped in `--whole_archive`, `--no_whole_archive`, thus the whole library is always linked. This changes with Bazel 1.0, and libraries that export otherwise unused symbols must be tagged as `alwayslink=1`.

This PR fixes https://github.com/tensorflow/tensorflow/issues/32835 (once again, as it was fixed by https://github.com/tensorflow/tensorflow/pull/33415 but the codebase regressed in the meantime.)
It also fixes most of the TF tests.

PiperOrigin-RevId: 276772147
Change-Id: I05db02e84200a484df52f4f02b601dc486636912
---
 tensorflow/core/lib/core/BUILD                      | 1 +
 tensorflow/core/platform/BUILD                      | 1 +
 tensorflow/core/platform/default/build_refactor.bzl | 2 ++
 tensorflow/lite/python/testdata/BUILD               | 1 +
 tensorflow/python/BUILD                             | 1 +
 tensorflow/tools/graph_transforms/BUILD             | 1 +
 third_party/icu/data/BUILD.bazel                    | 1 +
 7 files changed, 8 insertions(+)

diff --git a/tensorflow/core/lib/core/BUILD b/tensorflow/core/lib/core/BUILD
index 5a99f1ab764..f9bd2441547 100644
--- a/tensorflow/core/lib/core/BUILD
+++ b/tensorflow/core/lib/core/BUILD
@@ -30,6 +30,7 @@ cc_library(
         "//tensorflow/core/platform:logging",
         "//tensorflow/core/platform:types",
     ],
+    alwayslink = 1,
 )
 
 cc_library(
diff --git a/tensorflow/core/platform/BUILD b/tensorflow/core/platform/BUILD
index c9fca55015d..aabad23aa60 100644
--- a/tensorflow/core/platform/BUILD
+++ b/tensorflow/core/platform/BUILD
@@ -268,6 +268,7 @@ cc_library(
         "@com_google_absl//absl/base",
         "@com_google_absl//absl/synchronization",
     ],
+    alwayslink = 1,
 )
 
 cc_library(
diff --git a/tensorflow/core/platform/default/build_refactor.bzl b/tensorflow/core/platform/default/build_refactor.bzl
index 50514472ce7..d82e8813485 100644
--- a/tensorflow/core/platform/default/build_refactor.bzl
+++ b/tensorflow/core/platform/default/build_refactor.bzl
@@ -210,6 +210,7 @@ TF_DEFAULT_PLATFORM_LIBRARIES = {
         ],
         "visibility": ["//visibility:private"],
         "tags": ["no_oss", "manual"],
+        "alwayslink": 1,
     },
     "notification": {
         "name": "notification_impl",
@@ -298,6 +299,7 @@ TF_DEFAULT_PLATFORM_LIBRARIES = {
         ],
         "tags": ["no_oss", "manual"],
         "visibility": ["//visibility:private"],
+        "alwayslink": 1,
     },
     "test": {
         "name": "test_impl",
diff --git a/tensorflow/lite/python/testdata/BUILD b/tensorflow/lite/python/testdata/BUILD
index 0c12e19451c..1b501507aa5 100644
--- a/tensorflow/lite/python/testdata/BUILD
+++ b/tensorflow/lite/python/testdata/BUILD
@@ -61,6 +61,7 @@ cc_library(
     deps = [
         "//tensorflow/lite/c:c_api_internal",
     ],
+    alwayslink = 1,
 )
 
 cc_binary(
diff --git a/tensorflow/python/BUILD b/tensorflow/python/BUILD
index e928b002d93..2fc6d5de5d4 100644
--- a/tensorflow/python/BUILD
+++ b/tensorflow/python/BUILD
@@ -439,6 +439,7 @@ cc_library(
         "//tensorflow/core:lib",
         "//tensorflow/core:protos_all_cc",
     ],
+    alwayslink = 1,
 )
 
 tf_python_pybind_extension(
diff --git a/tensorflow/tools/graph_transforms/BUILD b/tensorflow/tools/graph_transforms/BUILD
index 870edf5581a..06390ce9945 100644
--- a/tensorflow/tools/graph_transforms/BUILD
+++ b/tensorflow/tools/graph_transforms/BUILD
@@ -234,6 +234,7 @@ cc_library(
         "//tensorflow/core:lib_internal",
         "//tensorflow/core:protos_all_cc",
     ],
+    alwayslink = 1,
 )
 
 # This library includes a main function, to make it easy to create other
diff --git a/third_party/icu/data/BUILD.bazel b/third_party/icu/data/BUILD.bazel
index 6ff47a8d5fc..80ea92ce9b4 100644
--- a/third_party/icu/data/BUILD.bazel
+++ b/third_party/icu/data/BUILD.bazel
@@ -40,4 +40,5 @@ cc_library(
     name = "conversion_data",
     srcs = [":conversion_data.c"],
     deps = ["@icu//:headers"],
+    alwayslink = 1,
 )