Skip to content

Windows arm64: use cc-rs' prefer_clang_cl_over_msvc#2699

Closed
dennisameling wants to merge 2 commits intobriansmith:mainfrom
dennisameling:windows-arm64-clang-cl
Closed

Windows arm64: use cc-rs' prefer_clang_cl_over_msvc#2699
dennisameling wants to merge 2 commits intobriansmith:mainfrom
dennisameling:windows-arm64-clang-cl

Conversation

@dennisameling
Copy link
Copy Markdown

This is a new attempt to address #2215, and might supersede #2216 - I'll leave that up to you.

cc-rs version 1.2.35 introduced support for prefer_clang_cl_over_msvc, which automatically finds clang-cl in the Visual Studio installation directory and uses it instead of cl.exe. Since clang-cl supports MSVC-style flags, this should address the reported issue.

Confirming this is working as expected on Windows arm64. In this CI run you can see that clang-cl.exe is invoked as expected.

Comment thread build.rs
"/Zc:forScope",
"/Zc:inline",
// Warnings.
"/Wall",
Copy link
Copy Markdown
Author

@dennisameling dennisameling Sep 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be triggering the warnings (which are then treated as errors) that @MarijnS95 reported here. Even when adding /std:c11, they keep showing up:

warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519/curve25519.c:22:
warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519\internal.h:18:
warning: [email protected]: C:\repos\ring\include\ring-core/base.h(60,1): error: '_Static_assert' is incompatible with C standards before C11 [-Werror,-Wpre-c11-compat]
warning: [email protected]:    60 | OPENSSL_STATIC_ASSERT(sizeof(int32_t) == sizeof(int), "int isn't 32 bits.");
warning: [email protected]:       | ^
warning: [email protected]: C:\repos\ring\include\ring-core/type_check.h(29,42): note: expanded from macro 'OPENSSL_STATIC_ASSERT'
warning: [email protected]:    29 | #define OPENSSL_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
warning: [email protected]:       |                                          ^
warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519/curve25519.c:22:
warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519\internal.h:18:
warning: [email protected]: C:\repos\ring\include\ring-core/base.h(61,1): error: '_Static_assert' is incompatible with C standards before C11 [-Werror,-Wpre-c11-compat]
warning: [email protected]:    61 | OPENSSL_STATIC_ASSERT(sizeof(uint32_t) == sizeof(unsigned int), "unsigned int isn't 32 bits.");
warning: [email protected]:       | ^
warning: [email protected]: C:\repos\ring\include\ring-core/type_check.h(29,42): note: expanded from macro 'OPENSSL_STATIC_ASSERT'
warning: [email protected]:    29 | #define OPENSSL_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
warning: [email protected]:       |                                          ^
warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519/curve25519.c:22:
warning: [email protected]: In file included from C:\repos\ring\crypto/curve25519\internal.h:18:
warning: [email protected]: C:\repos\ring\include\ring-core/base.h(62,1): error: '_Static_assert' is incompatible with C standards before C11 [-Werror,-Wpre-c11-compat]
warning: [email protected]:    62 | OPENSSL_STATIC_ASSERT(sizeof(size_t) == sizeof(uintptr_t), "uintptr_t and size_t differ.");
warning: [email protected]:       | ^
warning: [email protected]: C:\repos\ring\include\ring-core/type_check.h(29,42): note: expanded from macro 'OPENSSL_STATIC_ASSERT'
warning: [email protected]:    29 | #define OPENSSL_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
warning: [email protected]:       |                                          ^

Removing the /Wall flag fixes the build. This looks like a bug in clang-cl.exe to me and I could reproduce the behavior in a minimal example. Reported that here: https://developercommunity.visualstudio.com/t/Calling-clang-clexe-with-Wall-reports/10961806

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a bug in clang-cl - /Wall in CL parlance translates to -Weverything in Clang parlance. That includes these spurious warnings designed to help users migrating code forward to avoid pitfalls when their code base uses multiple C versions simultaneously.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR #2802, which reduces the warning level with MSVC to /W4 on all targets.

Comment thread BUILDING.md
Alternatively, if the host machine is already a Windows ARM64 then use:
```
$env:Path += ";C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\ARM64\bin"
```
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\o/

Comment thread build.rs
};
// On Windows AArch64 we currently must use Clang to compile C code.
// clang-cl.exe has support for MSVC-style command-line arguments.
if target.os == WINDOWS && target.arch == AARCH64 && !compiler.is_like_clang() {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is !compiler.is_like_clang() necessary? I would expect cc-rs to already check that itself.

Copy link
Copy Markdown
Author

@dennisameling dennisameling Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, this was in place because there's technically two flavors of Clang for Windows:

If I understand things correctly, cc-rs will look at the target first (e.g. aarch64-pc-windows-msvc or aarch64-pc-windows-gnullvm) and based on that finds the appropriate compiler. It defaults to cl.exe for the former, and to clang.exe for the latter. The prefer_clang_cl_over_msvc flag just forces the use of clang-cl.exe instead of cl.exe, but looking at the logic shouldn't force clang-cl.exe if the compiling for targets like aarch64-pc-windows-gnullvm.

TL;DR: I think it should be OK to leave it out here, but we'd need to test compiling for the aarch64-pc-windows-gnullvm target to be sure. I'm a bit short on time this week, but will try to squeeze in some test runs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it indeed works just fine in your updated setup. Tested with cargo test --target aarch64-pc-windows-gnullvm in MSYS2 on arm64 Windows, as well as cargo test --target aarch64-pc-windows-msvc in regular Windows 11 ARM with Visual Studio 2022 + Clang installed.

I also tried the latter by explicitly removing Clang from the Visual Studio 2022 installation, which then failed with a clear error message. I'll work with the cc-rs team to get a dedicated entry in that documentation URL for clang-cl.exe not being found, indicating that users need to install the Clang tools for Visual Studio.

cargo:warning=Compiler family detection failed due to error: ToolNotFound: failed to find tool "clang-cl.exe": program not found (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help) 

  --- stderr
  running "perl" "C:/repos/ring/crypto/chacha/asm/chacha-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/chacha-armv8-win64.S"
  running "perl" "C:/repos/ring/crypto/cipher/asm/chacha20_poly1305_armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/chacha20_poly1305_armv8-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/aes/asm/aesv8-armx.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/aesv8-armx-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/aes/asm/aesv8-gcm-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/aesv8-gcm-armv8-win64.S"        
  running "perl" "C:/repos/ring/crypto/fipsmodule/aes/asm/ghash-neon-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/ghash-neon-armv8-win64.S"      
  running "perl" "C:/repos/ring/crypto/fipsmodule/aes/asm/ghashv8-armx.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/ghashv8-armx-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/aes/asm/vpaes-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/vpaes-armv8-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/bn/asm/armv8-mont.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/armv8-mont-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/ec/asm/p256-armv8-asm.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/p256-armv8-asm-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/sha/asm/sha512-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/sha512-armv8-win64.S"
  running "perl" "C:/repos/ring/crypto/fipsmodule/sha/asm/sha512-armv8.pl" "win64" "C:/repos/ring/target/aarch64-pc-windows-msvc/debug/build/ring-a8b6d2989661e2f1/out/sha256-armv8-win64.S"


  error occurred in cc-rs: failed to find tool "clang-cl.exe": program not found (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)

@briansmith
Copy link
Copy Markdown
Owner

If you can rebase this on top of the current main branch then I can review it this week and get it merged. Please check whether the !compiler.is_like_clang() check is really necessary.

@briansmith
Copy link
Copy Markdown
Owner

I took a stab at doing the same thing in PR #2803, cleaning up the logic a bit. PTAL.

@briansmith
Copy link
Copy Markdown
Owner

Thanks for submitting this. A slightly different version of these changes was merged in PR #2803.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants