Function find

Source
pub fn find(arch_or_target: &str, tool: &str) -> Option<Command>
Expand description

Attempts to find a tool within an MSVC installation using the Windows registry as a point to search from.

The arch_or_target argument is the architecture or the Rust target name that the tool should work for (e.g. compile or link for). The supported architecture names are:

  • "x64" or "x86_64"
  • "arm64" or "aarch64"
  • "arm64ec"
  • "x86", "i586" or "i686"
  • "arm" or "thumbv7a"

The tool argument is the tool to find. Supported tools include:

  • MSVC tools: cl.exe, link.exe, lib.exe, etc.
  • MSBuild: msbuild.exe
  • Visual Studio IDE: devenv.exe
  • Clang/LLVM tools: clang.exe, clang++.exe, clang-*.exe, llvm-*.exe, lld.exe, etc.

This function will return None if the tool could not be found, or it will return Some(cmd) which represents a command that’s ready to execute the tool with the appropriate environment variables set.

To find MSVC tools, this function will first attempt to detect if we are running in the context of a developer command prompt, and then use the tools as found in the current PATH. If that fails, it will attempt to locate the newest MSVC toolset in the newest installed version of Visual Studio. To limit the search to a specific version of the MSVC toolset, set the VCToolsVersion environment variable to the desired version (e.g. “14.44.35207”).

Note that this function always returns None for non-MSVC targets (if a full target name was specified).