| 1 |
/// Rust and Clang don't really agree on naming, so do a best-effort |
| 2 |
/// conversion to support out-of-tree / custom target-spec targets. |
| 3 |
pub(crate) fn guess_llvm_target_triple( |
| 4 |
full_arch: &str, |
| 5 |
vendor: &str, |
| 6 |
os: &str, |
| 7 |
env: &str, |
| 8 |
abi: &str, |
| 9 |
) -> String { |
| 10 |
let arch = match full_arch { |
| 11 |
riscv32 if riscv32.starts_with("riscv32") => "riscv32", |
| 12 |
riscv64 if riscv64.starts_with("riscv64") => "riscv64", |
| 13 |
arch => arch, |
| 14 |
}; |
| 15 |
let os = match os { |
| 16 |
"darwin" => "macosx", |
| 17 |
"visionos" => "xros", |
| 18 |
"uefi" => "windows", |
| 19 |
os => os, |
| 20 |
}; |
| 21 |
let env = match env { |
| 22 |
"newlib" | "nto70" | "nto71" | "ohos" | "p1" | "p2" | "relibc" | "sgx" | "uclibc" => "", |
| 23 |
env => env, |
| 24 |
}; |
| 25 |
let abi = match abi { |
| 26 |
"sim" => "simulator", |
| 27 |
"llvm" | "softfloat" | "uwp" | "vec-extabi" => "", |
| 28 |
"ilp32" => "_ilp32", |
| 29 |
abi => abi, |
| 30 |
}; |
| 31 |
match (env, abi) { |
| 32 |
("", "") => format!("{arch}-{vendor}-{os}"), |
| 33 |
(env, abi) => format!("{arch}-{vendor}-{os}-{env}{abi}"), |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
#[cfg(test)] |
| 38 |
mod tests { |
| 39 |
use super::*; |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn test_basic_llvm_triple_guessing() { |
| 43 |
assert_eq!( |
| 44 |
guess_llvm_target_triple("aarch64", "unknown", "linux", "", ""), |
| 45 |
"aarch64-unknown-linux" |
| 46 |
); |
| 47 |
assert_eq!( |
| 48 |
guess_llvm_target_triple("x86_64", "unknown", "linux", "gnu", ""), |
| 49 |
"x86_64-unknown-linux-gnu" |
| 50 |
); |
| 51 |
assert_eq!( |
| 52 |
guess_llvm_target_triple("x86_64", "unknown", "linux", "gnu", "eabi"), |
| 53 |
"x86_64-unknown-linux-gnueabi" |
| 54 |
); |
| 55 |
assert_eq!( |
| 56 |
guess_llvm_target_triple("x86_64", "apple", "darwin", "", ""), |
| 57 |
"x86_64-apple-macosx" |
| 58 |
); |
| 59 |
} |
| 60 |
} |