-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipe.go
More file actions
48 lines (37 loc) · 1.02 KB
/
Recipe.go
File metadata and controls
48 lines (37 loc) · 1.02 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
//go:build gobake
package bake_recipe
import (
"fmt"
"runtime"
"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 the current platform", func(ctx *gobake.Context) error {
ctx.Log("Building %s v%s for %s/%s...", bake.Info.Name, bake.Info.Version, runtime.GOOS, runtime.GOARCH)
osName := runtime.GOOS
archName := runtime.GOARCH
err := ctx.Mkdir("build")
if err != nil {
return err
}
ldflags := fmt.Sprintf("-X main.Version=%s", bake.Info.Version)
output := "build/" + bake.Info.Name + "-" + osName + "-" + archName
if osName == "windows" {
output += ".exe"
}
ctx.Env = []string{
"CGO_ENABLED=1",
"GOOS=" + osName,
"GOARCH=" + archName,
}
err = ctx.Run("go", "build", "-ldflags", ldflags, "-o", output, ".")
return err
})
bake.Task("clean", "Removes build artifacts", func(ctx *gobake.Context) error {
return ctx.Remove("build")
})
return nil
}