A CPU architecture.
| 19 | |
| 20 | |
| 21 | class Arch(Enum): |
| 22 | """A CPU architecture.""" |
| 23 | |
| 24 | X86_64 = "x86_64" |
| 25 | """The 64-bit x86 architecture.""" |
| 26 | |
| 27 | AARCH64 = "aarch64" |
| 28 | """The 64-bit ARM architecture.""" |
| 29 | |
| 30 | def __str__(self) -> str: |
| 31 | return self.value |
| 32 | |
| 33 | def go_str(self) -> str: |
| 34 | """Return the architecture name in Go nomenclature: amd64 or arm64.""" |
| 35 | if self == Arch.X86_64: |
| 36 | return "amd64" |
| 37 | elif self == Arch.AARCH64: |
| 38 | return "arm64" |
| 39 | else: |
| 40 | raise RuntimeError("unreachable") |
| 41 | |
| 42 | @staticmethod |
| 43 | def host() -> "Arch": |
| 44 | if platform.machine() == "x86_64": |
| 45 | return Arch.X86_64 |
| 46 | elif platform.machine() in ["aarch64", "arm64"]: |
| 47 | return Arch.AARCH64 |
| 48 | else: |
| 49 | raise RuntimeError(f"unknown host architecture {platform.machine()}") |
| 50 | |
| 51 | |
| 52 | def target(arch: Arch) -> str: |
no outgoing calls
no test coverage detected