Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling assembly with gcc-style args broken using clang-cl on Windows #24152

Open
fhanau opened this issue Oct 31, 2024 · 13 comments
Open

Compiling assembly with gcc-style args broken using clang-cl on Windows #24152

fhanau opened this issue Oct 31, 2024 · 13 comments
Labels

Comments

@fhanau
Copy link

fhanau commented Oct 31, 2024

Description of the bug:

As of Bazel 7.3.1, the standard clang-cl Windows toolchain supports compiling assembly code using clang-cl.exe (as it does with C and C++ code). As of 7.4.0, the clang-cl toolchain uses MASM instead of clang-cl itself to compile assembly code. This breaks our build configuration as we use gcc-style compiler flags (e.g. -Wno-macro-redefined) which are not supported by MASM.
The most straightforward way to fix this would be to revert #23406 so that clang-cl.exe is used again for assembly, contrary to what is stated there it is capable of compiling assembly code. This resolves the inconsistency of using MSVC tools for assembly and clang-cl for everything else in the clang-cl toolchain; having the tools be consistent is crucial for being able to compile the same files with the same compiler flags on both Unix and Windows using clang/clang-cl. Of course, this would break developers who depend on using MASM for some assembly files (as reported in the original issue motivating the change, #23128). Ideally, there would be some way to configure what assembler is being used without having to define a custom toolchain; and a means to not have C/C++ compiler flags apply to compiling assembly (we need -Wno-macro-redefined to avoid excessive warnings for C++ code on Windows, but don't actually need it when compiling assembly).

Which category does this issue belong to?

C++ Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

We assume that Windows and the clang-cl toolchain are being used. Create an empty dummy.S file alongside a basic assembly target:

cc_library(
    name = "dummy",
    srcs = ["dummy.S"],
)

Then compile the target with a gcc-style compiler flag, e.g. bazel build --copt=-Wno-macro-redefined //:dummy. This works with Bazel 7.3.1, but fails with Bazel 7.4.0 with the following error. //:x64_windows-clang-cl refers to a simple platform definition for clang-cl setting the @bazel_tools//tools/cpp:clang-cl constraint. The output reflects this being executed in a CI environment for our project.

ERROR: D:/a/<path>/tests/BUILD.bazel:28:11: Compiling <path>/tests/dummy.S failed: (Exit 1): ml64.exe failed: error executing CppCompile command (from target //<path>/tests:dummy) 
MASM : warning A4018:invalid command-line option : /bigobj
  cd /d C:/tmp/hs7imhxj/execroot/<path>
  SET INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\include;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files\LLVM\lib\clang\18\include
    SET PATH=C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\;C:\Program Files (x86)\HTML Help Workshop;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Team Tools\DiagnosticsHub\Collector;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\CodeCoverage.Console;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\;;C:\Windows\system32;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\x64\bin;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\vcpkg
    SET ***
    SET TEMP=C:\Users\RUNNER~1\AppData\Local\Temp
    SET TMP=C:\Users\RUNNER~1\AppData\Local\Temp
    SET VSLANG=1033
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64\ml64.exe @bazel-out/x64_windows-fastbuild/bin/<path>/tests/_objs/dummy/dummy.obj.params
# Configuration: ed49adc2ea3b3e3521585f328ebde607[70]<redacted>
# Execution platform: //:x64_windows-clang-cl
Microsoft (R) Macro Assembler (x64) Version 14.41.34123.0
Copyright (C) Microsoft Corporation.  All rights reserved.

MASM : warning A4018:invalid command-line option : /Zm500
MASM : warning A4018:invalid command-line option : /Z500
MASM : warning A4018:invalid command-line option : /Z00
MASM : warning A4018:invalid command-line option : /Z0
MASM : warning A4018:invalid command-line option : /EHsc
MASM : warning A4018:invalid command-line option : /wd4351
MASM : warning A4018:invalid command-line option : /wd4291
MASM : warning A4018:invalid command-line option : /wd4250
MASM : warning A4018:invalid command-line option : /wd4996
MASM : warning A4018:invalid command-line option : /showIncludes
MASM : fatal error A1013:invalid numerical command-line argument : /W

The params file dummy.obj.params suggests that this failed with the first argument with a leading dash, which leads to the A1013 error.

/nologo
/DCOMPILER_MSVC
/DNOMINMAX
/D_WIN32_WINNT=0x0601
/D_CRT_SECURE_NO_DEPRECATE
/D_CRT_SECURE_NO_WARNINGS
/bigobj
/Zm500
/EHsc
/wd4351
/wd4291
/wd4250
/wd4996
/I.
/Ibazel-out/x64_windows-fastbuild/bin
/showIncludes
-Wno-macro-redefined
/Fobazel-out/x64_windows-fastbuild/bin/<path>/tests/_objs/dummy/dummy.obj
/c
<path>/tests/dummy.S

Since the action failed due to MASM not accepting gcc-style arguments like -Wno-macro-redefined, the switch to MASM in 7.4.0 is likely responsible here.

Which operating system are you running Bazel on?

Windows Server 2022

What is the output of bazel info release?

release 7.4.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

N/A

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

I did not bisect since I only observed this on Windows CI, but believe that this is being caused by #23406 where the clang-cl toolchain starts using MASM to compile assembly instead of clang-cl which is used for other compile actions.
The PR asserts that "clang-cl is not intended to handle assembly", but we have been compiling assembly code on Windows with Bazel 7.3.1 and thus clang-cl without any issues; using MASM instead breaks compilation.

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@meteorcloudy
Copy link
Member

@michaelsiegrist Can you take a look at this issue?
Otherwise, we should probably revert e5a083d in 7.4.1, 8.0.0, and Bazel@HEAD

@meteorcloudy
Copy link
Member

@bazel-io fork 7.4.1

@meteorcloudy
Copy link
Member

@bazel-io fork 8.0.0

@michaelsiegrist
Copy link
Contributor

@meteorcloudy sure, I can try to take a look here.

@fhanau, can you verify the behavior in your environment without #23406 when the .S file contains actual assembly? For instance, this is the contents used in the unit test (dec.S):

.code
PUBLIC decrement
decrement PROC x:WORD
  xchg rcx,rax
  dec rax
  ret
decrement EndP
END

If you're able to compile that code with clang-cl rather than using ml64, then I suppose the issue is somehow with the MSVC/ClangCl setup I've been using for my testing. But if that code fails to compile using clang-cl, then I think the issue is with the commands passed to ml64 rather than with the tool being used.

Here's what I see in my environment when I compile that code with clang-cl:

PS C:\Users\micha\source\repos\test> & 'C:\Program Files\LLVM\bin\clang-cl.exe' dec.S        
dec.S:1:1: error: unknown directive .code
.code
^
dec.S:2:1: error: invalid instruction mnemonic 'public'
PUBLIC decrement
^~~~~~
dec.S:3:16: error: unexpected token in argument list
decrement PROC x:WORD
               ^
dec.S:4:3: error: unknown use of instruction mnemonic without a size suffix
  xchg rcx,rax
  ^
dec.S:5:3: error: ambiguous instructions require an explicit suffix (could be 'decb', 'decw', 'decl', or 'decq')
  dec rax
  ^
dec.S:7:1: error: invalid instruction mnemonic 'decrement'
decrement EndP
^~~~~~~~~
dec.S:8:1: error: invalid instruction mnemonic 'end'
END
^~~

Whereas when I use ml64, I get this:

PS C:\Users\micha\source\repos\test> & 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\Hostx64\x64\ml64.exe' dec.S                                                                                                                                                                                                                                                                                                                      
Microsoft (R) Macro Assembler (x64) Version 14.33.31629.0                                                                                                                                                                                                                                                                                                                                                                                                                      
Copyright (C) Microsoft Corporation.  All rights reserved.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     Assembling: dec.S                                                                                                                                                                                                                                                                                                                                                                                                                                                             
Microsoft (R) Incremental Linker Version 14.33.31629.0                                                                                                                                                                                                                                                                                                                                                                                                                         
Copyright (C) Microsoft Corporation.  All rights reserved.                                                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
/OUT:dec.exe                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
dec.obj                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
LINK : fatal error LNK1561: entry point must be defined

If you get the same behavior, then I think the right thing to do is to not pass the C/C++ compiler arguments to the assembler, at least for ml64. However, I'm not sure if that is true of all assemblers; I'm not very familiar with invoking them directly.

@fhanau
Copy link
Author

fhanau commented Nov 1, 2024

@michaelsiegrist I agree that the code in your example is likely to fail with clang-cl, regardless of what my build environment looks like. This is due to it using MASM-style syntax, which I assume is not supported by clang-cl (just how clang on Linux does not support MASM syntax)

The way I see it there's two things going on here that cause problems:

  1. MASM and clang-cl both support compiling assembly, but they presumably both support different syntaxes. MASM supports MASM syntax whereas clang-cl uses native AT&T syntax by default, which is widely used on Linux/macOS and makes it easier to write assembly that works across platforms. (both tools might support more than just that, I'm not that familiar with them). The file we need to compile is in non-MASM syntax too.
  2. clang-cl.exe accepts both MSVC-style arguments and Unix clang/gcc-style arguments, whereas MASM requires MSVC syntax.

As I explained in the issue description, there is no perfect solution here: Some asm files can be compiled only with MASM and some can only be compiled with clang-cl. This is a more fundamental issue than (2), which can be worked around by modifying copts. But if we have to choose one assembler to be used for the clang-cl toolchain, it is more consistent to use clang-cl.exe, as we use clang-cl for everything else (as mentioned, this will make some ASM files work and some files not work). As a side effect, this also solves (2) – we would want to not have C/C++ flags be passed to the assembler, but this seems difficult to fix and with clang-cl it is not harmful to do so.

@michaelsiegrist
Copy link
Contributor

@fhanau just to be sure I'm clear, it sounds like in your environment, you have some assembly files in AT&T format that are meant to be ingested by clang/clang-cl to be compiled on both Linux and Windows environments. Is that right?

If that is the case, and if as you say there is no great way to support both AT&T and MASM style assembly as input to the same assembler, I feel personally like it would make the most sense for MASM support to be the primary goal of Windows toolchains, just as AT&T support should be the primary goal of Linux toolchains. At least if we have to make a choice, it seems reasonable to me to prefer the "most native" option.

To give a bit more of my own context, we depend on both LLVM and Boost, which both have .S files buried in them that. Those .S files are MASM style and are automatically selected by their Bazel targets when compiling for Windows. If Bazel can't properly handle those files, there isn't a way to use those dependencies with a clang-cl toolchain.

I think it is still worth a stab at getting the C/C++ options detached from assembly options if we can, though I still need to look more at the toolchain code to see if it's possible to really do that.

Also, if you would like to use GCC-style arguments, would it be possible to use the clang toolchain on Windows instead of clang-cl? That's a bit of a shot in the dark, but perhaps it would provide better support for Linux-style arguments than the clang-cl toolchain does.

I did also find that there's an llvm-ml tool that could possibly be an alternative to ml64. I'll take a look at it next week to see if switching to that tool could get around the options issue as well. I think it still limits input to MASM style, but I can poke around it a bit to see if there are options to allow AT&T-style input.

@fhanau
Copy link
Author

fhanau commented Nov 5, 2024

@fhanau just to be sure I'm clear, it sounds like in your environment, you have some assembly files in AT&T format that are meant to be ingested by clang/clang-cl to be compiled on both Linux and Windows environments. Is that right?

If that is the case, and if as you say there is no great way to support both AT&T and MASM style assembly as input to the same assembler, I feel personally like it would make the most sense for MASM support to be the primary goal of Windows toolchains, just as AT&T support should be the primary goal of Linux toolchains. At least if we have to make a choice, it seems reasonable to me to prefer the "most native" option.

Yup, I think having Unix-style AT&T asm files describes our situation well. My concern is that clang-cl driver is fundamentally intended to make the clang interface compatible with Windows – it makes it possible to compile the same code across platforms using a shared set of compiler flags (some exceptions apply, of course) in accordance with the MSVC ABI so that it is possible to use clang to compile code across platforms and still depend on libraries using the MSVC ABI and support Windows-specific APIs. For applications developed primarily for Windows, the MSVC toolchain is a good choice.
The clang-cl toolchain makes it possible to use code that is written with Unix in mind and does not have the same limitations as the MSVC toolchain. MSVC lacks support for many C, Posix and C++ APIs and language extensions that are supported by clang/GCC on Linux (this situation may have improved a bit in recent years). Based on that the MSVC assembler (MASM), should be provided in the MSVC toolchain and the clang/LLVM assembler should be provided in the clang-cl toolchain (as invoked using the clang-cl.exe driver). This makes it possible to develop Windows-specific assembly and C/C++ code using the MSVC toolchain and assembly/code aiming for greater Unix interop with the clang-cl toolchain.

To give a bit more of my own context, we depend on both LLVM and Boost, which both have .S files buried in them that. Those .S files are MASM style and are automatically selected by their Bazel targets when compiling for Windows. If Bazel can't properly handle those files, there isn't a way to use those dependencies with a clang-cl toolchain.

Compiling such .S files sounds to me like a use case for the MSVC-based Bazel toolchain which already uses MASM. Fundamentally, I understand the MSVC toolchain as supporting compiling code that is for Windows and follows Windows-style conventions. I assume that there are other factors preventing you from using the MSVC toolchain – as discussed there's no perfect solution here.

I think it is still worth a stab at getting the C/C++ options detached from assembly options if we can, though I still need to look more at the toolchain code to see if it's possible to really do that.

Absolutely – I suspect this may require a lot of work since there's nothing like --asmopt that could set asm-only compiler options.

Also, if you would like to use GCC-style arguments, would it be possible to use the clang toolchain on Windows instead of clang-cl? That's a bit of a shot in the dark, but perhaps it would provide better support for Linux-style arguments than the clang-cl toolchain does.

I'm afraid that there is no such thing as a plain clang bazel toolchain for Windows. The clang-cl toolchain takes that role.

Either way, I think we've both described our perspectives in detail here, the bazel maintainers should weigh in at this point.

@meteorcloudy
Copy link
Member

The cc toolchain configuration code has actually been moved from Bazel to rules_cc for Bazel@HEAD and Bazel 8, see https://github.com/bazelbuild/rules_cc/blob/main/cc/private/toolchain/windows_cc_configure.bzl#L830-L831. This means we can actually fix the problem in rules_cc without a new bazel release.

I want to propose the following:

  • Revert e5a083d in Bazel 7.4.1, since while it fixed a bug, it introduced regression for other use cases.
  • Continue to look for a solution in rules_cc to properly support assemble compilation on Windows.

@michaelsiegrist @fhanau Does this sounds good?

@meteorcloudy
Copy link
Member

meteorcloudy commented Nov 5, 2024

Maybe the fix would be to remove assemble actions from the user_compile_flags feature and maybe some other features?

https://github.com/bazelbuild/rules_cc/blob/a5827bf372d12b684f629198ba195aa2f72075e8/cc/private/toolchain/windows_cc_toolchain_config.bzl#L1523-L1524

@fhanau
Copy link
Author

fhanau commented Nov 5, 2024

The cc toolchain configuration code has actually been moved from Bazel to rules_cc for Bazel@HEAD and Bazel 8, see https://github.com/bazelbuild/rules_cc/blob/main/cc/private/toolchain/windows_cc_configure.bzl#L830-L831. This means we can actually fix the problem in rules_cc without a new bazel release.

I want to propose the following:

  • Revert e5a083d in Bazel 7.4.1, since while it fixed a bug, it introduced regression for other use cases.
  • Continue to look for a solution in rules_cc to properly support assemble compilation on Windows.

@michaelsiegrist @fhanau Does this sounds good?

Thank you, that sounds like a path forward! Modifying user_compile_flags as suggested sounds worth exploring, but there might be developers that rely on adding specific flags when compiling assembly so it'll require some discussion at least. Either way, it's certainly more convenient to address this within rules_cc so that it's not dependent on bazel releases.

@fmeum
Copy link
Collaborator

fmeum commented Nov 5, 2024

The right path forward may very well be to add --asmopt to Bazel itself.

@michaelsiegrist
Copy link
Contributor

The cc toolchain configuration code has actually been moved from Bazel to rules_cc for Bazel@HEAD and Bazel 8, see https://github.com/bazelbuild/rules_cc/blob/main/cc/private/toolchain/windows_cc_configure.bzl#L830-L831. This means we can actually fix the problem in rules_cc without a new bazel release.

I want to propose the following:

  • Revert e5a083d in Bazel 7.4.1, since while it fixed a bug, it introduced regression for other use cases.
  • Continue to look for a solution in rules_cc to properly support assemble compilation on Windows.

@michaelsiegrist @fhanau Does this sounds good?

Sure, that sounds good to me. We can use rules_cc for our needs while this all gets ironed out. And I suppose it's fine by me if this gets reverted in rules_cc as well.

I do think it would be worth investigating further what the right thing to do for selecting an assembler. Perhaps the ClangCL toolset used by CMake would be informative here. If I understand correctly, the ClangCL toolset uses clang-cl and other LLVM tools to create a CMake toolchain usable in MSBuild projects, and those projects (I believe) have ABI compatibility with code compiled with an MSVC toolchain.

Here's what I see when I use CMake to compile Boost on Windows with MSVC and the ClangCL toolset.

Set up the CMake project:

cmake -B build -S . -G "Visual Studio 17 2022" -T ClangCL

Build with verbose output, and note that clang-cl is chosen for compiling C++ files and llvm-lib for linking while MSVC's ml64 is chosen for the assembly files:

>cmake --build build --target boost_context --verbose
MSBuild version 17.11.9+a69bbaaf5 for .NET Framework
Build started 11/8/2024 3:31:25 PM.

Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\context\boost_context.vcxproj" on node 1 (default targets).
Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\context\boost_context.vcxproj" (1) is building "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\ZERO_CHECK.vcxproj" (2) on node 1 (default targets).
PrepareForBuild:
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
InitializeBuildStatus:
  Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
PreBuildEvent:
  Checking File Globs
  setlocal
  "C:\Program Files\CMake\bin\cmake.exe" -P C:/Users/micha/source/repos/bazel-test/bazel-bazel-test/external/rules_boost~~non_module_dependencies~boost/build/CMakeFiles/VerifyGlobs.cmake
  if %errorlevel% neq 0 goto :cmEnd
  :cmEnd
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd
  :VCEnd
CustomBuild:
  Checking Build System
FinalizeBuildStatus:
  Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\ZERO_CHECK.vcxproj" (default targets).
Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\context\boost_context.vcxproj" (1) is building "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\assert\boost_assert.vcxproj" (3) on node 1 (default targets).
PrepareForBuild:
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
InitializeBuildStatus:
  Creating "boost_assert\x64\Debug\boost_assert.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "boost_assert\x64\Debug\boost_assert.tlog\unsuccessfulbuild".
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "boost_assert\x64\Debug\boost_assert.tlog\unsuccessfulbuild".
  Touching "boost_assert\x64\Debug\boost_assert.tlog\boost_assert.lastbuildstate".
Done Building Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\assert\boost_assert.vcxproj" (default targets).
Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\context\boost_context.vcxproj" (1) is building "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\core\boost_core.vcxproj" (4) on node 1 (default targets).
PrepareForBuild:
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
InitializeBuildStatus:
  Creating "boost_core\x64\Debug\boost_core.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "boost_core\x64\Debug\boost_core.tlog\unsuccessfulbuild".
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "boost_core\x64\Debug\boost_core.tlog\unsuccessfulbuild".
  Touching "boost_core\x64\Debug\boost_core.tlog\boost_core.lastbuildstate".
Done Building Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\core\boost_core.vcxproj" (default targets).
PrepareForBuild:
  Structured output is enabled. The formatting of compiler diagnostics will reflect the error hierarchy. See https://aka.ms/cpp/structured-output for more details.
InitializeBuildStatus:
  Creating "boost_context.dir\Debug\boost_context.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
  Touching "boost_context.dir\Debug\boost_context.tlog\unsuccessfulbuild".
CustomBuild:
  Building Custom Rule C:/Users/micha/source/repos/bazel-test/bazel-bazel-test/external/rules_boost~~non_module_dependencies~boost/libs/context/CMakeLists.txt
_MASM:
  Assembling C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\make_x86_64_ms_pe_masm.asm...
  cmd.exe /C "C:\Users\micha\AppData\Local\Temp\tmp28dfa4ba832345da9a44e9bcaf7fdbbe.cmd"
  ml64.exe /c /nologo /Zi /Fo"boost_context.dir\Debug\make_x86_64_ms_pe_masm.obj" /D"WIN32" /D"_WINDOWS" /D"BOOST_CONTEXT_NO_LIB=" /D"BOOST_CONTEXT_SOURCE=" /D"BOOST_CONTEXT_STATIC_LINK=" /D"BOOST_CONTEXT_EXPORT=" /D"CMAKE_INTDIR="Debug"" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\config\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\core\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\static_assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\throw_exception\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\mp11\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\pool\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\integer\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\type_traits\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\winapi\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\predef\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\smart_ptr\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\move\include" /W3 /errorReport:prompt  /Ta"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\make_x86_64_ms_pe_masm.asm"
_MASM:
  Assembling C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\jump_x86_64_ms_pe_masm.asm...
  cmd.exe /C "C:\Users\micha\AppData\Local\Temp\tmpb2dc24a1dac949ad9bc2717dc622cb03.cmd"
  ml64.exe /c /nologo /Zi /Fo"boost_context.dir\Debug\jump_x86_64_ms_pe_masm.obj" /D"WIN32" /D"_WINDOWS" /D"BOOST_CONTEXT_NO_LIB=" /D"BOOST_CONTEXT_SOURCE=" /D"BOOST_CONTEXT_STATIC_LINK=" /D"BOOST_CONTEXT_EXPORT=" /D"CMAKE_INTDIR="Debug"" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\config\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\core\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\static_assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\throw_exception\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\mp11\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\pool\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\integer\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\type_traits\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\winapi\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\predef\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\smart_ptr\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\move\include" /W3 /errorReport:prompt  /Ta"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\jump_x86_64_ms_pe_masm.asm"
_MASM:
  Assembling C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\ontop_x86_64_ms_pe_masm.asm...
  cmd.exe /C "C:\Users\micha\AppData\Local\Temp\tmp436c0124dc9e442a9cc9cd09e0902a0e.cmd"
  ml64.exe /c /nologo /Zi /Fo"boost_context.dir\Debug\ontop_x86_64_ms_pe_masm.obj" /D"WIN32" /D"_WINDOWS" /D"BOOST_CONTEXT_NO_LIB=" /D"BOOST_CONTEXT_SOURCE=" /D"BOOST_CONTEXT_STATIC_LINK=" /D"BOOST_CONTEXT_EXPORT=" /D"CMAKE_INTDIR="Debug"" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\config\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\core\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\static_assert\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\throw_exception\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\mp11\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\pool\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\integer\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\type_traits\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\winapi\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\predef\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\smart_ptr\include" /I "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\move\include" /W3 /errorReport:prompt  /Ta"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\asm\ontop_x86_64_ms_pe_masm.asm"
ClCompile:
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\clang-cl.exe /c /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\assert\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\config\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\core\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\static_assert\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\throw_exception\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\mp11\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\pool\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\integer\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\type_traits\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\winapi\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\predef\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\smart_ptr\include" /I"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\move\include" /Z7 /nologo /W1 /WX- /diagnostics:column /Od /Ob0 /D _MBCS /D WIN32 /D _WINDOWS /D BOOST_CONTEXT_NO_LIB= /D BOOST_CONTEXT_SOURCE= /D BOOST_CONTEXT_STATIC_LINK= /D BOOST_CONTEXT_EXPORT= /D "CMAKE_INTDIR=\"Debug\"" /EHsc /MDd /GS /fp:precise /GR /Fo"boost_context.dir\Debug\\" /Gd /TP --target=amd64-pc-windows-msvc  "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\libs\context\src\windows\stack_traits.cpp"
Lib:
  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\x64\bin\llvm-lib.exe /OUT:"C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\stage\lib\Debug\libboost_context-clangw17-mt-gd-x64-1_84.lib" /NOLOGO  /machine:x64 boost_context.dir\Debug\stack_traits.obj
  boost_context.dir\Debug\make_x86_64_ms_pe_masm.obj
  boost_context.dir\Debug\jump_x86_64_ms_pe_masm.obj
  boost_context.dir\Debug\ontop_x86_64_ms_pe_masm.obj
  boost_context.vcxproj -> C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\stage\lib\Debug\libboost_context-clangw17-mt-gd-x64-1_84.lib
FinalizeBuildStatus:
  Deleting file "boost_context.dir\Debug\boost_context.tlog\unsuccessfulbuild".
  Touching "boost_context.dir\Debug\boost_context.tlog\boost_context.lastbuildstate".
Done Building Project "C:\Users\micha\source\repos\bazel-test\bazel-bazel-test\external\rules_boost~~non_module_dependencies~boost\build\libs\context\boost_context.vcxproj" (default targets).

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.67

That said, I know this is a single data point, and it could be that Boost in particular (or CMake or MSVC) has some special knowledge that chooses ml64 for this case but could potentially choose some other tool for non-MASM assembly. It does seem like CMake has configuration for assembly compilation (ASM<DIALECT> and ASM<DIALECT>FLAGS) that may be helping differentiate between kinds of assembly in a way that Bazel doesn't.

All that to say, it does seem like having a separate --asmopt would be helpful for Bazel to implement, and then C/C++ options would be the combination of --copt and --conlyopt while assembly would be --copt and --asmopt (because it does look like include paths and preprocessor definitions are still passed to ml64).

That will still probably not help @fhanau, though, since instead of getting errors about unsupported options, ml64 would simply fail to compile the assembly, I imagine, since it would be AT&T style instead of MASM style. But to me, it seems like the thing to do is to choose a different assembler, and the way to do that would be with a custom toolchain. Based on everything I've found so far, it seems like ml64 and MASM should have first-class support on Windows with the built-in toolchains.

Some references:
https://learn.microsoft.com/en-us/cpp/build/clang-support-cmake?view=msvc-170#clang-compatibility-modes
https://clang.llvm.org/docs/MSVCCompatibility.html
https://clang.llvm.org/docs/UsersManual.html#clang-cl
https://cmake.org/cmake/help/latest/envvar/ASM_DIALECT.html
https://cmake.org/cmake/help/latest/envvar/ASM_DIALECTFLAGS.html

fhanau added a commit to fhanau/rules_cc that referenced this issue Nov 11, 2024
This essentially reverts bazelbuild/bazel#23337 now that the toolchain
configuration has been moved here. clang-cl does support assembly just like
other clang variants and unlike MASM supports assembly using native AT&T syntax
as with regular clang. MSVC-style assembly requires using MASM, which continues
to be available in the MSVC toolchain.

This has previously been discussed in bazelbuild/bazel#24152 and reverted for
Bazel 7.4.1 in bazelbuild/bazel#24211. Ideally, we'd want to have some mechanism
to make assembler selection configurable and support several kinds of asm syntax
in the future.
@Shaihammock86

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants