diff options
author | 2016-10-06 10:55:54 +0000 | |
---|---|---|
committer | 2016-10-06 10:58:43 +0000 | |
commit | ffdc05d2278d7f9c6e299c923019f689cde5fe76 (patch) | |
tree | 3f927eca381f68465fc0b142c9c499b18d503f62 /tools | |
parent | 27085f44a168b502542cda6216863601e64da833 (diff) |
Add action_config and feature for linking on Windows
Also implemented whole archive feature on Windows
1. Pulled action_configs and features from CppLinkActionConfigs.java
2. Deleted many features not working on Windows. (AFAIK)
including:
symbol_counts
output_execpath_flags_executable
global_whole_archive_open
runtime_root_flags
global_whole_archive_close
force_pic_flags
3. Added c++-link-interface-dynamic-library action config
Not sure there is such thing on Windows, but it's currently in MANDATORY_LINK_TARGET_TYPES
4. Added build variable "whole_archive_object_files_params"
5. Automatically detect if linker supports /WHOLEARCHIVE and use the corresponding build variable
--
Change-Id: I232798a0eb1a3291f972b313a81e678b0121d58c
Reviewed-on: https://bazel-review.googlesource.com/#/c/6414
MOS_MIGRATED_REVID=135342093
Diffstat (limited to 'tools')
-rw-r--r-- | tools/cpp/CROSSTOOL.tpl | 157 | ||||
-rw-r--r-- | tools/cpp/cc_configure.bzl | 22 |
2 files changed, 177 insertions, 2 deletions
diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl index 740b68cbee..f33e9afbe1 100644 --- a/tools/cpp/CROSSTOOL.tpl +++ b/tools/cpp/CROSSTOOL.tpl @@ -288,6 +288,163 @@ toolchain { } } + action_config { + config_name: 'c++-link-executable' + action_name: 'c++-link-executable' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'linkstamps' + implies: 'output_execpath_flags' + implies: 'input_param_flags' + } + + action_config { + config_name: 'c++-link-dynamic-library' + action_name: 'c++-link-dynamic-library' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'shared_flag' + implies: 'linkstamps' + implies: 'output_execpath_flags' + implies: 'input_param_flags' + } + + action_config { + config_name: 'c++-link-static-library' + action_name: 'c++-link-static-library' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'input_param_flags' + } + + action_config { + config_name: 'c++-link-alwayslink-static-library' + action_name: 'c++-link-alwayslink-static-library' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'input_param_flags' + } + + # TODO(pcloudy): The following action_config is listed in MANDATORY_LINK_TARGET_TYPES. + # But do we really need them on Windows? + action_config { + config_name: 'c++-link-pic-static-library' + action_name: 'c++-link-pic-static-library' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'input_param_flags' + } + + action_config { + config_name: 'c++-link-alwayslink-pic-static-library' + action_name: 'c++-link-alwayslink-pic-static-library' + tool { + tool_path: 'DUMMY_TOOL' + } + implies: 'input_param_flags' + } + + action_config { + config_name: 'c++-link-interface-dynamic-library' + action_name: 'c++-link-interface-dynamic-library' + tool { + tool_path: 'DUMMY_TOOL' + } + } + + feature { + name: 'shared_flag' + flag_set { + action: 'c++-link-dynamic-library' + flag_group { + flag: '/DLL' + } + } + } + + feature { + name: 'linkstamps' + flag_set { + action: 'c++-link-executable' + action: 'c++-link-dynamic-library' + expand_if_all_available: 'linkstamp_paths' + flag_group { + flag: '%{linkstamp_paths}' + } + } + } + + feature { + name: 'output_execpath_flags' + flag_set { + expand_if_all_available: 'output_execpath' + action: 'c++-link-executable' + action: 'c++-link-dynamic-library' + flag_group { + flag: '/OUT:%{output_execpath}' + } + } + } + + feature { + name: 'input_param_flags' + flag_set { + expand_if_all_available: 'libopts' + 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 { + flag: '%{libopts}' + } + } + flag_set { + expand_if_all_available: 'whole_archive_linker_params' + 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 + %{whole_archive_linker_params} + } + } + flag_set { + expand_if_all_available: 'whole_archive_object_files_params' + 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 doesn't support /WHOLEARCHIVE, this field will be enabled + %{whole_archive_object_files_params} + } + } + flag_set { + expand_if_all_available: 'linker_input_params' + 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 { + flag: '%{linker_input_params}' + } + } + } + compilation_mode_flags { mode: DBG compiler_flag: "/DDEBUG=1" diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl index 69daae5822..aeb0715536 100644 --- a/tools/cpp/cc_configure.bzl +++ b/tools/cpp/cc_configure.bzl @@ -428,6 +428,12 @@ def _find_env_vars(repository_ctx, vs_path): return env_map +def _is_support_whole_archive(repository_ctx, vs_dir): + """Run MSVC linker alone to see if it supports /WHOLEARCHIVE.""" + result = _execute(repository_ctx, [vs_dir + "/VC/BIN/amd64/link"]) + return result.find("/WHOLEARCHIVE") != -1 + + def _tpl(repository_ctx, tpl, substitutions={}, out=None): if not out: out = tpl @@ -488,12 +494,22 @@ def _impl(repository_ctx): for path in include_paths.split(";"): if path: cxx_include_directories.append(("cxx_builtin_include_directory: \"%s\"" % path)) + + if _is_support_whole_archive(repository_ctx, vs_path): + whole_archive_linker_params = "flag: '/WHOLEARCHIVE:%{whole_archive_linker_params}'" + whole_archive_object_files_params = "" + else: + whole_archive_linker_params = "" + whole_archive_object_files_params = "flag: '%{whole_archive_object_files_params}'" + _tpl(repository_ctx, "CROSSTOOL", { "%{cpu}": cpu_value, "%{content}": _get_windows_crosstool_content(repository_ctx), "%{opt_content}": "", "%{dbg_content}": "", - "%{cxx_builtin_include_directory}": "\n".join(cxx_include_directories) + "%{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, }) else: darwin = cpu_value == "darwin" @@ -518,7 +534,9 @@ def _impl(repository_ctx): _build_tool_path(tool_paths), "%{opt_content}": _build_crosstool(opt_content, " "), "%{dbg_content}": _build_crosstool(dbg_content, " "), - "%{cxx_builtin_include_directory}": "" + "%{cxx_builtin_include_directory}": "", + "%{whole_archive_linker_params}": "", + "%{whole_archive_object_files_params}": "", }) |