Skip to content

Commit

Permalink
Add global_whole_archive into MSVC CROSSTOOL
Browse files Browse the repository at this point in the history
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
  • Loading branch information
meteorcloudy committed Oct 12, 2016
1 parent 368d7b7 commit ee311f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tools/cpp/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ toolchain {
implies: 'linkstamps'
implies: 'output_execpath_flags'
implies: 'input_param_flags'
implies: 'global_whole_archive'
}

action_config {
Expand All @@ -314,6 +315,7 @@ toolchain {
implies: 'linkstamps'
implies: 'output_execpath_flags'
implies: 'input_param_flags'
implies: 'global_whole_archive'
}

action_config {
Expand All @@ -323,6 +325,7 @@ toolchain {
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
implies: 'global_whole_archive'
}

action_config {
Expand All @@ -332,6 +335,7 @@ toolchain {
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.
Expand All @@ -343,6 +347,7 @@ toolchain {
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
implies: 'global_whole_archive'
}

action_config {
Expand All @@ -352,6 +357,7 @@ toolchain {
tool_path: 'DUMMY_TOOL'
}
implies: 'input_param_flags'
implies: 'global_whole_archive'
}

action_config {
Expand Down Expand Up @@ -450,6 +456,23 @@ toolchain {
}
}

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"
Expand Down
4 changes: 4 additions & 0 deletions tools/cpp/cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,11 @@ def _impl(repository_ctx):

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", {
Expand All @@ -510,6 +512,7 @@ def _impl(repository_ctx):
"%{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"
Expand Down Expand Up @@ -537,6 +540,7 @@ def _impl(repository_ctx):
"%{cxx_builtin_include_directory}": "",
"%{whole_archive_linker_params}": "",
"%{whole_archive_object_files_params}": "",
"%{global_whole_archive}": "",
})


Expand Down

0 comments on commit ee311f4

Please sign in to comment.