Skip to content

Commit

Permalink
image: Fix powerpc, add a test case for arch mapping
Browse files Browse the repository at this point in the history
I happened to notice while skimming over this that Rust using `powerpc`
is a strange outlier - the other key arch names AFAICS match the GNU
ones (e.g. `s390x`, `riscv64`, `x86_64` etc).

Now unfortunately, tests from dependencies aren't usually run
by default by `cargo`.  A major exception here is how Fedora packages
crates and as part of the "build" of a crate the tests are run.

So we will hopefully flush out any un-mapped architectures by that
as well as anyone who actually goes to some effort to run the
dependency tests.
  • Loading branch information
cgwalters committed Jan 17, 2022
1 parent b10f910 commit 52e450e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,31 @@ impl<'de> Deserialize<'de> for Arch {
impl Default for Arch {
fn default() -> Self {
// Translate from the Rust architecture names to the Go versions.
// I think the Rust ones are the same as the Linux kernel ones.
// It seems like the Rust ones are the same GNU/Linux...except for `powerpc64` and not `ppc64le`?
// This list just contains exceptions, everything else is passed through literally.
// See also https://github.com/containerd/containerd/blob/140ecc9247386d3be21616fe285021c081f4ea08/platforms/database.go
let goarch = match std::env::consts::ARCH {
"x86_64" => "amd64",
"aarch64" => "arm64",
"powerpc64" if cfg!(target_endian = "big") => "ppc64",
"powerpc64" if cfg!(target_endian = "little") => "ppc64le",
o => o,
};
Arch::from(goarch)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_arch_translation() {
let a = Arch::default();
match a {
// If you hit this, please update the mapping above.
Arch::Other(o) => panic!("Architecture {} not mapped between Rust and OCI", o),
_ => {}
}
}
}

0 comments on commit 52e450e

Please sign in to comment.