Skip to content

Commit 858dd08

Browse files
authored
Merge pull request #842 from brson/msvc
Default to MSVC on Windows
2 parents 9bf75b8 + f384d7b commit 858dd08

File tree

8 files changed

+66
-14
lines changed

8 files changed

+66
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ winapi = "0.2.8"
5757
winreg = "0.3.2"
5858
user32-sys = "0.1.2"
5959
kernel32-sys = "0.2.1"
60+
gcc = "0.3.28"
6061

6162
[dev-dependencies]
6263
rustup-mock = { path = "src/rustup-mock", version = "0.6.5" }

src/rustup-cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extern crate sha2;
2121
extern crate markdown;
2222
extern crate toml;
2323

24+
#[cfg(windows)]
25+
extern crate gcc;
2426
#[cfg(windows)]
2527
extern crate winapi;
2628
#[cfg(windows)]

src/rustup-cli/self_update.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,31 @@ This will uninstall all Rust toolchains and data, and remove
167167
}
168168
}
169169

170+
#[cfg(windows)]
171+
static MSVC_MESSAGE: &'static str =
172+
r#"# Rust Visual C++ prerequisites
173+
174+
Rust requires the Microsoft C++ build tools for Visual Studio 2013 or
175+
later, but they don't seem to be installed.
176+
177+
The easiest way to acquire the build tools is by installing Microsoft
178+
Visual C++ Build Tools 2015 which provides just the Visual C++ build
179+
tools:
180+
181+
http://landinghub.visualstudio.com/visual-cpp-build-tools
182+
183+
Alternately, you can install Visual Studio 2015 or Visual
184+
Studio 2013 and during install select the "C++ tools":
185+
186+
https://www.visualstudio.com/downloads/
187+
188+
_Install the C++ build tools before proceeding_.
189+
190+
If you will be targetting the GNU ABI or otherwise know what you are
191+
doing then it is fine to continue installation without the build
192+
tools, but otherwise, install the C++ build tools before proceeding.
193+
"#;
194+
170195
static TOOLS: &'static [&'static str]
171196
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb"];
172197

@@ -196,6 +221,11 @@ pub fn install(no_prompt: bool, verbose: bool,
196221
try!(do_pre_install_sanity_checks());
197222
try!(do_anti_sudo_check(no_prompt));
198223

224+
if !try!(do_msvc_check(&opts)) {
225+
info!("aborting installation");
226+
return Ok(());
227+
}
228+
199229
if !no_prompt {
200230
let ref msg = try!(pre_install_msg(opts.no_modify_path));
201231

@@ -422,6 +452,33 @@ fn do_anti_sudo_check(no_prompt: bool) -> Result<()> {
422452
Ok(())
423453
}
424454

455+
// Provide guidance about setting up MSVC if it doesn't appear to be
456+
// installed
457+
#[cfg(windows)]
458+
fn do_msvc_check(opts: &InstallOpts) -> Result<bool> {
459+
// Test suite skips this since it's env dependent
460+
if env::var("RUSTUP_INIT_SKIP_MSVC_CHECK").is_ok() {
461+
return Ok(true);
462+
}
463+
464+
use gcc::windows_registry;
465+
let installing_msvc = opts.default_host_triple.contains("msvc");
466+
let have_msvc = windows_registry::find_tool(&opts.default_host_triple, "cl.exe").is_some();
467+
if installing_msvc && !have_msvc {
468+
term2::stdout().md(MSVC_MESSAGE);
469+
if !try!(common::confirm("\nContinue? (Y/n)", true)) {
470+
return Ok(false);
471+
}
472+
}
473+
474+
Ok(true)
475+
}
476+
477+
#[cfg(not(windows))]
478+
fn do_msvc_check(_opts: &InstallOpts) -> Result<bool> {
479+
Ok(true)
480+
}
481+
425482
fn pre_install_msg(no_modify_path: bool) -> Result<String> {
426483
let cargo_home = try!(utils::cargo_home());
427484
let cargo_home_bin = cargo_home.join("bin");

src/rustup-dist/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ winapi = "0.2.8"
3232
winreg = "0.3.2"
3333
user32-sys = "0.1.2"
3434
kernel32-sys = "0.2.1"
35-
gcc = "0.3.28"
3635

3736
[target."cfg(not(windows))".dependencies]
3837
libc = "0.2.0"

src/rustup-dist/src/dist.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ impl TargetTriple {
116116
pub fn from_host() -> Option<Self> {
117117
#[cfg(windows)]
118118
fn inner() -> Option<TargetTriple> {
119-
use gcc::windows_registry;
120119
use kernel32::GetNativeSystemInfo;
121120
use std::mem;
122121

@@ -136,16 +135,9 @@ impl TargetTriple {
136135
_ => return None,
137136
};
138137

139-
// Now try to find an installation of msvc, using the gcc crate to do the hard work
138+
// Default to msvc
140139
let msvc_triple = format!("{}-pc-windows-msvc", arch);
141-
let gnu_triple = format!("{}-pc-windows-gnu", arch);
142-
if let Some(_) = windows_registry::find_tool(&msvc_triple, "cl.exe") {
143-
// Found msvc, so default to the msvc triple
144-
Some(TargetTriple(msvc_triple))
145-
} else {
146-
// No msvc found, so use gnu triple as a fallback
147-
Some(TargetTriple(gnu_triple))
148-
}
140+
Some(TargetTriple(msvc_triple))
149141
}
150142

151143
#[cfg(not(windows))]

src/rustup-dist/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ extern crate winreg;
2121
extern crate user32;
2222
#[cfg(windows)]
2323
extern crate kernel32;
24-
#[cfg(windows)]
25-
extern crate gcc;
2624
#[cfg(not(windows))]
2725
extern crate libc;
2826

src/rustup-mock/src/clitools.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ pub fn env(config: &Config, cmd: &mut Command) {
265265

266266
// Setting HOME will confuse the sudo check for rustup-init. Override it
267267
cmd.env("RUSTUP_INIT_SKIP_SUDO_CHECK", "yes");
268+
269+
// Skip the MSVC warning check since it's environment dependent
270+
cmd.env("RUSTUP_INIT_SKIP_MSVC_CHECK", "yes");
268271
}
269272

270273
pub fn run(config: &Config, name: &str, args: &[&str], env: &[(&str, &str)]) -> SanitizedOutput {

0 commit comments

Comments
 (0)