From bbc4e2217fdcd0f4581fda3fa2df9b80e54f478a Mon Sep 17 00:00:00 2001 From: Michael Siegrist Date: Thu, 22 Aug 2024 10:36:42 -0700 Subject: [PATCH 1/2] Fix ml path for Windows clang-cl cc toolchain Assembly files are not valid inputs for `clang-cl.exe`; the MSVC `ml64.exe` must be used instead. Fixes #23128. Closes #23337. PiperOrigin-RevId: 666406544 Change-Id: Ia7a5fc4702f08a5754145ca286c079d1a4f0e204 --- src/test/py/bazel/bazel_windows_cpp_test.py | 75 +++++++++++++++------ tools/cpp/windows_cc_configure.bzl | 3 +- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/test/py/bazel/bazel_windows_cpp_test.py b/src/test/py/bazel/bazel_windows_cpp_test.py index 1d28826e43769f..fc5d52904cd4f1 100644 --- a/src/test/py/bazel/bazel_windows_cpp_test.py +++ b/src/test/py/bazel/bazel_windows_cpp_test.py @@ -775,30 +775,65 @@ def testBuildWithClangClByToolchainResolution(self): ' "@local_config_cc//:cc-toolchain-x64_windows-clang-cl",', ')', ]) - self.ScratchFile('BUILD', [ - 'platform(', - ' name = "windows_clang",', - ' constraint_values = [', - ' "@platforms//cpu:x86_64",', - ' "@platforms//os:windows",', - ' "@bazel_tools//tools/cpp:clang-cl",', - ' ]', - ')', - '', - 'cc_binary(', - ' name = "main",', - ' srcs = ["main.cc"],', - ')', - ]) - self.ScratchFile('main.cc', [ - 'int main() {', - ' return 0;', - '}', - ]) exit_code, _, stderr = self.RunBazel([ 'build', '-s', '--incompatible_enable_cc_toolchain_resolution=true', '//:main' ]) + self.ScratchFile( + 'BUILD', + [ + 'platform(', + ' name = "windows_clang",', + ' constraint_values = [', + ' "@platforms//cpu:x86_64",', + ' "@platforms//os:windows",', + ' "@bazel_tools//tools/cpp:clang-cl",', + ' ]', + ')', + '', + 'cc_binary(', + ' name = "main",', + ' srcs = [ "main.cc",', + ' "inc.asm",', # Test assemble action_config + ' "dec.S",', # Test preprocess-assemble action_config + ' ],', + ')', + ], + ) + self.ScratchFile( + 'main.cc', + [ + 'int main() {', + ' return 0;', + '}', + ], + ) + self.ScratchFile( + 'inc.asm', + [ + '.code', + 'PUBLIC increment', + 'increment PROC x:WORD', + ' xchg rcx,rax', + ' inc rax', + ' ret', + 'increment EndP', + 'END', + ], + ) + self.ScratchFile( + 'dec.S', + [ + '.code', + 'PUBLIC decrement', + 'decrement PROC x:WORD', + ' xchg rcx,rax', + ' dec rax', + ' ret', + 'decrement EndP', + 'END', + ], + ) self.AssertExitCode(exit_code, 0, stderr) self.assertIn('clang-cl.exe', ''.join(stderr)) diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl index 4c3e367b22b4f8..fe41e469bcbe2d 100644 --- a/tools/cpp/windows_cc_configure.bzl +++ b/tools/cpp/windows_cc_configure.bzl @@ -793,7 +793,8 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars, target_arch): "%{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, + # clang-cl does not support assembly files as input. + "%{clang_cl_ml_path_" + target_arch + "}": msvc_vars["%{msvc_ml_path_" + target_arch + "}"], # LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK. "%{clang_cl_dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG", "%{clang_cl_fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG", From 1a55e1cdddc238ab6167fa394465a83608da4473 Mon Sep 17 00:00:00 2001 From: iancha1992 Date: Mon, 26 Aug 2024 11:14:55 -0700 Subject: [PATCH 2/2] Clean up --- src/test/py/bazel/bazel_windows_cpp_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/py/bazel/bazel_windows_cpp_test.py b/src/test/py/bazel/bazel_windows_cpp_test.py index fc5d52904cd4f1..1c4edbd8c3c4e3 100644 --- a/src/test/py/bazel/bazel_windows_cpp_test.py +++ b/src/test/py/bazel/bazel_windows_cpp_test.py @@ -775,10 +775,6 @@ def testBuildWithClangClByToolchainResolution(self): ' "@local_config_cc//:cc-toolchain-x64_windows-clang-cl",', ')', ]) - exit_code, _, stderr = self.RunBazel([ - 'build', '-s', '--incompatible_enable_cc_toolchain_resolution=true', - '//:main' - ]) self.ScratchFile( 'BUILD', [ @@ -834,6 +830,10 @@ def testBuildWithClangClByToolchainResolution(self): 'END', ], ) + exit_code, _, stderr = self.RunBazel([ + 'build', '-s', '--incompatible_enable_cc_toolchain_resolution=true', + '//:main' + ]) self.AssertExitCode(exit_code, 0, stderr) self.assertIn('clang-cl.exe', ''.join(stderr))