From f5b878051a13f62a6ba724bec0e27b9be46421f1 Mon Sep 17 00:00:00 2001 From: Kostas Stamatakis Date: Wed, 24 Jul 2024 19:05:07 +0300 Subject: [PATCH] export to function --- dev-tools/mage/crossbuild.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go index 7c570ceba1c6..21509efc5784 100644 --- a/dev-tools/mage/crossbuild.go +++ b/dev-tools/mage/crossbuild.go @@ -355,7 +355,7 @@ func (b GolangCrossBuilder) Build() error { ) } else if strings.HasPrefix(b.Platform, "linux/") && b.UseHostPlatform { args = append(args, - "--platform", "linux/"+runtime.GOARCH, + "--platform", dockerHostPlatform(), ) } @@ -371,6 +371,16 @@ func (b GolangCrossBuilder) Build() error { return dockerRun(args...) } +func dockerHostPlatform() string { + os := runtime.GOOS + // darwin docker runs inside a linux vm + if os == "darwin" { + os = "linux" + } + + return os + "/" + runtime.GOARCH +} + // DockerChown chowns files generated during build. EXEC_UID and EXEC_GID must // be set in the containers environment otherwise this is a noop. func DockerChown(path string) {