Skip to content

Commit

Permalink
Default to MSVC on Windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brson committed Dec 2, 2016
1 parent f6cd385 commit 4795228
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions src/rustup-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
48 changes: 48 additions & 0 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ This will uninstall all Rust toolchains and data, and remove
}
}

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"];

Expand Down Expand Up @@ -200,6 +224,11 @@ pub fn install(no_prompt: bool, verbose: bool,
// miscompiled on the deployed builds. I am very confused.
//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));

Expand Down Expand Up @@ -423,6 +452,25 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
Ok(())
}

// Provide guidance about setting up MSVC if it doesn't appear to be
// installed
fn do_msvc_check(opts: &InstallOpts) -> Result<bool> {
if cfg!(windows) {
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();
let have_msvc = false;
if installing_msvc && !have_msvc {
term2::stdout().md(MSVC_MESSAGE);
if !try!(common::confirm("\nContinue? (Y/n)", true)) {
return Ok(false);
}
}
}

Ok(true)
}

fn pre_install_msg(no_modify_path: bool) -> Result<String> {
let cargo_home = try!(utils::cargo_home());
let cargo_home_bin = cargo_home.join("bin");
Expand Down
1 change: 0 additions & 1 deletion src/rustup-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 2 additions & 10 deletions src/rustup-dist/src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl TargetTriple {
pub fn from_host() -> Option<Self> {
#[cfg(windows)]
fn inner() -> Option<TargetTriple> {
use gcc::windows_registry;
use kernel32::GetNativeSystemInfo;
use std::mem;

Expand All @@ -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))]
Expand Down
2 changes: 0 additions & 2 deletions src/rustup-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4795228

Please sign in to comment.