rustbuild: update the llvm link logic further
There are now four static/shared scenarios that can happen for the supported LLVM versions: - 3.9+: By default use `llvm-config --link-static` - 3.9+ and `--enable-llvm-link-shared`: Use `--link-shared` instead. - 3.8: Use `llvm-config --shared-mode` and go with its answer. - 3.7: Just assume static, maintaining the status quo.
This commit is contained in:
parent
f13391a603
commit
f3240377e6
|
@ -17,6 +17,35 @@ use std::path::{PathBuf, Path};
|
|||
|
||||
use build_helper::output;
|
||||
|
||||
fn detect_llvm_link(llvm_config: &Path) -> (&'static str, Option<&'static str>) {
|
||||
let mut version_cmd = Command::new(llvm_config);
|
||||
version_cmd.arg("--version");
|
||||
let version_output = output(&mut version_cmd);
|
||||
let mut parts = version_output.split('.').take(2)
|
||||
.filter_map(|s| s.parse::<u32>().ok());
|
||||
if let (Some(major), Some(minor)) = (parts.next(), parts.next()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
("static", None)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rustc-cfg=cargobuild");
|
||||
|
||||
|
@ -123,14 +152,7 @@ fn main() {
|
|||
.cpp_link_stdlib(None) // we handle this below
|
||||
.compile("librustllvm.a");
|
||||
|
||||
// Find out LLVM's default linking mode.
|
||||
let mut cmd = Command::new(&llvm_config);
|
||||
cmd.arg("--shared-mode");
|
||||
let mut llvm_kind = if output(&mut cmd).trim() == "shared" {
|
||||
"dylib"
|
||||
} else {
|
||||
"static"
|
||||
};
|
||||
let (llvm_kind, llvm_link_arg) = detect_llvm_link(&llvm_config);
|
||||
|
||||
// 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
|
||||
|
@ -138,24 +160,8 @@ fn main() {
|
|||
let mut cmd = Command::new(&llvm_config);
|
||||
cmd.arg("--libs");
|
||||
|
||||
// Force static linking with "--link-static" if available, or
|
||||
// force "--link-shared" if the configuration requested it.
|
||||
let llvm_link_shared = env::var_os("LLVM_LINK_SHARED").is_some();
|
||||
let mut version_cmd = Command::new(&llvm_config);
|
||||
version_cmd.arg("--version");
|
||||
let version_output = output(&mut version_cmd);
|
||||
let mut parts = version_output.split('.');
|
||||
if let (Some(major), Some(minor)) = (parts.next().and_then(|s| s.parse::<u32>().ok()),
|
||||
parts.next().and_then(|s| s.parse::<u32>().ok())) {
|
||||
if major > 3 || (major == 3 && minor >= 9) {
|
||||
if llvm_link_shared {
|
||||
cmd.arg("--link-shared");
|
||||
llvm_kind = "dylib";
|
||||
} else {
|
||||
cmd.arg("--link-static");
|
||||
llvm_kind = "static";
|
||||
}
|
||||
}
|
||||
if let Some(link_arg) = llvm_link_arg {
|
||||
cmd.arg(link_arg);
|
||||
}
|
||||
|
||||
if !is_crossed {
|
||||
|
|
Loading…
Reference in New Issue