Skip to content

Commit

Permalink
fix: gozip across different host OS architectures (#3650)
Browse files Browse the repository at this point in the history
* fix: gozip across different host OS architectures

* fix build
  • Loading branch information
mxschmitt authored Sep 19, 2024
1 parent 2c5b814 commit 37b826f
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions build/BuildSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,28 +764,34 @@ private static IEnumerable<string> GetAllRuntimesToSign()

public static void AddGoZip()
{
var runtimeToGoEnv = new Dictionary<string, (string GOOS, string GOARCH)>
{
{ "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}");
}
}
}
Expand Down

0 comments on commit 37b826f

Please sign in to comment.