Skip to content

Commit

Permalink
Support VS 2017
Browse files Browse the repository at this point in the history
Fixes #38584
  • Loading branch information
brson committed Jun 1, 2017
1 parent f89d8d1 commit da100fe
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 533 deletions.
35 changes: 18 additions & 17 deletions src/Cargo.lock

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

2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Expand Up @@ -36,5 +36,5 @@ num_cpus = "1.0"
toml = "0.1"
getopts = "0.2"
rustc-serialize = "0.3"
gcc = "0.3.46"
gcc = "0.3.50"
libc = "0.2"
2 changes: 1 addition & 1 deletion src/liballoc_jemalloc/Cargo.toml
Expand Up @@ -17,7 +17,7 @@ libc = { path = "../rustc/libc_shim" }

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
gcc = "0.3.50"

[features]
debug = []
2 changes: 1 addition & 1 deletion src/libcompiler_builtins/Cargo.toml
Expand Up @@ -16,4 +16,4 @@ core = { path = "../libcore" }

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
gcc = "0.3.50"
2 changes: 1 addition & 1 deletion src/libflate/Cargo.toml
Expand Up @@ -11,4 +11,4 @@ crate-type = ["dylib"]

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
gcc = "0.3.50"
2 changes: 1 addition & 1 deletion src/librustc_llvm/Cargo.toml
Expand Up @@ -17,4 +17,4 @@ rustc_bitflags = { path = "../librustc_bitflags" }

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
gcc = "0.3.50"
3 changes: 3 additions & 0 deletions src/librustc_trans/Cargo.toml
Expand Up @@ -25,3 +25,6 @@ rustc_platform_intrinsics = { path = "../librustc_platform_intrinsics" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }

[target."cfg(windows)".dependencies]
gcc = "0.3.50"
41 changes: 31 additions & 10 deletions src/librustc_trans/back/link.rs
Expand Up @@ -12,7 +12,6 @@ use super::archive::{ArchiveBuilder, ArchiveConfig};
use super::linker::Linker;
use super::rpath::RPathConfig;
use super::rpath;
use super::msvc;
use metadata::METADATA_FILENAME;
use rustc::session::config::{self, NoDebugInfo, OutputFilenames, Input, OutputType};
use rustc::session::filesearch;
Expand Down Expand Up @@ -142,20 +141,41 @@ pub fn build_link_meta(incremental_hashes_map: &IncrementalHashesMap) -> LinkMet
return r;
}

// The third parameter is for an extra path to add to PATH for MSVC
// cross linkers for host toolchain DLL dependencies
pub fn get_linker(sess: &Session) -> (String, Command, Option<PathBuf>) {
// The third parameter is for an env vars, used to set up the path for MSVC
// to find its DLLs
pub fn get_linker(sess: &Session) -> (String, Command, Vec<(OsString, OsString)>) {
if let Some(ref linker) = sess.opts.cg.linker {
(linker.clone(), Command::new(linker), None)
(linker.clone(), Command::new(linker), vec![])
} else if sess.target.target.options.is_like_msvc {
let (cmd, host) = msvc::link_exe_cmd(sess);
("link.exe".to_string(), cmd, host)
let (cmd, envs) = msvc_link_exe_cmd(sess);
("link.exe".to_string(), cmd, envs)
} else {
(sess.target.target.options.linker.clone(),
Command::new(&sess.target.target.options.linker), None)
Command::new(&sess.target.target.options.linker), vec![])
}
}

#[cfg(windows)]
pub fn msvc_link_exe_cmd(sess: &Session) -> (Command, Vec<(OsString, OsString)>) {
use gcc::windows_registry;

let target = &sess.opts.target_triple;
let tool = windows_registry::find_tool(target, "link.exe");

if let Some(tool) = tool {
let envs = tool.env().to_vec();
(tool.to_command(), envs)
} else {
debug!("Failed to locate linker.");
(Command::new("link.exe"), vec![])
}
}

#[cfg(not(windows))]
pub fn msvc_link_exe_cmd(_sess: &Session) -> (Command, Vec<(OsString, OsString)>) {
(Command::new("link.exe"), vec![])
}

pub fn get_ar_prog(sess: &Session) -> String {
sess.opts.cg.ar.clone().unwrap_or_else(|| {
sess.target.target.options.ar.clone()
Expand Down Expand Up @@ -706,8 +726,9 @@ fn link_natively(sess: &Session,
let flavor = sess.linker_flavor();

// The invocations of cc share some flags across platforms
let (pname, mut cmd, extra) = get_linker(sess);
cmd.env("PATH", command_path(sess, extra));
let (pname, mut cmd, envs) = get_linker(sess);
// This will set PATH on MSVC
cmd.envs(envs);

let root = sess.target_filesearch(PathKind::Native).get_lib_path();
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
Expand Down
56 changes: 0 additions & 56 deletions src/librustc_trans/back/msvc/arch.rs

This file was deleted.

0 comments on commit da100fe

Please sign in to comment.