Skip to content

Add "prefer to use clang instead of MSVC" API that can automatically find Microsoft-provided clang #882

Open
@briansmith

Description

@briansmith

I would love to be able in my build.rs to instead just say b.prefer_clang_over_msvc() to get cc-rs to automatically discover Microsoft-provided clang's and use it if/when it is available, when it would otherwise choose MSVC.

Some projects, such as ring, require clang when building for Windows AArch64.
Some projects, such as ring would prefer to build with clang if it were available, when building for Windows X86-64, because the C code is optimized for clang in various ways (because Google uses clang for everything, and the C code we have comes from Google, and Google's preferences are unlikely to change any time soon).

Currently I am recommending people to do this:

$env:Path += ";C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\Llvm\x64\bin"

to get ring to build for aarch64-pc-windows-msvc using the clang that Microsoft provides with the build tools. Unfortunately, this advice is problematic:

  • It is one extra step that shouldn't be necessary.
  • "2022" varies depending on the version of MS build tools that is released
  • "BuildTools" varies depending on whether the user installed the "Build Tools," "Community," "Enterprise," etc. edition of Visual Studio.
  • "x64" varies depending on the host: ARM64 vs. x64, IIRC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions