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 const BIG_ENDIAN: &'static [&'static str] = &[
116 pub fn matches_os(triple: &str, name: &str) -> bool {
117 // For the wasm32 bare target we ignore anything also ignored on emscripten
118 // and then we also recognize `wasm32-bare` as the os for the target
119 if triple == "wasm32-unknown-unknown" {
120 return name == "emscripten" || name == "wasm32-bare";
122 let triple: Vec<_> = triple.split('-').collect();
123 for &(triple_os, os) in OS_TABLE {
124 if triple.contains(&triple_os) {
128 panic!("Cannot determine OS from triple");
131 /// Determine the architecture from `triple`
132 pub fn get_arch(triple: &str) -> &'static str {
133 let triple: Vec<_> = triple.split('-').collect();
134 for &(triple_arch, arch) in ARCH_TABLE {
135 if triple.contains(&triple_arch) {
139 panic!("Cannot determine Architecture from triple");
142 /// Determine the endianness from `triple`
143 pub fn is_big_endian(triple: &str) -> bool {
144 let triple_arch = triple.split('-').next().unwrap();
145 BIG_ENDIAN.contains(&triple_arch)
148 pub fn matches_env(triple: &str, name: &str) -> bool {
149 if let Some(env) = triple.split('-').nth(3) { env.starts_with(name) } else { false }
152 pub fn get_pointer_width(triple: &str) -> &'static str {
153 if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
155 } else if triple.starts_with("avr") {
162 pub fn make_new_path(path: &str) -> String {
163 assert!(cfg!(windows));
164 // Windows just uses PATH as the library search path, so we have to
165 // maintain the current value while adding our own
166 match env::var(lib_path_env_var()) {
167 Ok(curr) => format!("{}{}{}", path, path_div(), curr),
168 Err(..) => path.to_owned(),
172 pub fn lib_path_env_var() -> &'static str {
175 fn path_div() -> &'static str {
179 pub fn logv(config: &Config, s: String) {
186 pub trait PathBufExt {
187 /// Append an extension to the path, even if it already has one.
188 fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf;
191 impl PathBufExt for PathBuf {
192 fn with_extra_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
193 if extension.as_ref().len() == 0 {
196 let mut fname = self.file_name().unwrap().to_os_string();
197 if !extension.as_ref().to_str().unwrap().starts_with(".") {
200 fname.push(extension);
201 self.with_file_name(fname)