Skip to main content

opal/executor/
container_arch.rs

1use std::env;
2
3pub(crate) fn default_container_cli_arch(platform: Option<&str>) -> Option<String> {
4    container_arch_override()
5        .or_else(|| platform.and_then(container_arch_from_platform))
6        .or_else(host_container_arch)
7}
8
9fn container_arch_override() -> Option<String> {
10    env::var("OPAL_CONTAINER_ARCH")
11        .ok()
12        .filter(|value| !value.is_empty())
13}
14
15fn host_container_arch() -> Option<String> {
16    normalize_container_arch(std::env::consts::ARCH)
17}
18
19pub(crate) fn normalize_container_arch(value: &str) -> Option<String> {
20    match value {
21        "aarch64" => Some("arm64".to_string()),
22        "x86_64" => Some("x86_64".to_string()),
23        other if !other.is_empty() => Some(other.to_string()),
24        _ => None,
25    }
26}
27
28pub(crate) fn container_arch_from_platform(value: &str) -> Option<String> {
29    let normalized = value.to_ascii_lowercase();
30    if normalized.contains("amd64") || normalized.contains("x86_64") {
31        return Some("x86_64".to_string());
32    }
33    if normalized.contains("arm64") || normalized.contains("aarch64") {
34        return Some("arm64".to_string());
35    }
36    None
37}