aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-06-26 09:03:45 +0200
committerGravatar Marcel Hlopko <hlopko@google.com>2017-06-26 18:35:52 +0200
commit22187a32b6b147758ac7a6d5158b4b12dee2eea0 (patch)
tree9b1d6b70463e24c6468dacf911cc2877dd6cf9ec
parent27486a67370ec1dac01739a51f313227042e4491 (diff)
Fix include check on Windows
Don't add $TMP as cxx_builtin_include_directory, instead use $TMP/nvcc_inter_files_tmp_dir as tmp direcotry for nvcc.exe Fixed https://github.com/bazelbuild/bazel/issues/3202 RELNOTES: None. PiperOrigin-RevId: 160109290
-rw-r--r--tools/cpp/windows_cc_configure.bzl7
-rw-r--r--tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl10
2 files changed, 15 insertions, 2 deletions
diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl
index aa36ce189e..f0c03d9bcc 100644
--- a/tools/cpp/windows_cc_configure.bzl
+++ b/tools/cpp/windows_cc_configure.bzl
@@ -331,6 +331,7 @@ def configure_windows_toolchain(repository_ctx):
support_whole_archive = "False"
escaped_tmp_dir = escape_string(
get_env_var(repository_ctx, "TMP", "C:\\Windows\\Temp").replace("\\", "\\\\"))
+ nvcc_tmp_dir_name = escaped_tmp_dir + "\\\\nvcc_inter_files_tmp_dir"
# Make sure nvcc.exe is in PATH
escaped_paths = escape_string(env["PATH"])
cuda_path = _find_cuda(repository_ctx)
@@ -342,6 +343,7 @@ def configure_windows_toolchain(repository_ctx):
"%{support_whole_archive}": support_whole_archive,
"%{cuda_compute_capabilities}": ", ".join(
["\"%s\"" % c for c in escaped_compute_capabilities]),
+ "%{nvcc_tmp_dir_name}": nvcc_tmp_dir_name,
})
if _is_no_msvc_wrapper(repository_ctx):
@@ -352,8 +354,9 @@ def configure_windows_toolchain(repository_ctx):
msvc_lib_path = "wrapper/bin/msvc_link.bat"
compilation_mode_content = _get_compilation_mode_content()
- # nvcc will generate some source files under tmp_dir
- escaped_cxx_include_directories = [ "cxx_builtin_include_directory: \"%s\"" % escaped_tmp_dir ]
+ # nvcc will generate some source files under %{nvcc_tmp_dir_name}
+ # The generated files are guranteed to have unique name, so they can share the same tmp directory
+ escaped_cxx_include_directories = [ "cxx_builtin_include_directory: \"%s\"" % nvcc_tmp_dir_name ]
for path in escaped_include_paths.split(";"):
if path:
escaped_cxx_include_directories.append("cxx_builtin_include_directory: \"%s\"" % path)
diff --git a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
index b8f86abc3b..01b4bb6738 100644
--- a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
+++ b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
@@ -29,6 +29,7 @@ MAX_PATH_ADJUSTED = MAX_PATH - MAX_OPTION_LENGTH - MAX_DRIVE_LENGTH
ASSEMBLY_AS_C_SOURCE = '/Tc'
LIB_SUFFIX = '.lib'
LIB_TOOL = "%{lib_tool}"
+NVCC_TEMP_DIR = "%{nvcc_tmp_dir_name}"
supported_cuda_compute_capabilities = [ %{cuda_compute_capabilities} ]
class Error(Exception):
@@ -186,6 +187,15 @@ class ArgParser(object):
nvccopts += m_options
nvccopts += ['--compiler-options="' + " ".join(host_compiler_options) + '"']
nvccopts += ['-x', 'cu'] + opt + includes + out + ['-c'] + src_files
+ # If we don't specify --keep-dir, nvcc will generate intermediate files under TEMP
+ # Put them under NVCC_TEMP_DIR instead, then Bazel can ignore files under NVCC_TEMP_DIR during dependency check
+ # http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#options-for-guiding-compiler-driver
+ # Different actions are sharing NVCC_TEMP_DIR, so we cannot remove it if the directory already exists.
+ if os.path.isfile(NVCC_TEMP_DIR):
+ os.remove(NVCC_TEMP_DIR)
+ if not os.path.exists(NVCC_TEMP_DIR):
+ os.makedirs(NVCC_TEMP_DIR)
+ nvccopts += ['--keep', '--keep-dir', NVCC_TEMP_DIR]
if self.cuda_log:
Log("Running: " + " ".join(["nvcc"] + nvccopts))