From ac1c86c431d3f38185e9ce762a4b7bd6824c8236 Mon Sep 17 00:00:00 2001 From: "T. R. Bernstein" Date: Sun, 22 Mar 2026 15:40:32 +0100 Subject: [PATCH] Run linux container with same architechture as host As the development team uses both Intel and Apple Silicon Macs, we have to get the host CPU architecture at compilation time instead of harcoding it. If the container has a different architecture, the guest has to be emulated. --- Sources/TaskCLI/Docker.swift | 9 +++++++++ Sources/TaskCLI/GenerateDocumentation Command.swift | 2 +- Sources/TaskCLI/Test Command.swift | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Sources/TaskCLI/Docker.swift diff --git a/Sources/TaskCLI/Docker.swift b/Sources/TaskCLI/Docker.swift new file mode 100644 index 0000000..17362c6 --- /dev/null +++ b/Sources/TaskCLI/Docker.swift @@ -0,0 +1,9 @@ +struct Docker { + static func getLinuxPlatformStringWithHostArchitecture() -> String { + #if arch(x86_64) + return "linux/amd64" + #else + return "linux/arm64" + #endif + } +} \ No newline at end of file diff --git a/Sources/TaskCLI/GenerateDocumentation Command.swift b/Sources/TaskCLI/GenerateDocumentation Command.swift index 91a36c5..c7fdd83 100644 --- a/Sources/TaskCLI/GenerateDocumentation Command.swift +++ b/Sources/TaskCLI/GenerateDocumentation Command.swift @@ -46,7 +46,7 @@ struct GenerateDocumentationCommand: Script { try await docker( "run", "--rm", "-v", "\(tempDirectory.path):/code", - "--platform", "linux/arm64", + "--platform", Docker.getLinuxPlatformStringWithHostArchitecture(), "-w", "/code", "swift:latest", "/bin/bash", "-c", script, diff --git a/Sources/TaskCLI/Test Command.swift b/Sources/TaskCLI/Test Command.swift index c2cc229..28f74a7 100644 --- a/Sources/TaskCLI/Test Command.swift +++ b/Sources/TaskCLI/Test Command.swift @@ -26,7 +26,7 @@ struct TestCommand: Script { "run", "-v", "\(currentDirectory):/code", "--security-opt", "systempaths=unconfined", - "--platform", "linux/arm64", + "--platform", Docker.getLinuxPlatformStringWithHostArchitecture(), "-w", "/code", "swift:latest", "/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests" )