Add --rosetta option for arm64 images (#846)

`container` automatically enables Rosetta for amd64 containers. This
change allows Rosetta to be enabled for arm64 containers by passing the
`--rosetta` flag. This allows native containers to benefit from being
able to execute the occasional amd64 executable in niche situations,
e.g., containers used for cross-compilation.

Resolves #391.

I considered adding a warning for passing `--rosetta` when it is not
necessary, but there wasn't obvious infrastructure for conveying the
This commit is contained in:
Ryan Govostes
2025-11-09 15:10:58 -08:00
committed by GitHub
parent 14f1df59bf
commit 651c39cf95
2 changed files with 7 additions and 2 deletions
+3
View File
@@ -184,6 +184,9 @@ public struct Flags {
@Flag(name: [.customLong("rm"), .long], help: "Remove the container after it stops")
public var remove = false
@Flag(name: .long, help: "Enable Rosetta in the container")
public var rosetta = false
@Flag(name: .long, help: "Forward SSH agent socket to container")
public var ssh = false
+4 -2
View File
@@ -213,8 +213,10 @@ public struct Utility {
)
}
if Platform.current.architecture == "arm64" && requestedPlatform.architecture == "amd64" {
config.rosetta = true
config.rosetta = management.rosetta || (Platform.current.architecture == "arm64" && requestedPlatform.architecture == "amd64")
if management.rosetta && Platform.current.architecture != "arm64" {
throw ContainerizationError(.unsupported, message: "--rosetta flag requires an arm64 host")
}
config.labels = try Parser.labels(management.labels)