use std::env::consts::{ARCH, EXE_SUFFIX, OS};
pub fn go(prefix: &str) -> String {
format!("{prefix}-{}-{}{EXE_SUFFIX}", go_os(OS), go_arch(ARCH))
}
pub fn rust(prefix: &str) -> String {
format!("{prefix}-{}{EXE_SUFFIX}", crate::TARGET)
}
fn go_os(os: &str) -> &str {
match os {
"macos" => "darwin",
other => other,
}
}
fn go_arch(arch: &str) -> &str {
match arch {
"x86_64" => "amd64",
"i686" => "386",
"aarch64" => "arm64",
"powerpc64" => "ppc64",
other => other,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn go_starts_with_prefix_and_has_no_rust_arch() {
let name = go("myapp");
assert!(name.starts_with("myapp-"), "got {name}");
assert!(!name.contains("x86_64"), "got {name}");
assert!(!name.contains("aarch64"), "got {name}");
#[cfg(target_os = "macos")]
assert!(name.contains("-darwin-"), "got {name}");
#[cfg(target_os = "windows")]
assert!(name.ends_with(".exe"), "got {name}");
#[cfg(target_os = "linux")]
assert!(
name.contains("-linux-") && !name.ends_with(".exe"),
"got {name}"
);
}
#[test]
fn rust_uses_the_target_triple() {
let name = rust("myapp");
assert!(name.starts_with("myapp-"), "got {name}");
assert!(name.contains(crate::TARGET), "got {name}");
assert!(name.contains(std::env::consts::ARCH), "got {name}");
#[cfg(target_os = "windows")]
assert!(name.ends_with(".exe"), "got {name}");
}
#[test]
fn go_translations() {
assert_eq!(go_os("macos"), "darwin");
assert_eq!(go_os("linux"), "linux");
assert_eq!(go_arch("x86_64"), "amd64");
assert_eq!(go_arch("aarch64"), "arm64");
assert_eq!(go_arch("riscv64"), "riscv64");
}
}