Skip to content

Commit

Permalink
Merge pull request #842 from brson/msvc
Browse files Browse the repository at this point in the history
Default to MSVC on Windows
  • Loading branch information
brson authored Dec 12, 2016
2 parents 9bf75b8 + f384d7b commit 858dd08
Show file tree
Hide file tree
Showing 8 changed files with 66 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
57 changes: 57 additions & 0 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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<bool> {
// 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<bool> {
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
3 changes: 3 additions & 0 deletions src/rustup-mock/src/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 858dd08

Please sign in to comment.