Skip to content

Commit

Permalink
Windows MSVC CROSSTOOL: Don't pass /DEBUG:FASTLINK to linker if it do…
Browse files Browse the repository at this point in the history
…esn't support it

This makes Bazel work nicer with VC++ version prior to VC++ 2015, but it
doesn't mean we fully support them. For example, /WHOLEARCHIVE doesn't
work with versions older that VC++ 2015, either.

Fixed bazelbuild#3109
Fixed bazelbuild#4240

Change-Id: Iab7280bea241a203cb04dc9ca0a7b3bce518fb64
PiperOrigin-RevId: 178615516
  • Loading branch information
meteorcloudy authored and Copybara-Service committed Dec 11, 2017
1 parent ce7df3f commit 09a6a9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/cpp/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ toolchain {
action: 'c++-link-executable'
action: 'c++-link-dynamic-library'
flag_group {
flag: "/DEBUG:FULL"
flag: "%{dbg_mode_debug}"
flag: "/INCREMENTAL:NO"
}
}
Expand All @@ -971,7 +971,7 @@ toolchain {
action: 'c++-link-executable'
action: 'c++-link-dynamic-library'
flag_group {
flag: "/DEBUG:FASTLINK"
flag: "%{fastbuild_mode_debug}"
flag: "/INCREMENTAL:NO"
}
}
Expand Down
2 changes: 2 additions & 0 deletions tools/cpp/unix_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value):
"%{msvc_ml_path}": "",
"%{msvc_link_path}": "",
"%{msvc_lib_path}": "",
"%{dbg_mode_debug}": "",
"%{fastbuild_mode_debug}": "",
"%{compilation_mode_content}": "",
})
12 changes: 12 additions & 0 deletions tools/cpp/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ def _is_support_whole_archive(repository_ctx, vc_path):
return result.find("/WHOLEARCHIVE") != -1


def _is_support_debug_fastlink(repository_ctx, vc_path):
"""Run MSVC linker alone to see if it supports /DEBUG:FASTLINK."""
linker = find_msvc_tool(repository_ctx, vc_path, "link.exe")
result = execute(repository_ctx, [linker], expect_failure = True)
return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1


def _is_use_msvc_wrapper(repository_ctx):
"""Returns True if USE_MSVC_WRAPPER is set to 1."""
env = repository_ctx.os.environ
Expand Down Expand Up @@ -361,6 +368,9 @@ def configure_windows_toolchain(repository_ctx):
for path in escaped_include_paths.split(";"):
if path:
escaped_cxx_include_directories.append("cxx_builtin_include_directory: \"%s\"" % path)

support_debug_fastlink = _is_support_debug_fastlink(repository_ctx, vc_path)

tpl(repository_ctx, "CROSSTOOL", {
"%{cpu}": "x64_windows",
"%{default_toolchain_name}": "msvc_x64",
Expand All @@ -373,6 +383,8 @@ def configure_windows_toolchain(repository_ctx):
"%{msvc_ml_path}": msvc_ml_path,
"%{msvc_link_path}": msvc_link_path,
"%{msvc_lib_path}": msvc_lib_path,
"%{dbg_mode_debug}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
"%{fastbuild_mode_debug}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
"%{compilation_mode_content}": compilation_mode_content,
"%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
"%{opt_content}": "",
Expand Down

0 comments on commit 09a6a9f

Please sign in to comment.