2016-01-21 17:21:13 -06:00
|
|
|
use std::env;
|
2022-02-24 06:30:50 -06:00
|
|
|
use std::ffi::{OsStr, OsString};
|
|
|
|
use std::fmt::Display;
|
2016-07-25 17:37:12 -05:00
|
|
|
use std::path::{Path, PathBuf};
|
2022-02-24 06:30:50 -06:00
|
|
|
use std::process::{Command, Stdio};
|
2016-01-21 17:21:13 -06:00
|
|
|
|
2022-07-03 09:02:20 -05:00
|
|
|
const OPTIONAL_COMPONENTS: &[&str] = &[
|
|
|
|
"x86",
|
|
|
|
"arm",
|
|
|
|
"aarch64",
|
|
|
|
"amdgpu",
|
|
|
|
"avr",
|
2022-07-07 02:46:10 -05:00
|
|
|
"loongarch",
|
2022-07-03 09:02:20 -05:00
|
|
|
"m68k",
|
2023-07-13 09:19:59 -05:00
|
|
|
"csky",
|
2022-07-03 09:02:20 -05:00
|
|
|
"mips",
|
|
|
|
"powerpc",
|
|
|
|
"systemz",
|
|
|
|
"jsbackend",
|
|
|
|
"webassembly",
|
|
|
|
"msp430",
|
|
|
|
"sparc",
|
|
|
|
"nvptx",
|
|
|
|
"hexagon",
|
|
|
|
"riscv",
|
|
|
|
"bpf",
|
|
|
|
];
|
|
|
|
|
|
|
|
const REQUIRED_COMPONENTS: &[&str] =
|
|
|
|
&["ipo", "bitreader", "bitwriter", "linker", "asmparser", "lto", "coverage", "instrumentation"];
|
|
|
|
|
2017-11-30 19:54:02 -06:00
|
|
|
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`.
|
2020-07-22 11:51:19 -05:00
|
|
|
if tracked_env_var_os("LLVM_LINK_SHARED").is_some() {
|
2017-11-30 19:54:02 -06:00
|
|
|
("dylib", "--link-shared")
|
|
|
|
} else {
|
|
|
|
("static", "--link-static")
|
2016-11-17 23:50:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 06:30:50 -06:00
|
|
|
// Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
|
|
|
|
// break: the dylib path for the compiler, as of this writing, contains a copy of the LLVM
|
|
|
|
// shared library, which means that when our freshly built llvm-config goes to load it's
|
|
|
|
// associated LLVM, it actually loads the compiler's LLVM. In particular when building the first
|
|
|
|
// compiler (i.e., in stage 0) that's a problem, as the compiler's LLVM is likely different from
|
|
|
|
// the one we want to use. As such, we restore the environment to what bootstrap saw. This isn't
|
|
|
|
// perfect -- we might actually want to see something from Cargo's added library paths -- but
|
|
|
|
// for now it works.
|
|
|
|
fn restore_library_path() {
|
|
|
|
let key = tracked_env_var_os("REAL_LIBRARY_PATH_VAR").expect("REAL_LIBRARY_PATH_VAR");
|
|
|
|
if let Some(env) = tracked_env_var_os("REAL_LIBRARY_PATH") {
|
|
|
|
env::set_var(&key, &env);
|
|
|
|
} else {
|
|
|
|
env::remove_var(&key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Reads an environment variable and adds it to dependencies.
|
|
|
|
/// Supposed to be used for all variables except those set for build scripts by cargo
|
|
|
|
/// <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts>
|
|
|
|
fn tracked_env_var_os<K: AsRef<OsStr> + Display>(key: K) -> Option<OsString> {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rerun-if-env-changed={key}");
|
2022-02-24 06:30:50 -06:00
|
|
|
env::var_os(key)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rerun_if_changed_anything_in_dir(dir: &Path) {
|
|
|
|
let mut stack = dir
|
|
|
|
.read_dir()
|
|
|
|
.unwrap()
|
|
|
|
.map(|e| e.unwrap())
|
|
|
|
.filter(|e| &*e.file_name() != ".git")
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
while let Some(entry) = stack.pop() {
|
|
|
|
let path = entry.path();
|
|
|
|
if entry.file_type().unwrap().is_dir() {
|
|
|
|
stack.extend(path.read_dir().unwrap().map(|e| e.unwrap()));
|
|
|
|
} else {
|
|
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[track_caller]
|
|
|
|
fn output(cmd: &mut Command) -> String {
|
|
|
|
let output = match cmd.stderr(Stdio::inherit()).output() {
|
|
|
|
Ok(status) => status,
|
|
|
|
Err(e) => {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("\n\nfailed to execute command: {cmd:?}\nerror: {e}\n\n");
|
2022-02-24 06:30:50 -06:00
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if !output.status.success() {
|
|
|
|
panic!(
|
|
|
|
"command did not execute successfully: {:?}\n\
|
|
|
|
expected success, got: {}",
|
|
|
|
cmd, output.status
|
|
|
|
);
|
|
|
|
}
|
|
|
|
String::from_utf8(output.stdout).unwrap()
|
|
|
|
}
|
|
|
|
|
2016-01-21 17:21:13 -06:00
|
|
|
fn main() {
|
2022-07-03 09:02:20 -05:00
|
|
|
for component in REQUIRED_COMPONENTS.iter().chain(OPTIONAL_COMPONENTS.iter()) {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-check-cfg=values(llvm_component,\"{component}\")");
|
2022-07-03 09:02:20 -05:00
|
|
|
}
|
|
|
|
|
2020-07-22 11:51:19 -05:00
|
|
|
if tracked_env_var_os("RUST_CHECK").is_some() {
|
2018-04-17 18:50:41 -05:00
|
|
|
// If we're just running `check`, there's no need for LLVM to be built.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-24 06:30:50 -06:00
|
|
|
restore_library_path();
|
2019-01-21 18:47:57 -06:00
|
|
|
|
2016-09-25 10:59:12 -05:00
|
|
|
let target = env::var("TARGET").expect("TARGET was not set");
|
2020-04-10 15:42:19 -05:00
|
|
|
let llvm_config =
|
2020-07-22 11:51:19 -05:00
|
|
|
tracked_env_var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
|
|
|
|
if let Some(dir) = tracked_env_var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
|
2020-04-10 15:42:19 -05:00
|
|
|
let to_test = dir
|
|
|
|
.parent()
|
|
|
|
.unwrap()
|
|
|
|
.parent()
|
|
|
|
.unwrap()
|
|
|
|
.join(&target)
|
|
|
|
.join("llvm/bin/llvm-config");
|
|
|
|
if Command::new(&to_test).output().is_ok() {
|
|
|
|
return Some(to_test);
|
|
|
|
}
|
2016-10-22 08:07:35 -05:00
|
|
|
}
|
2020-04-10 15:42:19 -05:00
|
|
|
None
|
|
|
|
});
|
|
|
|
|
|
|
|
if let Some(llvm_config) = &llvm_config {
|
|
|
|
println!("cargo:rerun-if-changed={}", llvm_config.display());
|
|
|
|
}
|
|
|
|
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
|
2016-01-21 17:21:13 -06:00
|
|
|
|
2016-02-24 19:09:17 -06:00
|
|
|
// Test whether we're cross-compiling LLVM. This is a pretty rare case
|
|
|
|
// currently where we're producing an LLVM for a different platform than
|
|
|
|
// what this build script is currently running on.
|
|
|
|
//
|
|
|
|
// In that case, there's no guarantee that we can actually run the target,
|
|
|
|
// so the build system works around this by giving us the LLVM_CONFIG for
|
|
|
|
// the host platform. This only really works if the host LLVM and target
|
|
|
|
// LLVM are compiled the same way, but for us that's typically the case.
|
|
|
|
//
|
2016-03-11 18:03:28 -06:00
|
|
|
// We *want* detect this cross compiling situation by asking llvm-config
|
2019-09-04 10:25:51 -05:00
|
|
|
// what its host-target is. If that's not the TARGET, then we're cross
|
2016-03-11 18:03:28 -06:00
|
|
|
// compiling. Unfortunately `llvm-config` seems either be buggy, or we're
|
|
|
|
// misconfiguring it, because the `i686-pc-windows-gnu` build of LLVM will
|
|
|
|
// report itself with a `--host-target` of `x86_64-pc-windows-gnu`. This
|
|
|
|
// tricks us into thinking we're doing a cross build when we aren't, so
|
|
|
|
// havoc ensues.
|
|
|
|
//
|
|
|
|
// In any case, if we're cross compiling, this generally just means that we
|
2019-09-04 10:25:51 -05:00
|
|
|
// can't trust all the output of llvm-config because it might be targeted
|
2016-03-11 18:03:28 -06:00
|
|
|
// for the host rather than the target. As a result a bunch of blocks below
|
|
|
|
// are gated on `if !is_crossed`
|
2016-09-25 10:59:12 -05:00
|
|
|
let target = env::var("TARGET").expect("TARGET was not set");
|
|
|
|
let host = env::var("HOST").expect("HOST was not set");
|
2016-02-24 19:09:17 -06:00
|
|
|
let is_crossed = target != host;
|
|
|
|
|
2016-01-21 17:21:13 -06:00
|
|
|
let components = output(Command::new(&llvm_config).arg("--components"));
|
|
|
|
let mut components = components.split_whitespace().collect::<Vec<_>>();
|
2022-07-03 09:02:20 -05:00
|
|
|
components.retain(|c| OPTIONAL_COMPONENTS.contains(c) || REQUIRED_COMPONENTS.contains(c));
|
2016-01-21 17:21:13 -06:00
|
|
|
|
2022-07-03 09:02:20 -05:00
|
|
|
for component in REQUIRED_COMPONENTS {
|
2016-01-21 17:21:13 -06:00
|
|
|
if !components.contains(component) {
|
2022-12-19 03:31:55 -06:00
|
|
|
panic!("require llvm component {component} but wasn't found");
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for component in components.iter() {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-cfg=llvm_component=\"{component}\"");
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Link in our own LLVM shims, compiled with the same flags as LLVM
|
|
|
|
let mut cmd = Command::new(&llvm_config);
|
|
|
|
cmd.arg("--cxxflags");
|
|
|
|
let cxxflags = output(&mut cmd);
|
2017-09-22 23:34:27 -05:00
|
|
|
let mut cfg = cc::Build::new();
|
2017-09-05 10:48:47 -05:00
|
|
|
cfg.warnings(false);
|
2016-01-21 17:21:13 -06:00
|
|
|
for flag in cxxflags.split_whitespace() {
|
2016-02-24 19:09:17 -06:00
|
|
|
// Ignore flags like `-m64` when we're doing a cross build
|
|
|
|
if is_crossed && flag.starts_with("-m") {
|
2016-05-29 04:27:34 -05:00
|
|
|
continue;
|
2016-02-24 19:09:17 -06:00
|
|
|
}
|
2017-03-17 14:52:44 -05:00
|
|
|
|
2018-12-17 23:10:59 -06:00
|
|
|
if flag.starts_with("-flto") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-17 14:52:44 -05:00
|
|
|
// -Wdate-time is not supported by the netbsd cross compiler
|
|
|
|
if is_crossed && target.contains("netbsd") && flag.contains("date-time") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-08-17 07:53:24 -05:00
|
|
|
// Include path contains host directory, replace it with target
|
|
|
|
if is_crossed && flag.starts_with("-I") {
|
|
|
|
cfg.flag(&flag.replace(&host, &target));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-01-21 17:21:13 -06:00
|
|
|
cfg.flag(flag);
|
|
|
|
}
|
2016-02-16 10:07:30 -06:00
|
|
|
|
2017-03-24 03:31:26 -05:00
|
|
|
for component in &components {
|
2017-11-26 15:25:49 -06:00
|
|
|
let mut flag = String::from("LLVM_COMPONENT_");
|
2016-02-16 10:07:30 -06:00
|
|
|
flag.push_str(&component.to_uppercase());
|
2017-11-26 15:25:49 -06:00
|
|
|
cfg.define(&flag, None);
|
2016-02-16 10:07:30 -06:00
|
|
|
}
|
|
|
|
|
2020-07-22 11:51:19 -05:00
|
|
|
if tracked_env_var_os("LLVM_RUSTLLVM").is_some() {
|
2017-11-26 15:25:49 -06:00
|
|
|
cfg.define("LLVM_RUSTLLVM", None);
|
2016-07-29 08:09:32 -05:00
|
|
|
}
|
|
|
|
|
2020-07-22 11:51:19 -05:00
|
|
|
if tracked_env_var_os("LLVM_NDEBUG").is_some() {
|
2019-08-15 14:55:03 -05:00
|
|
|
cfg.define("NDEBUG", None);
|
2020-02-11 18:15:34 -06:00
|
|
|
cfg.debug(false);
|
2019-08-15 14:55:03 -05:00
|
|
|
}
|
|
|
|
|
2022-02-24 06:30:50 -06:00
|
|
|
rerun_if_changed_anything_in_dir(Path::new("llvm-wrapper"));
|
2020-07-26 12:11:30 -05:00
|
|
|
cfg.file("llvm-wrapper/PassWrapper.cpp")
|
|
|
|
.file("llvm-wrapper/RustWrapper.cpp")
|
|
|
|
.file("llvm-wrapper/ArchiveWrapper.cpp")
|
|
|
|
.file("llvm-wrapper/CoverageMappingWrapper.cpp")
|
2022-05-28 05:43:51 -05:00
|
|
|
.file("llvm-wrapper/SymbolWrapper.cpp")
|
2020-07-26 12:11:30 -05:00
|
|
|
.file("llvm-wrapper/Linker.cpp")
|
2016-01-21 17:21:13 -06:00
|
|
|
.cpp(true)
|
|
|
|
.cpp_link_stdlib(None) // we handle this below
|
2020-07-26 12:11:30 -05:00
|
|
|
.compile("llvm-wrapper");
|
2016-01-21 17:21:13 -06:00
|
|
|
|
2017-11-30 19:54:02 -06:00
|
|
|
let (llvm_kind, llvm_link_arg) = detect_llvm_link();
|
2016-11-17 01:28:14 -06:00
|
|
|
|
2019-09-04 10:25:51 -05:00
|
|
|
// Link in all LLVM libraries, if we're using the "wrong" llvm-config then
|
2016-02-24 19:09:17 -06:00
|
|
|
// 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.
|
2016-01-21 17:21:13 -06:00
|
|
|
let mut cmd = Command::new(&llvm_config);
|
2017-11-30 19:54:02 -06:00
|
|
|
cmd.arg(llvm_link_arg).arg("--libs");
|
2016-11-06 04:45:21 -06:00
|
|
|
|
2016-02-24 19:09:17 -06:00
|
|
|
if !is_crossed {
|
|
|
|
cmd.arg("--system-libs");
|
2022-11-18 06:36:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target.starts_with("arm") && !target.contains("freebsd"))
|
2022-08-01 03:02:10 -05:00
|
|
|
|| target.starts_with("mips-")
|
|
|
|
|| target.starts_with("mipsel-")
|
|
|
|
|| target.starts_with("powerpc-")
|
|
|
|
{
|
|
|
|
// 32-bit targets need to link libatomic.
|
|
|
|
println!("cargo:rustc-link-lib=atomic");
|
2022-11-18 06:36:49 -06:00
|
|
|
} else if target.contains("windows-gnu") {
|
|
|
|
println!("cargo:rustc-link-lib=shell32");
|
|
|
|
println!("cargo:rustc-link-lib=uuid");
|
2023-08-07 19:11:01 -05:00
|
|
|
} else if target.contains("haiku")
|
|
|
|
|| target.contains("darwin")
|
|
|
|
|| (is_crossed && (target.contains("dragonfly") || target.contains("solaris")))
|
2023-08-01 17:54:30 -05:00
|
|
|
{
|
2022-11-18 06:36:49 -06:00
|
|
|
println!("cargo:rustc-link-lib=z");
|
2023-07-17 01:30:54 -05:00
|
|
|
} else if target.contains("netbsd") {
|
|
|
|
println!("cargo:rustc-link-lib=z");
|
|
|
|
println!("cargo:rustc-link-lib=execinfo");
|
2016-02-24 19:09:17 -06:00
|
|
|
}
|
2017-03-24 03:31:26 -05:00
|
|
|
cmd.args(&components);
|
2016-02-24 19:09:17 -06:00
|
|
|
|
2016-01-21 17:21:13 -06:00
|
|
|
for lib in output(&mut cmd).split_whitespace() {
|
2020-12-11 10:32:03 -06:00
|
|
|
let name = if let Some(stripped) = lib.strip_prefix("-l") {
|
|
|
|
stripped
|
|
|
|
} else if let Some(stripped) = lib.strip_prefix('-') {
|
|
|
|
stripped
|
2016-07-25 17:37:12 -05:00
|
|
|
} else if Path::new(lib).exists() {
|
|
|
|
// On MSVC llvm-config will print the full name to libraries, but
|
|
|
|
// we're only interested in the name part
|
|
|
|
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
|
2018-12-05 08:42:56 -06:00
|
|
|
name.trim_end_matches(".lib")
|
2016-07-25 17:37:12 -05:00
|
|
|
} else if lib.ends_with(".lib") {
|
|
|
|
// Some MSVC libraries just come up with `.lib` tacked on, so chop
|
|
|
|
// that off
|
2018-12-05 08:42:56 -06:00
|
|
|
lib.trim_end_matches(".lib")
|
2016-01-21 17:21:13 -06:00
|
|
|
} else {
|
2016-10-22 08:07:35 -05:00
|
|
|
continue;
|
2016-01-21 17:21:13 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// Don't need or want this library, but LLVM's CMake build system
|
|
|
|
// doesn't provide a way to disable it, so filter it here even though we
|
|
|
|
// may or may not have built it. We don't reference anything from this
|
|
|
|
// library and it otherwise may just pull in extra dependencies on
|
|
|
|
// libedit which we don't want
|
|
|
|
if name == "LLVMLineEditor" {
|
2016-10-22 08:07:35 -05:00
|
|
|
continue;
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
|
2016-05-29 04:27:34 -05:00
|
|
|
let kind = if name.starts_with("LLVM") { llvm_kind } else { "dylib" };
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib={kind}={name}");
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// LLVM ldflags
|
2016-02-24 19:09:17 -06:00
|
|
|
//
|
|
|
|
// If we're a cross-compile of LLVM then unfortunately we can't trust these
|
|
|
|
// ldflags (largely where all the LLVM libs are located). Currently just
|
|
|
|
// hack around this by replacing the host triple with the target and pray
|
|
|
|
// that those -L directories are the same!
|
2016-01-21 17:21:13 -06:00
|
|
|
let mut cmd = Command::new(&llvm_config);
|
2017-11-30 19:54:02 -06:00
|
|
|
cmd.arg(llvm_link_arg).arg("--ldflags");
|
2016-01-21 17:21:13 -06:00
|
|
|
for lib in output(&mut cmd).split_whitespace() {
|
2020-01-10 11:11:32 -06:00
|
|
|
if is_crossed {
|
2020-12-11 10:32:03 -06:00
|
|
|
if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
|
|
|
|
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
|
|
|
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
|
|
|
println!("cargo:rustc-link-search=native={}", stripped.replace(&host, &target));
|
2016-02-24 19:09:17 -06:00
|
|
|
}
|
2020-12-11 10:32:03 -06:00
|
|
|
} else if let Some(stripped) = lib.strip_prefix("-LIBPATH:") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-search=native={stripped}");
|
2020-12-11 10:32:03 -06:00
|
|
|
} else if let Some(stripped) = lib.strip_prefix("-l") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib={stripped}");
|
2020-12-11 10:32:03 -06:00
|
|
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-search=native={stripped}");
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 18:28:25 -05:00
|
|
|
// Some LLVM linker flags (-L and -l) may be needed even when linking
|
2020-07-26 12:11:30 -05:00
|
|
|
// rustc_llvm, for example when using static libc++, we may need to
|
2019-06-09 18:28:25 -05:00
|
|
|
// manually specify the library search path and -ldl -lpthread as link
|
|
|
|
// dependencies.
|
2020-07-22 11:51:19 -05:00
|
|
|
let llvm_linker_flags = tracked_env_var_os("LLVM_LINKER_FLAGS");
|
2019-06-09 18:28:25 -05:00
|
|
|
if let Some(s) = llvm_linker_flags {
|
|
|
|
for lib in s.into_string().unwrap().split_whitespace() {
|
2020-12-11 10:32:03 -06:00
|
|
|
if let Some(stripped) = lib.strip_prefix("-l") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib={stripped}");
|
2020-12-11 10:32:03 -06:00
|
|
|
} else if let Some(stripped) = lib.strip_prefix("-L") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-search=native={stripped}");
|
2019-06-09 18:28:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 11:51:19 -05:00
|
|
|
let llvm_static_stdcpp = tracked_env_var_os("LLVM_STATIC_STDCPP");
|
|
|
|
let llvm_use_libcxx = tracked_env_var_os("LLVM_USE_LIBCXX");
|
2017-03-19 13:31:49 -05:00
|
|
|
|
2016-12-18 11:31:42 -06:00
|
|
|
let stdcppname = if target.contains("openbsd") {
|
2019-08-15 08:34:23 -05:00
|
|
|
if target.contains("sparc64") { "estdc++" } else { "c++" }
|
2022-03-06 08:12:50 -06:00
|
|
|
} else if target.contains("darwin")
|
|
|
|
|| target.contains("freebsd")
|
|
|
|
|| target.contains("windows-gnullvm")
|
2023-03-23 03:33:54 -05:00
|
|
|
|| target.contains("aix")
|
2022-03-06 08:12:50 -06:00
|
|
|
{
|
2019-01-23 18:17:24 -06:00
|
|
|
"c++"
|
2017-03-19 13:31:49 -05:00
|
|
|
} else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
|
|
|
|
// NetBSD uses a separate library when relocation is required
|
2022-10-18 21:06:57 -05:00
|
|
|
"stdc++_p"
|
2018-11-13 18:25:51 -06:00
|
|
|
} else if llvm_use_libcxx.is_some() {
|
|
|
|
"c++"
|
2016-12-18 11:31:42 -06:00
|
|
|
} else {
|
|
|
|
"stdc++"
|
|
|
|
};
|
|
|
|
|
2021-12-03 11:48:53 -06:00
|
|
|
// RISC-V GCC erroneously requires libatomic for sub-word
|
2022-08-28 00:22:21 -05:00
|
|
|
// atomic operations. Some BSD uses Clang as its system
|
2021-12-03 11:48:53 -06:00
|
|
|
// compiler and provides no libatomic in its base system so
|
|
|
|
// does not want this.
|
2022-08-28 00:22:21 -05:00
|
|
|
if target.starts_with("riscv") && !target.contains("freebsd") && !target.contains("openbsd") {
|
2019-11-30 06:47:59 -06:00
|
|
|
println!("cargo:rustc-link-lib=atomic");
|
|
|
|
}
|
|
|
|
|
2016-01-21 17:21:13 -06:00
|
|
|
// C++ runtime library
|
|
|
|
if !target.contains("msvc") {
|
2017-03-19 13:31:49 -05:00
|
|
|
if let Some(s) = llvm_static_stdcpp {
|
2016-01-21 17:21:13 -06:00
|
|
|
assert!(!cxxflags.contains("stdlib=libc++"));
|
|
|
|
let path = PathBuf::from(s);
|
|
|
|
println!("cargo:rustc-link-search=native={}", path.parent().unwrap().display());
|
2019-10-28 15:43:37 -05:00
|
|
|
if target.contains("windows") {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib=static:-bundle={stdcppname}");
|
2019-10-28 15:43:37 -05:00
|
|
|
} else {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib=static={stdcppname}");
|
2019-10-28 15:43:37 -05:00
|
|
|
}
|
2016-01-21 17:21:13 -06:00
|
|
|
} else if cxxflags.contains("stdlib=libc++") {
|
|
|
|
println!("cargo:rustc-link-lib=c++");
|
|
|
|
} else {
|
2022-12-19 03:31:55 -06:00
|
|
|
println!("cargo:rustc-link-lib={stdcppname}");
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|
|
|
|
}
|
2017-03-24 12:59:27 -05:00
|
|
|
|
2020-06-19 08:02:12 -05:00
|
|
|
// Libstdc++ depends on pthread which Rust doesn't link on MinGW
|
|
|
|
// since nothing else requires it.
|
2022-03-06 08:12:50 -06:00
|
|
|
if target.ends_with("windows-gnu") {
|
2021-10-23 07:34:33 -05:00
|
|
|
println!("cargo:rustc-link-lib=static:-bundle=pthread");
|
2017-04-13 15:27:53 -05:00
|
|
|
}
|
2016-01-21 17:21:13 -06:00
|
|
|
}
|