Which Visual studio version does msvc toolset use?

If I have multiple Visual Studio versions installed (ex. 2019, 2017, 2015 or more...), which one will Rust's msvc toolset adopt?
Also, can I explicitly specify which version to use?

Maybe the 2019 version will be selected under the above conditions, is it correct?

It will choose the latest by default. You can get it to use another version by running rust in a "Native Tools Command Prompt". Check your start menu to find these.

@chrisd, thank you.

Is there any documentation that mentions it?

Not that I'm aware of. To be honest the Windows documentation could stand to be improved.

I only know because I'm aware of the code. Internally Rust uses the cc crate. The part relevant to finding the Visual studio tools is here:

// If VCINSTALLDIR is set, then someone's probably already run vcvars and we
// should just find whatever that indicates.
if env::var_os("VCINSTALLDIR").is_some() {
    return env::var_os("PATH")
        .and_then(|path| {
                .map(|p| p.join(tool))
                .find(|p| p.exists())
        .map(|path| Tool::with_family(path.into(), MSVC_FAMILY));

// Ok, if we're here, now comes the fun part of the probing. Default shells
// or shells like MSYS aren't really configured to execute `cl.exe` and the
// various compiler tools shipped as part of Visual Studio. Here we try to
// first find the relevant tool, then we also have to be sure to fill in
// environment variables like `LIB`, `INCLUDE`, and `PATH` to ensure that
// the tool is actually usable.

return impl_::find_msvc_15plus(tool, target)
    .or_else(|| impl_::find_msvc_14(tool, target))
    .or_else(|| impl_::find_msvc_12(tool, target))
    .or_else(|| impl_::find_msvc_11(tool, target));

So it first check if an environment variable has been set. If not it then tries to find the tools by starting from the newest versions of Visual Studio and working its way back.


I could understand very well in your reply, thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.