Skip to content

Commit

Permalink
rustc_llvm: Assume at least LLVM 3.9 in build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Dec 1, 2017
1 parent 51342f1 commit 5c4452a
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions src/librustc_llvm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,14 @@ use std::path::{PathBuf, Path};

use build_helper::output;

fn detect_llvm_link(major: u32, minor: u32, llvm_config: &Path)
-> (&'static str, Option<&'static str>) {
if major > 3 || (major == 3 && minor >= 9) {
// Force the link mode we want, preferring static by default, but
// possibly overridden by `configure --enable-llvm-link-shared`.
if env::var_os("LLVM_LINK_SHARED").is_some() {
return ("dylib", Some("--link-shared"));
} else {
return ("static", Some("--link-static"));
}
} else if major == 3 && minor == 8 {
// Find out LLVM's default linking mode.
let mut mode_cmd = Command::new(llvm_config);
mode_cmd.arg("--shared-mode");
if output(&mut mode_cmd).trim() == "shared" {
return ("dylib", None);
} else {
return ("static", None);
}
fn detect_llvm_link() -> (&'static str, &'static str) {
// Force the link mode we want, preferring static by default, but
// possibly overridden by `configure --enable-llvm-link-shared`.
if env::var_os("LLVM_LINK_SHARED").is_some() {
("dylib", "--link-shared")
} else {
("static", "--link-static")
}
("static", None)
}

fn main() {
Expand Down Expand Up @@ -96,11 +83,11 @@ fn main() {
let version_output = output(&mut version_cmd);
let mut parts = version_output.split('.').take(2)
.filter_map(|s| s.parse::<u32>().ok());
let (major, minor) =
let (major, _minor) =
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
(major, minor)
} else {
(3, 7)
(3, 9)
};

if major > 3 {
Expand Down Expand Up @@ -171,17 +158,13 @@ fn main() {
.cpp_link_stdlib(None) // we handle this below
.compile("librustllvm.a");

let (llvm_kind, llvm_link_arg) = detect_llvm_link(major, minor, &llvm_config);
let (llvm_kind, llvm_link_arg) = detect_llvm_link();

// Link in all LLVM libraries, if we're uwring the "wrong" llvm-config then
// we don't pick up system libs because unfortunately they're for the host
// of llvm-config, not the target that we're attempting to link.
let mut cmd = Command::new(&llvm_config);
cmd.arg("--libs");

if let Some(link_arg) = llvm_link_arg {
cmd.arg(link_arg);
}
cmd.arg(llvm_link_arg).arg("--libs");

if !is_crossed {
cmd.arg("--system-libs");
Expand Down Expand Up @@ -230,10 +213,7 @@ fn main() {
// hack around this by replacing the host triple with the target and pray
// that those -L directories are the same!
let mut cmd = Command::new(&llvm_config);
if let Some(link_arg) = llvm_link_arg {
cmd.arg(link_arg);
}
cmd.arg("--ldflags");
cmd.arg(llvm_link_arg).arg("--ldflags");
for lib in output(&mut cmd).split_whitespace() {
if lib.starts_with("-LIBPATH:") {
println!("cargo:rustc-link-search=native={}", &lib[9..]);
Expand Down

0 comments on commit 5c4452a

Please sign in to comment.