Skip to content

Commit 651c39c

Browse files
authored
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
1 parent 14f1df5 commit 651c39c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/ContainerClient/Flags.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ public struct Flags {
184184
@Flag(name: [.customLong("rm"), .long], help: "Remove the container after it stops")
185185
public var remove = false
186186

187+
@Flag(name: .long, help: "Enable Rosetta in the container")
188+
public var rosetta = false
189+
187190
@Flag(name: .long, help: "Forward SSH agent socket to container")
188191
public var ssh = false
189192

Sources/ContainerClient/Utility.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ public struct Utility {
213213
)
214214
}
215215

216-
if Platform.current.architecture == "arm64" && requestedPlatform.architecture == "amd64" {
217-
config.rosetta = true
216+
config.rosetta = management.rosetta || (Platform.current.architecture == "arm64" && requestedPlatform.architecture == "amd64")
217+
218+
if management.rosetta && Platform.current.architecture != "arm64" {
219+
throw ContainerizationError(.unsupported, message: "--rosetta flag requires an arm64 host")
218220
}
219221

220222
config.labels = try Parser.labels(management.labels)

0 commit comments

Comments
 (0)