cargo_dist/platform/
github_runners.rs1use std::collections::HashMap;
4
5use crate::platform::targets as t;
6use cargo_dist_schema::{target_lexicon::Triple, GithubRunnerRef, TripleNameRef};
7use tracing::warn;
8
9lazy_static::lazy_static! {
10 static ref KNOWN_GITHUB_RUNNERS: HashMap<&'static GithubRunnerRef, &'static TripleNameRef> = {
11 let mut m = HashMap::new();
12 m.insert(GithubRunnerRef::from_str("ubuntu-22.04"), t::TARGET_X64_LINUX_GNU);
17 m.insert(GithubRunnerRef::from_str("ubuntu-22.04-arm"), t::TARGET_ARM64_LINUX_GNU);
18 m.insert(GithubRunnerRef::from_str("ubuntu-24.04"), t::TARGET_X64_LINUX_GNU);
19 m.insert(GithubRunnerRef::from_str("ubuntu-24.04-arm"), t::TARGET_ARM64_LINUX_GNU);
20 m.insert(GithubRunnerRef::from_str("ubuntu-latest"), t::TARGET_X64_LINUX_GNU);
21
22 m.insert(GithubRunnerRef::from_str("windows-2022"), t::TARGET_X64_WINDOWS);
24 m.insert(GithubRunnerRef::from_str("windows-2025"), t::TARGET_X64_WINDOWS);
25 m.insert(GithubRunnerRef::from_str("windows-latest"), t::TARGET_X64_WINDOWS);
26
27 m.insert(GithubRunnerRef::from_str("macos-14-large"), t::TARGET_X64_MAC);
29 m.insert(GithubRunnerRef::from_str("macos-15-large"), t::TARGET_X64_MAC);
30 m.insert(GithubRunnerRef::from_str("macos-15-intel"), t::TARGET_X64_MAC);
31 m.insert(GithubRunnerRef::from_str("macos-latest-large"), t::TARGET_X64_MAC);
32
33 m.insert(GithubRunnerRef::from_str("macos-14"), t::TARGET_ARM64_MAC);
35 m.insert(GithubRunnerRef::from_str("macos-14-xlarge"), t::TARGET_ARM64_MAC);
36 m.insert(GithubRunnerRef::from_str("macos-15"), t::TARGET_ARM64_MAC);
37 m.insert(GithubRunnerRef::from_str("macos-15-xlarge"), t::TARGET_ARM64_MAC);
38 m.insert(GithubRunnerRef::from_str("macos-26"), t::TARGET_ARM64_MAC);
39 m.insert(GithubRunnerRef::from_str("macos-26-xlarge"), t::TARGET_ARM64_MAC);
40 m.insert(GithubRunnerRef::from_str("macos-latest"), t::TARGET_ARM64_MAC);
41 m.insert(GithubRunnerRef::from_str("macos-latest-xlarge"), t::TARGET_ARM64_MAC);
42
43 m
44 };
45}
46
47pub fn target_for_github_runner(runner: &GithubRunnerRef) -> Option<&'static TripleNameRef> {
49 if let Some(target) = KNOWN_GITHUB_RUNNERS.get(runner).copied() {
50 return Some(target);
51 }
52
53 let runner_str = runner.as_str();
54 if let Some(rest) = runner_str.strip_prefix("buildjet-") {
55 if rest.contains("ubuntu") {
56 if rest.ends_with("-arm") {
57 return Some(t::TARGET_ARM64_LINUX_GNU);
58 } else {
59 return Some(t::TARGET_X64_LINUX_GNU);
60 }
61 }
62 }
63
64 None
65}
66
67pub fn target_for_github_runner_or_default(runner: &GithubRunnerRef) -> &'static TripleNameRef {
69 const DEFAULT_ASSUMED_TARGET: &TripleNameRef = t::TARGET_X64_LINUX_GNU;
70
71 target_for_github_runner(runner).unwrap_or_else(|| {
72 warn!(
73 "don't know the triple for github runner '{runner}', assuming {DEFAULT_ASSUMED_TARGET}"
74 );
75 DEFAULT_ASSUMED_TARGET
76 })
77}
78
79pub fn triple_for_github_runner_or_default(runner: &GithubRunnerRef) -> Triple {
81 target_for_github_runner_or_default(runner).parse().unwrap()
84}
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 #[test]
91 fn test_target_for_github_runner() {
92 assert_eq!(
93 target_for_github_runner(GithubRunnerRef::from_str("ubuntu-22.04")),
94 Some(t::TARGET_X64_LINUX_GNU)
95 );
96 assert_eq!(
97 target_for_github_runner(GithubRunnerRef::from_str("buildjet-8vcpu-ubuntu-2204-arm")),
98 Some(t::TARGET_ARM64_LINUX_GNU)
99 );
100 }
101}