-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.go
More file actions
61 lines (50 loc) · 1.19 KB
/
Recipe.go
File metadata and controls
61 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build gobake
package bake_recipe
import (
"fmt"
"github.com/fezcode/gobake"
)
func Run(bake *gobake.Engine) error {
if err := bake.LoadRecipeInfo("recipe.piml"); err != nil {
return err
}
bake.Task("build", "Builds the binary for multiple platforms", func(ctx *gobake.Context) error {
ctx.Log("Building %s v%s...", bake.Info.Name, bake.Info.Version)
targets := []struct {
os string
arch string
}{
{"linux", "amd64"},
{"linux", "arm64"},
{"windows", "amd64"},
{"windows", "arm64"},
{"darwin", "amd64"},
{"darwin", "arm64"},
}
err := ctx.Mkdir("build")
if err != nil {
return err
}
ldflags := fmt.Sprintf("-X main.Version=%s", bake.Info.Version)
for _, t := range targets {
output := "build/" + bake.Info.Name + "-" + t.os + "-" + t.arch
if t.os == "windows" {
output += ".exe"
}
ctx.Env = []string{
"CGO_ENABLED=0",
"GOOS=" + t.os,
"GOARCH=" + t.arch,
}
err := ctx.Run("go", "build", "-ldflags", ldflags, "-o", output, ".")
if err != nil {
return err
}
}
return nil
})
bake.Task("clean", "Removes build artifacts", func(ctx *gobake.Context) error {
return ctx.Remove("build")
})
return nil
}