Add global_whole_archive into MSVC CROSSTOOL
This feature is needed when linking the _pywrap_tensorflow.dll on Windows.
Which will force link all the libraries in deps.
I used /WHOLEARCHVIE to implement this, so it only works with Visual Stduio
2015 update 2 or later.
--
Change-Id: I0b018d3f4f482e56d1ebf78faa08fa46e1d60bbf
Reviewed-on: https://bazel-review.googlesource.com/#/c/6612
MOS_MIGRATED_REVID=135923622
diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl
index 329593f..dd82aff 100644
--- a/tools/cpp/CROSSTOOL.tpl
+++ b/tools/cpp/CROSSTOOL.tpl
@@ -302,6 +302,7 @@
implies: 'linkstamps'
implies: 'output_execpath_flags'
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
action_config {
@@ -314,6 +315,7 @@
implies: 'linkstamps'
implies: 'output_execpath_flags'
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
action_config {
@@ -323,6 +325,7 @@
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
action_config {
@@ -332,6 +335,7 @@
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
# TODO(pcloudy): The following action_config is listed in MANDATORY_LINK_TARGET_TYPES.
@@ -343,6 +347,7 @@
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
action_config {
@@ -352,6 +357,7 @@
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
+ implies: 'global_whole_archive'
}
action_config {
@@ -450,6 +456,23 @@
}
}
+ feature {
+ name: 'global_whole_archive'
+ flag_set {
+ expand_if_all_available: 'global_whole_archive'
+ action: 'c++-link-executable'
+ action: 'c++-link-dynamic-library'
+ action: 'c++-link-static-library'
+ action: 'c++-link-alwayslink-static-library'
+ action: 'c++-link-pic-static-library'
+ action: 'c++-link-alwayslink-pic-static-library'
+ flag_group {
+ # If MSVC linker supports /WHOLEARCHIVE, this field will be enabled
+ %{global_whole_archive}
+ }
+ }
+}
+
compilation_mode_flags {
mode: DBG
compiler_flag: "/DDEBUG=1"
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index aeb0715..eaeb2ec 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -497,9 +497,11 @@
if _is_support_whole_archive(repository_ctx, vs_path):
whole_archive_linker_params = "flag: '/WHOLEARCHIVE:%{whole_archive_linker_params}'"
+ global_whole_archive = "flag: '/WHOLEARCHIVE'"
whole_archive_object_files_params = ""
else:
whole_archive_linker_params = ""
+ global_whole_archive = ""
whole_archive_object_files_params = "flag: '%{whole_archive_object_files_params}'"
_tpl(repository_ctx, "CROSSTOOL", {
@@ -510,6 +512,7 @@
"%{cxx_builtin_include_directory}": "\n".join(cxx_include_directories),
"%{whole_archive_linker_params}": whole_archive_linker_params,
"%{whole_archive_object_files_params}": whole_archive_object_files_params,
+ "%{global_whole_archive}": global_whole_archive,
})
else:
darwin = cpu_value == "darwin"
@@ -537,6 +540,7 @@
"%{cxx_builtin_include_directory}": "",
"%{whole_archive_linker_params}": "",
"%{whole_archive_object_files_params}": "",
+ "%{global_whole_archive}": "",
})