Skip to content

Commit

Permalink
Fix clang_cl overriding bug and minor clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
niyas-sait committed Feb 2, 2022
1 parent 3a17839 commit 6c8fa1b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 59 deletions.
2 changes: 2 additions & 0 deletions src/conditions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ config_setting(
],
)

# TODO(https://github.com/bazelbuild/bazel/issues/7260)
# Remove the flag after toolchain cc resolution is fixed
config_setting(
name = "windows_x64_arm64_flag",
values = {"cpu": "x64_arm64_windows"},
Expand Down
2 changes: 1 addition & 1 deletion src/test/py/bazel/bazel_windows_cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def testBuildArm64CppBinaryWithMsvcCLAndCpuArm64Windows(self):
exit_code, _, stderr = self.RunBazel(
['build', '-s', '--cpu=arm64_windows', '//:main'])
self.AssertExitCode(exit_code, 0, stderr)
self.assertIn('arm64/cl.exe', ''.join(stderr))
self.assertIn('arm64\\cl.exe', ''.join(stderr))


if __name__ == '__main__':
Expand Down
64 changes: 32 additions & 32 deletions tools/cpp/BUILD.windows.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -450,31 +450,31 @@ cc_toolchain_config(
abi_version = "local",
abi_libc_version = "local",
toolchain_identifier = "clang_cl_x64",
msvc_env_tmp = "%{clang_cl_env_tmp}",
msvc_env_path = "%{clang_cl_env_path}",
msvc_env_include = "%{clang_cl_env_include}",
msvc_env_lib = "%{clang_cl_env_lib}",
msvc_cl_path = "%{clang_cl_cl_path}",
msvc_ml_path = "%{clang_cl_ml_path}",
msvc_link_path = "%{clang_cl_link_path}",
msvc_lib_path = "%{clang_cl_lib_path}",
cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories}],
msvc_env_tmp = "%{clang_cl_env_tmp_x64}",
msvc_env_path = "%{clang_cl_env_path_x64}",
msvc_env_include = "%{clang_cl_env_include_x64}",
msvc_env_lib = "%{clang_cl_env_lib_x64}",
msvc_cl_path = "%{clang_cl_cl_path_x64}",
msvc_ml_path = "%{clang_cl_ml_path_x64}",
msvc_link_path = "%{clang_cl_link_path_x64}",
msvc_lib_path = "%{clang_cl_lib_path_x64}",
cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories_x64}],
tool_paths = {
"ar": "%{clang_cl_lib_path}",
"ml": "%{clang_cl_ml_path}",
"cpp": "%{clang_cl_cl_path}",
"gcc": "%{clang_cl_cl_path}",
"ar": "%{clang_cl_lib_path_x64}",
"ml": "%{clang_cl_ml_path_x64}",
"cpp": "%{clang_cl_cl_path_x64}",
"gcc": "%{clang_cl_cl_path_x64}",
"gcov": "wrapper/bin/msvc_nop.bat",
"ld": "%{clang_cl_link_path}",
"ld": "%{clang_cl_link_path_x64}",
"nm": "wrapper/bin/msvc_nop.bat",
"objcopy": "wrapper/bin/msvc_nop.bat",
"objdump": "wrapper/bin/msvc_nop.bat",
"strip": "wrapper/bin/msvc_nop.bat",
},
archiver_flags = ["/MACHINE:X64"],
default_link_flags = ["/MACHINE:X64", "/DEFAULTLIB:clang_rt.builtins-x86_64.lib"],
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag}",
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_x64}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_x64}",
)

toolchain(
Expand Down Expand Up @@ -517,31 +517,31 @@ cc_toolchain_config(
abi_version = "local",
abi_libc_version = "local",
toolchain_identifier = "clang_cl_arm64",
msvc_env_tmp = "%{clang_cl_env_tmp}",
msvc_env_path = "%{clang_cl_env_path}",
msvc_env_include = "%{clang_cl_env_include}",
msvc_env_lib = "%{clang_cl_env_lib}",
msvc_cl_path = "%{clang_cl_cl_path}",
msvc_ml_path = "%{clang_cl_ml_path}",
msvc_link_path = "%{clang_cl_link_path}",
msvc_lib_path = "%{clang_cl_lib_path}",
cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories}],
msvc_env_tmp = "%{clang_cl_env_tmp_arm64}",
msvc_env_path = "%{clang_cl_env_path_arm64}",
msvc_env_include = "%{clang_cl_env_include_arm64}",
msvc_env_lib = "%{clang_cl_env_lib_arm64}",
msvc_cl_path = "%{clang_cl_cl_path_arm64}",
msvc_ml_path = "%{clang_cl_ml_path_arm64}",
msvc_link_path = "%{clang_cl_link_path_arm64}",
msvc_lib_path = "%{clang_cl_lib_path_arm64}",
cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories_arm64}],
tool_paths = {
"ar": "%{clang_cl_lib_path}",
"ml": "%{clang_cl_ml_path}",
"cpp": "%{clang_cl_cl_path}",
"gcc": "%{clang_cl_cl_path}",
"ar": "%{clang_cl_lib_path_arm64}",
"ml": "%{clang_cl_ml_path_arm64}",
"cpp": "%{clang_cl_cl_path_arm64}",
"gcc": "%{clang_cl_cl_path_arm64}",
"gcov": "wrapper/bin/msvc_nop.bat",
"ld": "%{clang_cl_link_path}",
"ld": "%{clang_cl_link_path_arm64}",
"nm": "wrapper/bin/msvc_nop.bat",
"objcopy": "wrapper/bin/msvc_nop.bat",
"objdump": "wrapper/bin/msvc_nop.bat",
"strip": "wrapper/bin/msvc_nop.bat",
},
archiver_flags = ["/MACHINE:ARM64"],
default_link_flags = ["/MACHINE:ARM64"],
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag}",
dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_arm64}",
fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_arm64}",
)

toolchain(
Expand Down
52 changes: 26 additions & 26 deletions tools/cpp/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def _get_vc_env_vars(repository_ctx, vc_path, msvc_vars_x64, target_arch):
lib = msvc_vars_x64["%{msvc_env_lib_x64}"]
full_version = _get_vc_full_version(repository_ctx, vc_path)
tools_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\%s" % (vc_path, full_version, target_arch)
# For native windows on arm64 builds host toolchain runs in an emulated x86 environment
# For native windows(10) on arm64 builds host toolchain runs in an emulated x86 environment
if not repository_ctx.path(tools_path).exists:
tools_path = tools_path.replace("HostX64", "HostX86")
tools_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX86\\%s" % (vc_path, full_version, target_arch)
else:
lib = msvc_vars_x64["%{msvc_env_lib_x64}"].replace("amd64", _targets_lib_folder[target_arch])
tools_path = vc_path + "\\bin\\" + _targets_archs[target_arch]
Expand Down Expand Up @@ -451,9 +451,9 @@ def find_msvc_tool(repository_ctx, vc_path, tool, target_arch = "x64"):
full_version = _get_vc_full_version(repository_ctx, vc_path)
if full_version:
tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\%s\\%s" % (vc_path, full_version, target_arch, tool)
# For native windows on arm64 builds host toolchain runs in an emulated x86 environment
# For native windows(10) on arm64 builds host toolchain runs in an emulated x86 environment
if not repository_ctx.path(tool_path).exists:
tool_path = tool_path.replace("HostX64", "HostX86")
tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX86\\%s\\%s" % (vc_path, full_version, target_arch, tool)
else:
# For VS 2015 and older version, the tools are under:
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64
Expand Down Expand Up @@ -724,17 +724,17 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars, target_arch):
if error_script:
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [], file_suffix = "_clangcl")
clang_cl_vars = {
"%{clang_cl_env_tmp}": "clang_cl_not_found",
"%{clang_cl_env_path}": "clang_cl_not_found",
"%{clang_cl_env_include}": "clang_cl_not_found",
"%{clang_cl_env_lib}": "clang_cl_not_found",
"%{clang_cl_cl_path}": error_script,
"%{clang_cl_link_path}": error_script,
"%{clang_cl_lib_path}": error_script,
"%{clang_cl_ml_path}": error_script,
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
"%{clang_cl_cxx_builtin_include_directories}": "",
"%{clang_cl_env_tmp_" + target_arch+ "}": "clang_cl_not_found",
"%{clang_cl_env_path_" + target_arch+ "}": "clang_cl_not_found",
"%{clang_cl_env_include_" + target_arch+ "}": "clang_cl_not_found",
"%{clang_cl_env_lib_" + target_arch+ "}": "clang_cl_not_found",
"%{clang_cl_cl_path_" + target_arch+ "}": error_script,
"%{clang_cl_link_path_" + target_arch+ "}": error_script,
"%{clang_cl_lib_path_" + target_arch+ "}": error_script,
"%{clang_cl_ml_path_" + target_arch+ "}": error_script,
"%{clang_cl_dbg_mode_debug_flag_" + target_arch+ "}": "/DEBUG",
"%{clang_cl_fastbuild_mode_debug_flag_" + target_arch+ "}": "/DEBUG",
"%{clang_cl_cxx_builtin_include_directories_" + target_arch+ "}": "",
}
return clang_cl_vars

Expand All @@ -750,18 +750,18 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars, target_arch):
clang_cl_include_directories = msvc_vars["%{msvc_cxx_builtin_include_directories_"+target_arch+"}"] + (",\n \"%s\"" % clang_include_path)
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [clang_cl_include_directories], file_suffix = "_clangcl")
clang_cl_vars = {
"%{clang_cl_env_tmp}": msvc_vars["%{msvc_env_tmp_"+target_arch+"}"],
"%{clang_cl_env_path}": msvc_vars["%{msvc_env_path_"+target_arch+"}"],
"%{clang_cl_env_include}": msvc_vars["%{msvc_env_include_"+target_arch+"}"] + ";" + clang_include_path,
"%{clang_cl_env_lib}": msvc_vars["%{msvc_env_lib_"+target_arch+"}"] + ";" + clang_lib_path,
"%{clang_cl_cxx_builtin_include_directories}": clang_cl_include_directories,
"%{clang_cl_cl_path}": clang_cl_path,
"%{clang_cl_link_path}": lld_link_path,
"%{clang_cl_lib_path}": llvm_lib_path,
"%{clang_cl_ml_path}": clang_cl_path,
"%{clang_cl_env_tmp_" + target_arch+ "}": msvc_vars["%{msvc_env_tmp_"+target_arch+"}"],
"%{clang_cl_env_path_" + target_arch+ "}": msvc_vars["%{msvc_env_path_"+target_arch+"}"],
"%{clang_cl_env_include_" + target_arch+ "}": msvc_vars["%{msvc_env_include_"+target_arch+"}"] + ";" + clang_include_path,
"%{clang_cl_env_lib_" + target_arch+ "}": msvc_vars["%{msvc_env_lib_"+target_arch+"}"] + ";" + clang_lib_path,
"%{clang_cl_cxx_builtin_include_directories_" + target_arch+ "}": clang_cl_include_directories,
"%{clang_cl_cl_path_" + target_arch+ "}": clang_cl_path,
"%{clang_cl_link_path_" + target_arch+ "}": lld_link_path,
"%{clang_cl_lib_path_" + target_arch+ "}": llvm_lib_path,
"%{clang_cl_ml_path_" + target_arch+ "}": clang_cl_path,
# LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK.
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
"%{clang_cl_dbg_mode_debug_flag_" + target_arch+ "}": "/DEBUG",
"%{clang_cl_fastbuild_mode_debug_flag_" + target_arch+ "}": "/DEBUG",
}
return clang_cl_vars

Expand Down

0 comments on commit 6c8fa1b

Please sign in to comment.