1 use crate::common::Config;
4 use std::path::PathBuf;
11 /// Conversion table from triple OS name to Rust SYSNAME
12 const OS_TABLE: &'static [(&'static str, &'static str)] = &[
13 ("android", "android"),
14 ("androideabi", "android"),
15 ("cloudabi", "cloudabi"),
18 ("dragonfly", "dragonfly"),
19 ("emscripten", "emscripten"),
20 ("freebsd", "freebsd"),
21 ("fuchsia", "fuchsia"),
24 ("illumos", "illumos"),
28 ("mingw32", "windows"),
31 ("openbsd", "openbsd"),
34 ("solaris", "solaris"),
36 ("windows", "windows"),
37 ("vxworks", "vxworks"),
40 const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
41 ("aarch64", "aarch64"),
51 ("hexagon", "hexagon"),
57 ("mips64el", "mips64"),
58 ("mipsisa32r6", "mips"),
59 ("mipsisa32r6el", "mips"),
60 ("mipsisa64r6", "mips64"),
61 ("mipsisa64r6el", "mips64"),
63 ("mipsisa32r6", "mips"),
64 ("mipsisa32r6el", "mips"),
65 ("mipsisa64r6", "mips64"),
66 ("mipsisa64r6el", "mips64"),
68 ("nvptx64", "nvptx64"),
69 ("powerpc", "powerpc"),
70 ("powerpc64", "powerpc64"),
71 ("powerpc64le", "powerpc64"),
72 ("riscv64gc", "riscv64"),
75 ("sparc64", "sparc64"),
76 ("sparcv9", "sparc64"),
77 ("thumbv6m", "thumb"),
78 ("thumbv7em", "thumb"),
79 ("thumbv7m", "thumb"),
85 pub const ASAN_SUPPORTED_TARGETS: &'static [&'static str] = &[
87 "aarch64-unknown-linux-gnu",
88 "x86_64-apple-darwin",
90 "x86_64-unknown-linux-gnu",
93 pub const LSAN_SUPPORTED_TARGETS: &'static [&'static str] =
94 &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
96 pub const MSAN_SUPPORTED_TARGETS: &'static [&'static str] =
97 &["aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu"];
99 pub const TSAN_SUPPORTED_TARGETS: &'static [&'static str] =
100 &["aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu"];
102 pub fn matches_os(triple: &str, name: &str) -> bool {
103 // For the wasm32 bare target we ignore anything also ignored on emscripten
104 // and then we also recognize `wasm32-bare` as the os for the target
105 if triple == "wasm32-unknown-unknown" {
106 return name == "emscripten" || name == "wasm32-bare";
108 let triple: Vec<_> = triple.split('-').collect();
109 for &(triple_os, os) in OS_TABLE {
110 if triple.contains(&triple_os) {
114 panic!("Cannot determine OS from triple");
117 /// Determine the architecture from `triple`
118 pub fn get_arch(triple: &str) -> &'static str {
119 let triple: Vec<_> = triple.split('-').collect();
120 for &(triple_arch, arch) in ARCH_TABLE {
121 if triple.contains(&triple_arch) {
125 panic!("Cannot determine Architecture from triple");
128 pub fn matches_env(triple: &str, name: &str) -> bool {
129 if let Some(env) = triple.split('-').nth(3) { env.starts_with(name) } else { false }
132 pub fn get_pointer_width(triple: &str) -> &'static str {
133 if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
135 } else if triple.starts_with("avr") {
142 pub fn make_new_path(path: &str) -> String {
143 assert!(cfg!(windows));
144 // Windows just uses PATH as the library search path, so we have to
145 // maintain the current value while adding our own
146 match env::var(lib_path_env_var()) {
147 Ok(curr) => format!("{}{}{}", path, path_div(), curr),
148 Err(..) => path.to_owned(),
152 pub fn lib_path_env_var() -> &'static str {
155 fn path_div() -> &'static str {
159 pub fn logv(config: &Config, s: String) {
166 pub trait PathBufExt {
167 /// Append an extension to the path, even if it already has one.
168 fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
171 impl PathBufExt for PathBuf {
172 fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
173 if extension.as_ref().len() == 0 {
176 let mut fname = self.file_name().unwrap().to_os_string();
177 if !extension.as_ref().to_str().unwrap().starts_with(".") {
180 fname.push(extension);
181 self.with_file_name(fname)