From a0efeb84938bc627b96890ecdb7478625c82b70f Mon Sep 17 00:00:00 2001
From: Johan de Klerk <jdeklerk00@gmail.com>
Date: Thu, 6 Jan 2022 10:48:46 +0200
Subject: [PATCH] Build windows app

---
 mage_helpers/build.go | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/mage_helpers/build.go b/mage_helpers/build.go
index 4ce7219..9d85d34 100644
--- a/mage_helpers/build.go
+++ b/mage_helpers/build.go
@@ -59,7 +59,7 @@ func Build(dir string, module string, isDebug bool) error {
 	}
 
 	// Copy shared files
-	sharedDir := currentDir+"/core/utils"
+	sharedDir := currentDir + "/core/utils"
 	_, err = os.Stat(sharedDir)
 	if err == nil {
 		err = copyFilesToBuildDir(sharedDir, outputDir)
@@ -111,6 +111,32 @@ func BuildGolangApp(outputDir string, appPath string, module string, isDebug boo
 	return nil
 }
 
+func BuildGolangAppWindows(outputDir string, appPath string, module string, isDebug bool) error {
+	commandArgs := []string{
+		`build`,
+		fmt.Sprintf(`-ldflags=-X %v/globals.BuildVersion=%v -X %v/globals.OSType=%v -X %v/globals.IsDebugBuild=%v`, module, CurrentCommit(), module, runtime.GOOS, module, isDebug),
+	}
+
+	if isDebug {
+		commandArgs = append(commandArgs, "-gcflags", "all=-N -l")
+	}
+
+	commandArgs = append(commandArgs, `-o`,
+		outputDir,
+		appPath)
+
+	env := map[string]string{
+		"GOOS":   "windows",
+		"GOARCH": "amd64",
+	}
+
+	err := sh.RunWith(env, "go", commandArgs...)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 func BuildMJML(filename string) error {
 	// Get the full path to the file
 	currentDir, _ := os.Getwd()
-- 
GitLab