From f384d7bed662c305d5926e7d8aa22da7acb0d6f1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 1 Dec 2016 19:33:25 -0800 Subject: [PATCH] Default to MSVC on Windows Instead of picking MSVC/GNU based on detection, just default to MSVC. During install, if MSVC is not detected provide guidance. This is more predictable and easier to explain. --- Cargo.lock | 2 +- Cargo.toml | 1 + src/rustup-cli/main.rs | 2 ++ src/rustup-cli/self_update.rs | 57 +++++++++++++++++++++++++++++++++ src/rustup-dist/Cargo.toml | 1 - src/rustup-dist/src/dist.rs | 12 ++----- src/rustup-dist/src/lib.rs | 2 -- src/rustup-mock/src/clitools.rs | 3 ++ 8 files changed, 66 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc1649c72d..9791ebb480 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -549,6 +549,7 @@ dependencies = [ "clap 2.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "download 0.3.0", "error-chain 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -579,7 +580,6 @@ version = "0.6.5" dependencies = [ "error-chain 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "gcc 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 165ebca498..3d08e3e6f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,6 +57,7 @@ winapi = "0.2.8" winreg = "0.3.2" user32-sys = "0.1.2" kernel32-sys = "0.2.1" +gcc = "0.3.28" [dev-dependencies] rustup-mock = { path = "src/rustup-mock", version = "0.6.5" } diff --git a/src/rustup-cli/main.rs b/src/rustup-cli/main.rs index 50ba59fe0b..3dfb9937e2 100644 --- a/src/rustup-cli/main.rs +++ b/src/rustup-cli/main.rs @@ -21,6 +21,8 @@ extern crate sha2; extern crate markdown; extern crate toml; +#[cfg(windows)] +extern crate gcc; #[cfg(windows)] extern crate winapi; #[cfg(windows)] diff --git a/src/rustup-cli/self_update.rs b/src/rustup-cli/self_update.rs index 880e004254..29e93c7aa6 100644 --- a/src/rustup-cli/self_update.rs +++ b/src/rustup-cli/self_update.rs @@ -167,6 +167,31 @@ This will uninstall all Rust toolchains and data, and remove } } +#[cfg(windows)] +static MSVC_MESSAGE: &'static str = +r#"# 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. + +The easiest way to acquire the build tools is by installing Microsoft +Visual C++ Build Tools 2015 which provides just the Visual C++ build +tools: + + http://landinghub.visualstudio.com/visual-cpp-build-tools + +Alternately, you can install Visual Studio 2015 or Visual +Studio 2013 and during install select the "C++ tools": + + https://www.visualstudio.com/downloads/ + +_Install the C++ build tools before proceeding_. + +If you will be targetting 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. +"#; + static TOOLS: &'static [&'static str] = &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb"]; @@ -196,6 +221,11 @@ pub fn install(no_prompt: bool, verbose: bool, try!(do_pre_install_sanity_checks()); try!(do_anti_sudo_check(no_prompt)); + if !try!(do_msvc_check(&opts)) { + info!("aborting installation"); + return Ok(()); + } + if !no_prompt { let ref msg = try!(pre_install_msg(opts.no_modify_path)); @@ -422,6 +452,33 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> { Ok(()) } +// Provide guidance about setting up MSVC if it doesn't appear to be +// installed +#[cfg(windows)] +fn do_msvc_check(opts: &InstallOpts) -> Result { + // Test suite skips this since it's env dependent + if env::var("RUSTUP_INIT_SKIP_MSVC_CHECK").is_ok() { + return Ok(true); + } + + use gcc::windows_registry; + let installing_msvc = opts.default_host_triple.contains("msvc"); + let have_msvc = windows_registry::find_tool(&opts.default_host_triple, "cl.exe").is_some(); + if installing_msvc && !have_msvc { + term2::stdout().md(MSVC_MESSAGE); + if !try!(common::confirm("\nContinue? (Y/n)", true)) { + return Ok(false); + } + } + + Ok(true) +} + +#[cfg(not(windows))] +fn do_msvc_check(_opts: &InstallOpts) -> Result { + Ok(true) +} + fn pre_install_msg(no_modify_path: bool) -> Result { let cargo_home = try!(utils::cargo_home()); let cargo_home_bin = cargo_home.join("bin"); diff --git a/src/rustup-dist/Cargo.toml b/src/rustup-dist/Cargo.toml index 86e239ffe2..15cebb132b 100644 --- a/src/rustup-dist/Cargo.toml +++ b/src/rustup-dist/Cargo.toml @@ -32,7 +32,6 @@ winapi = "0.2.8" winreg = "0.3.2" user32-sys = "0.1.2" kernel32-sys = "0.2.1" -gcc = "0.3.28" [target."cfg(not(windows))".dependencies] libc = "0.2.0" diff --git a/src/rustup-dist/src/dist.rs b/src/rustup-dist/src/dist.rs index 05e39e8c5a..c8f811e5cc 100644 --- a/src/rustup-dist/src/dist.rs +++ b/src/rustup-dist/src/dist.rs @@ -116,7 +116,6 @@ impl TargetTriple { pub fn from_host() -> Option { #[cfg(windows)] fn inner() -> Option { - use gcc::windows_registry; use kernel32::GetNativeSystemInfo; use std::mem; @@ -136,16 +135,9 @@ impl TargetTriple { _ => return None, }; - // Now try to find an installation of msvc, using the gcc crate to do the hard work + // Default to msvc let msvc_triple = format!("{}-pc-windows-msvc", arch); - let gnu_triple = format!("{}-pc-windows-gnu", arch); - if let Some(_) = windows_registry::find_tool(&msvc_triple, "cl.exe") { - // Found msvc, so default to the msvc triple - Some(TargetTriple(msvc_triple)) - } else { - // No msvc found, so use gnu triple as a fallback - Some(TargetTriple(gnu_triple)) - } + Some(TargetTriple(msvc_triple)) } #[cfg(not(windows))] diff --git a/src/rustup-dist/src/lib.rs b/src/rustup-dist/src/lib.rs index 5a4343b587..d87cd868aa 100644 --- a/src/rustup-dist/src/lib.rs +++ b/src/rustup-dist/src/lib.rs @@ -21,8 +21,6 @@ extern crate winreg; extern crate user32; #[cfg(windows)] extern crate kernel32; -#[cfg(windows)] -extern crate gcc; #[cfg(not(windows))] extern crate libc; diff --git a/src/rustup-mock/src/clitools.rs b/src/rustup-mock/src/clitools.rs index f04417d51a..75eb860a5c 100644 --- a/src/rustup-mock/src/clitools.rs +++ b/src/rustup-mock/src/clitools.rs @@ -265,6 +265,9 @@ pub fn env(config: &Config, cmd: &mut Command) { // Setting HOME will confuse the sudo check for rustup-init. Override it cmd.env("RUSTUP_INIT_SKIP_SUDO_CHECK", "yes"); + + // Skip the MSVC warning check since it's environment dependent + cmd.env("RUSTUP_INIT_SKIP_MSVC_CHECK", "yes"); } pub fn run(config: &Config, name: &str, args: &[&str], env: &[(&str, &str)]) -> SanitizedOutput {