rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.08k stars 877 forks source link

rustup didn't install Visual Studio #3823

Open KotlinIsland opened 3 months ago

KotlinIsland commented 3 months ago

If rustup-init detects that Visual Studio is installed but with the incorrect modules, it should say so.

If you don’t have Visual Studio already installed then rustup-init will offer to automatically install the prerequisites. - https://rust-lang.github.io/rustup/installation/windows-msvc.html

But when I ran rustup it didn't offer to install Visual Studio:

> rustup

Rust Visual C++ prerequisites

Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
later, but they don't seem to be installed.

You can acquire the build tools by installing Microsoft Visual Studio.

  https://visualstudio.microsoft.com/downloads/

Check the box for "Desktop development with C++" which will ensure that the
needed components are installed. If your locale language is not English,
then additionally check the box for English under Language packs.

For more details see:

  https://rust-lang.github.io/rustup/installation/windows-msvc.html

Install the C++ build tools before proceeding.

If you will be targeting the GNU ABI or otherwise know what you are
doing then it is fine to continue installation without the build
tools, but otherwise, install the C++ build tools before proceeding.

Continue? (y/N)

And I see this with the default project:

> cargo build
   Compiling test v0.1.0 (C:\Users\AMONGUS\projects\test)
error: linker `link.exe` not found                                                                                                                                                                                              
  |
  = note: program not found

note: the msvc targets depend on the msvc linker but `link.exe` was not found                                                                                                                                                   

note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the Visual C++ option.

note: VS Code is a different product, and is not sufficient.

error: could not compile `test` (bin "test") due to 1 previous error       

is it 2013 or 2017?

Why is this most basic step of "install rust on Windows" seemingly so completely broken and/or poorly documented?

rami3l commented 3 months ago

@KotlinIsland Thanks for filing this issue!

Regarding your second point, the change has already been made in #3799 to match rustc's output.

cc @ChrisDenton for the first point, introduced in #3060... I don't even know rustup-init offers to install MSVC. Maybe that's not true? (But I have quit Windows in 2020, so my impression might not be entirely true either.)

ChrisDenton commented 3 months ago

Currently the offer to auto install only works if Visual Studio is not already installed. If it is installed but missing required components then they will not currently be installed for you. This could definitely be improved. In the meantime the rustup doc page does walkthrough manual installation.

It also doesn't currently work on aarch64. That's just waiting on someone implementing and testing it.

KotlinIsland commented 3 months ago

At this time, I don't believe I have Visual Studio installed. Maybe I did in the past at some point. Is this some kind of heuristic check to determine if VS is installed or not?

If VS is determined to be installed with incorrect modules, perhaps rustup-init could indicate as much?

ChrisDenton commented 3 months ago

At this time, I don't believe I have Visual Studio installed. Maybe I did in the past at some point. Is this some kind of heuristic check to determine if VS is installed or not?

Rustup uses the cc crate for finding if visual studio is installed. This is the same crate that's used by rust itself for finding VS tools. You can see the logic here: https://github.com/rust-lang/rustup/blob/fcff18cb4c45cb27ae3c1194f4a464f9439efab7/src/cli/self_update/windows.rs#L109-L122

If VS is determined to be installed with incorrect modules, perhaps rustup-init could indicate as much?

Sure, the message here would need to be changed to a more specific message rather than the general manual install message. https://github.com/rust-lang/rustup/blob/fcff18cb4c45cb27ae3c1194f4a464f9439efab7/src/cli/self_update.rs#L420

ChrisDenton commented 3 months ago

Incidentally, if you do have visual studio installed then there should be a "Visual Studio Installer" in your start menu,

KotlinIsland commented 3 months ago

I don't: image

KotlinIsland commented 3 months ago

I assume some registry key exists on my machine from a previous install.