-
Notifications
You must be signed in to change notification settings - Fork 1k
Visual Studio prerequisites changes #4676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,70 +5,32 @@ For `msvc` targets these can be acquired through Visual Studio. | |
|
|
||
| ## Automatic install | ||
|
|
||
| If you don't have Visual Studio already installed then [rustup-init] will offer to automatically install the prerequisites. | ||
| Doing so means you can skip the rest of this page. | ||
| However, it installs Visual Studio Community edition which may not be appropriate for all users. | ||
| It is free for individuals, academic and open source use, but not for other uses, such as in proprietary enterprise software. | ||
| Users should ask their organisation which edition is right for them. | ||
| See [licensing terms][vs licences] for more details. | ||
| If you don't have Visual Studio already installed then the [rustup-init.exe][rustinstall] installer will offer to automatically install the prerequisites. | ||
|
|
||
| ## Manual install | ||
|
|
||
| [Download Visual Studio][vs downloads]. | ||
| Rust supports Visual Studio 2017 and later but it is recommended that you use the latest version (currently 2022) for new projects. | ||
| You can opt to download only the Build Tools for Visual Studio, which does not include the IDE. | ||
| However this requires you already have a license to the Community, Professional or Enterprise edition. | ||
| If you chose the automatic install this winget command will run in the background: | ||
| ```Batchfile | ||
| winget install --id Microsoft.VisualStudio.BuildTools --force --interactive --custom "--focusedUi --addProductLang En-us --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.26100" | ||
| ``` | ||
|
|
||
| Once you've downloaded and started the installer, the easiest way to get everything installed is to select "Desktop Development with C++". | ||
| This will include the necessary components. | ||
| On the "Language Packs" tab, make sure the English language pack is installed in addition to your preferred language. | ||
| But you could [download the Microsoft Build Tools for Visual Studio][vs download] Installer yourself and do the same steps manually. | ||
|
|
||
| If you want more details on the installation process or want to further customize the install then follow the walkthrough below. | ||
| Otherwise complete the Visual Studio install and continue with installing Rust. | ||
|
|
||
| ## Walkthrough: Installing Visual Studio 2022 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we should remove the GUI instructions, especially as it's the main user interface for the Visual Studio installer. If it's confusing we should improve that. If other installation methods are better then we should add those.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But to be honest if someone cant use the installer and find the, in text form described, components he is on the level of my grandma using a computer 😬 I even would remove the license part... somehow there isn't even a way around other then to accept them. And somehow I wanted to clarify that it would be better to use the new auto installer because unlike other examples it does the exact same (but guided) as you would do manual. For me as a complete newcomer to rust (one week), the documentation only to get rustup ready, splatted over 3 documentations was a bit too much for these little requirements.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to read it all. We can add a command line section before the full GUI instructions. The reason it was added in the first place is because people do indeed struggle with it. |
||
|
|
||
| This walkthrough uses the Community edition of Visual Studio but the Professional, Enterprise and the Build Tools all work the same way. | ||
|
|
||
| The installer will start by linking to the [license][vs licences] and for your edition of Visual Studio and then preparing the installer. | ||
| The installer will start by linking to the [Build Tools license][vs licences] and will install the "Visual Studio Installer", a tool to manage Visual Studio components. | ||
|
|
||
|  | ||
|  | ||
|
|
||
| Once this finishes, you can then select the components to be installed. | ||
| Here we use the "Workload" tab to select the "Desktop Development with C++" workload. | ||
| This will includes all needed components for Rust: | ||
|  | ||
|
|
||
| ### Installing only the required components (optional) | ||
|
|
||
| If you'd like a more minimal install (and won't be doing C++ development) then you can use the "Individual Components" tab to select just the essentials, which are: | ||
|
|
||
| * MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest) | ||
| * Windows 11 SDK (10.0.22621.0) | ||
|
|
||
| Note that the specific version of the Windows SDK doesn't matter for pure Rust code but if using C++ as well you'll likely want either the latest or whichever version is required by the C++ project (or both). | ||
|
|
||
|  | ||
|  | ||
|
|
||
| ### Adding Language Packs (optional) | ||
|
|
||
| After choosing the components, you may also want to select the language packs to install. | ||
| Switch to the "Language Packs" tab and add the languages. | ||
| It is recommended that you add the English language pack in addition to your preferred language. | ||
| This will provide English language error messages, which may help when reporting errors. | ||
|
|
||
|  | ||
|
|
||
| ### Completing the install | ||
| Then you need to install the "Individual components": | ||
| * MSVC Build Tools for x64/x86 (Latest) | ||
| * Windows 11 SDK (10.0.26100.XXXX) | ||
|
|
||
| Finally click the install button and wait for everything to be installed. | ||
| And the "Language pack": | ||
| * English | ||
|
|
||
|  | ||
|
|
||
| Once finished, you can continue on to installing Rust. | ||
| Once finished, you can continue on to installing Rust and the installer should detect MSVC. | ||
|
|
||
| [rustup-init]: https://rustup.rs | ||
| [vs downloads]: https://visualstudio.microsoft.com/downloads/ | ||
| [vs licences]: https://visualstudio.microsoft.com/license-terms/ | ||
| [vs licences]: https://visualstudio.microsoft.com/license-terms/vs2026-ga-diagnostic-buildtools | ||
| [vs download]: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2026 | ||
| [rustinstall]: https://rust-lang.org/tools/install/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,6 @@ use super::{InstallOpts, install_bins, report_error}; | |
| use crate::cli::markdown::md; | ||
| use crate::config::Cfg; | ||
| use crate::dist::TargetTriple; | ||
| use crate::dist::download::DownloadCfg; | ||
| use crate::download::download_file; | ||
| use crate::process::{ColorableTerminal, Process}; | ||
| use crate::utils; | ||
|
|
||
|
|
@@ -52,7 +50,7 @@ fn choice(max: u8, process: &Process) -> Result<Option<u8>> { | |
| pub(crate) fn choose_vs_install(process: &Process) -> Result<Option<VsInstallPlan>> { | ||
| writeln!( | ||
| process.stdout().lock(), | ||
| "\n1) Quick install via the Visual Studio Community installer" | ||
| "\n1) Quick install via the Visual Studio Installer" | ||
| )?; | ||
| writeln!( | ||
| process.stdout().lock(), | ||
|
|
@@ -145,13 +143,14 @@ later, but they don't seem to be installed. | |
| "#; | ||
|
|
||
| static MSVC_MANUAL_INSTALL_MESSAGE: &str = r#" | ||
| You can acquire the build tools by installing Microsoft Visual Studio. | ||
| You can acquire the build tools by installing the Build Tools for Microsoft Visual Studio: | ||
|
|
||
| https://visualstudio.microsoft.com/downloads/ | ||
| https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2026 | ||
|
|
||
| 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. | ||
| You will need the following components to be installed: | ||
| MSVC Build Tools for x64/x86 (Latest) | ||
| Windows 11 SDK (10.0.26100.XXXX) | ||
| Language pack: English | ||
|
|
||
| For more details see: | ||
|
|
||
|
|
@@ -199,9 +198,8 @@ pub(crate) fn do_msvc_check(opts: &InstallOpts<'_>, process: &Process) -> Option | |
| // If the user does not have Visual Studio installed and their host | ||
| // machine is i686 or x86_64 then it's OK to try an auto install. | ||
| // Otherwise a manual install will be required. | ||
| let has_any_vs = windows_registry::find_vs_version().is_ok(); | ||
| let is_x86 = host_triple.contains("i686") || host_triple.contains("x86_64"); | ||
| if is_x86 && !has_any_vs { | ||
rami3l marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if is_x86 { | ||
| Some(VsInstallPlan::Automatic) | ||
| } else { | ||
| Some(VsInstallPlan::Manual) | ||
|
|
@@ -262,47 +260,32 @@ pub(crate) async fn try_install_msvc( | |
| opts: &InstallOpts<'_>, | ||
| cfg: &Cfg<'_>, | ||
| ) -> Result<ContinueInstall> { | ||
| // download the installer | ||
| let visual_studio_url = utils::parse_url("https://aka.ms/vs/17/release/vs_community.exe")?; | ||
|
|
||
| let tempdir = tempfile::Builder::new() | ||
| .prefix("rustup-visualstudio") | ||
| .tempdir() | ||
| .context("error creating temp directory")?; | ||
|
|
||
| let visual_studio = tempdir.path().join("vs_setup.exe"); | ||
| let dl_cfg = DownloadCfg::new(cfg); | ||
| info!("downloading Visual Studio installer"); | ||
| download_file( | ||
| &visual_studio_url, | ||
| &visual_studio, | ||
| None, | ||
| None, | ||
| dl_cfg.process, | ||
| ) | ||
| .await?; | ||
|
|
||
| // Run the installer. Arguments are documented at: | ||
| // https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio | ||
| let mut cmd = Command::new(visual_studio); | ||
| cmd.arg("--wait") | ||
| // Display an interactive GUI focused on installing just the selected components. | ||
| .arg("--focusedUi") | ||
| // Add the English language pack | ||
| .args(["--addProductLang", "En-us"]) | ||
| // Add the linker and C runtime libraries. | ||
| .args(["--add", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"]); | ||
| info!("running the Visual Studio Installer\n"); | ||
| info!("Follow the Installation and Close the Window to continue with rustup!\n"); | ||
|
|
||
| let mut vsi_args = String::from( | ||
| "--focusedUi --addProductLang En-us --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64", | ||
| ); | ||
| // It's possible an earlier or later version of the Windows SDK has been | ||
| // installed separately from Visual Studio so installing it can be skipped. | ||
| if !has_windows_sdk_libs(cfg.process) { | ||
| cmd.args([ | ||
| "--add", | ||
| "Microsoft.VisualStudio.Component.Windows11SDK.26100", | ||
| ]); | ||
| vsi_args.push_str(" --add Microsoft.VisualStudio.Component.Windows11SDK.26100"); | ||
| } | ||
| info!("running the Visual Studio install"); | ||
| info!("rustup will continue once Visual Studio installation is complete\n"); | ||
|
|
||
| // Run the installer. Arguments are documented at: | ||
| // https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio | ||
| let mut cmd = Command::new("winget"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is If this is not the case, maybe we should notify the user and provide an installation hint?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it comes with every Windows 10 and 11 pre installed. In many cases Microsoft uses it itself for many things. (you can see it because many auto installed stuff comes with the install source winget) and you can find everything official through winget.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not with every SKU. E.g. Windows Sandbox does not have it installed by default. I'm not entirely against using winget here but I also don't think it get us anything useful. The aka.ms links always work. |
||
| cmd.arg("install") | ||
| .args(["--id", "Microsoft.VisualStudio.BuildTools"]) | ||
| // Simple force update the Installer | ||
| .arg("--force") | ||
| // Overide winget silent mode | ||
| .arg("--interactive") | ||
| // Add custom arguments to the installer | ||
| .arg("--custom") | ||
| // Has all to be an argument value of --custom | ||
| .arg(vsi_args); | ||
|
|
||
| let exit_status = cmd | ||
| .spawn() | ||
| .and_then(|mut child| child.wait()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question regarding #4543: will the wrong
--addparams causing the whole command to fail?The thing is that Microsoft, as it turned out, can remove any of those components from its server, meaning that these versions might no longer be valid a while later. However, if this is not a fatal error (meaning the GUI launches correctly and the user can tick the missing boxes manually) then this would be less of a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will appear to succeed but the component will be missing from the UI. There's nothing to indicate to the user that there is a missing component.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this was also a problem before (the vs installer is the same) and it only affects Windows 11 sdk. the "Microsoft.VisualStudio.Component.VC.Tools.x86.x64" is always the lasted version.
The best way would be to simple update the "Windows 11 SDK" it in the tool periodical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is a problem currently which is why we're looking into mitigations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are another 2 options:
Microsoft Visual Studio\Installer\setup.exe export --productId Microsoft.VisualStudio.Product.BuildTools --channelId VisualStudio.18.Release --config "%UserProfile%\Desktop\temp.vsconfig" --all --quiet```There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use
wingetthen doing a search for the latest would be best (we can use the version field to filter it).Using the json from the VS installer would be better in a sense because then we can be sure the it will show up labelled as installed when someone is attempting to debug issues. But I do worry that the json may not be stable between Visual Studio versions. That could be mitigated by ensuring we use a defined version.