Skip to content

Commit

Permalink
Support VS 2017
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed May 30, 2017
1 parent f89d8d1 commit 068a3ba
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 533 deletions.
42 changes: 25 additions & 17 deletions src/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 src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ debug-assertions = false

[replace]
"https://github.com/rust-lang/cargo#0.20.0" = { path = "tools/cargo" }
"gcc:0.3.49" = { git = "https://github.com/brson/gcc-rs", branch = "vs2017" }
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
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.49"
libc = "0.2"
2 changes: 1 addition & 1 deletion src/liballoc_jemalloc/Cargo.toml
Original file line number Diff line number Diff line change
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.49"

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

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

[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.27"
gcc = "0.3.47"
2 changes: 1 addition & 1 deletion src/librustc_llvm/Cargo.toml
Original file line number Diff line number Diff line change
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.49"
3 changes: 3 additions & 0 deletions src/librustc_trans/Cargo.toml
Original file line number Diff line number Diff line change
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.49"
41 changes: 31 additions & 10 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
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.

Loading

0 comments on commit 068a3ba

Please sign in to comment.