From 37b826f143b99cd62308b88320e71aa806f6197f Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 19 Sep 2024 05:16:18 +0200 Subject: [PATCH] fix: gozip across different host OS architectures (#3650) * fix: gozip across different host OS architectures * fix build --- build/BuildSteps.cs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/build/BuildSteps.cs b/build/BuildSteps.cs index e63a7900d..2b07a9a53 100644 --- a/build/BuildSteps.cs +++ b/build/BuildSteps.cs @@ -764,28 +764,34 @@ private static IEnumerable GetAllRuntimesToSign() public static void AddGoZip() { + var runtimeToGoEnv = new Dictionary + { + { "win-x86", ("windows", "386") }, + { "win-arm64", ("windows", "arm64") }, + { "win-x64", ("windows", "amd64") }, + { "linux-x64", ("linux", "amd64") }, + { "osx-arm64", ("darwin", "arm64") }, + { "osx-x64", ("darwin", "amd64") } + }; var combinedRuntimesToSign = GetAllTargetRuntimes(); foreach (var runtime in combinedRuntimesToSign) { - var outputPath = Path.Combine(Settings.OutputDir, runtime, "gozip"); - Environment.SetEnvironmentVariable("GOARCH", "amd64"); - Environment.SetEnvironmentVariable("CGO_ENABLED", "0"); - var goFile = Path.GetFullPath("../tools/go/gozip/main.go"); - - if (runtime.Contains("win")) - { - Environment.SetEnvironmentVariable("GOOS", "windows"); - Shell.Run("go", $"build -o {outputPath}.exe {goFile}"); - } - else if (runtime.Contains("linux")) + var runtimeId = GetRuntimeId(runtime); + // Remove the Net8ArtifactNameSuffix suffix if present + runtimeId = runtimeId.Replace(Net8ArtifactNameSuffix, ""); + if (runtimeToGoEnv.TryGetValue(runtimeId, out var goEnv)) { - Environment.SetEnvironmentVariable("GOOS", "linux"); - Shell.Run("go", $"build -o {outputPath} {goFile}"); + Environment.SetEnvironmentVariable("CGO_ENABLED", "0"); + Environment.SetEnvironmentVariable("GOOS", goEnv.GOOS); + Environment.SetEnvironmentVariable("GOARCH", goEnv.GOARCH); + var outputPath = Path.Combine(Settings.OutputDir, runtime, "gozip"); + var output = runtimeId.Contains("win") ? $"{outputPath}.exe" : outputPath; + var goFile = Path.GetFullPath("../tools/go/gozip/main.go"); + Shell.Run("go", $"build -o {output} {goFile}"); } - else if (runtime.Contains("osx")) + else { - Environment.SetEnvironmentVariable("GOOS", "darwin"); - Shell.Run("go", $"build -o {outputPath} {goFile}"); + throw new Exception($"Unsupported runtime: {runtime}"); } } }