Skip to content

Commit d66d8b5

Browse files
author
Adam Hughes
committed
build: disable CGO in mage build/install
1 parent de51ee2 commit d66d8b5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

magefile.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ var Aliases = map[string]interface{}{
2828
"test": Test.All,
2929
}
3030

31+
// env returns the environment to use when running Go commands.
32+
func env() map[string]string {
33+
return map[string]string{"CGO_ENABLED": "0"}
34+
}
35+
3136
// ldFlags returns linker flags to pass to various Go commands.
3237
func ldFlags() string {
3338
vals := []string{"-s", "-w", "-X", "main.builtBy=mage"}
@@ -71,7 +76,7 @@ func (ns Build) All() {
7176

7277
// Source compiles all source code.
7378
func (Build) Source() error {
74-
return sh.Run(mg.GoCmd(), "build", "-trimpath", "-ldflags", ldFlags(), "./...")
79+
return sh.RunWith(env(), mg.GoCmd(), "build", "-trimpath", "-ldflags", ldFlags(), "./...")
7580
}
7681

7782
type Install mg.Namespace
@@ -83,7 +88,7 @@ func (ns Install) All() {
8388

8489
// Bin installs binary to GOBIN.
8590
func (Install) Bin() error {
86-
return sh.Run(mg.GoCmd(), "install", "-trimpath", "-ldflags", ldFlags(), "./cmd/siftool")
91+
return sh.RunWith(env(), mg.GoCmd(), "install", "-trimpath", "-ldflags", ldFlags(), "./cmd/siftool")
8792
}
8893

8994
type Test mg.Namespace

0 commit comments

Comments
 (0)