1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub struct Target {
5 pub goos: &'static str,
6 pub goarch: &'static str,
7}
8
9impl Target {
10 pub const fn new(goos: &'static str, goarch: &'static str) -> Self {
11 Self { goos, goarch }
12 }
13
14 pub fn host() -> Self {
15 let goos = match std::env::consts::OS {
16 "macos" => "darwin",
17 other => other,
18 };
19 let goarch = match std::env::consts::ARCH {
20 "x86_64" => "amd64",
21 "aarch64" => "arm64",
22 "x86" => "386",
23 other => other,
24 };
25 Self { goos, goarch }
26 }
27}
28
29impl Default for Target {
30 fn default() -> Self {
31 Self::host()
32 }
33}
34
35impl fmt::Display for Target {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 write!(f, "{}/{}", self.goos, self.goarch)
38 }
39}
40
41pub fn format_targets(targets: &[(&str, &str)]) -> String {
44 targets
45 .iter()
46 .map(|(goos, goarch)| format!("{}/{}", goos, goarch))
47 .collect::<Vec<_>>()
48 .join(", ")
49}