38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
use crate::veprintln;
|
|
use anyhow::{anyhow, Result};
|
|
use std::path::Path;
|
|
|
|
/// Check if binfmt_misc is registered for the target architecture
|
|
pub fn check_binfmt(arch: &str) -> Result<()> {
|
|
let qemu_arch = map_arch_to_qemu(arch);
|
|
|
|
let binfmt_path = format!("/proc/sys/fs/binfmt_misc/qemu-{}", qemu_arch);
|
|
|
|
if !Path::new(&binfmt_path).exists() {
|
|
return Err(anyhow!(
|
|
"binfmt_misc not registered for {}\n\n\
|
|
Install QEMU user emulation:\n\
|
|
Ubuntu/Debian: sudo apt install qemu-user-static\n\
|
|
Arch: sudo pacman -S qemu-user-static-binfmt\n\
|
|
Alpine: sudo apk add qemu-user-static",
|
|
arch
|
|
));
|
|
}
|
|
|
|
veprintln!("QEMU binfmt_misc registered for {}", arch);
|
|
Ok(())
|
|
}
|
|
|
|
/// Map ecr architecture names to QEMU binary names
|
|
fn map_arch_to_qemu(arch: &str) -> &str {
|
|
match arch {
|
|
"amd64" | "x86_64" => "x86_64",
|
|
"arm64" | "aarch64" => "aarch64",
|
|
"armhf" | "armv7" => "arm",
|
|
"riscv64" => "riscv64",
|
|
"ppc64el" | "ppc64le" => "ppc64le",
|
|
"s390x" => "s390x",
|
|
_ => arch,
|
|
}
|
|
}
|